diff --git a/Cargo.lock b/Cargo.lock index b196c61..77e0814 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -49,7 +49,6 @@ dependencies = [ "password-auth", "serde", "serde_json", - "sqlx", "thiserror 2.0.17", "time", "tokio", diff --git a/api/Cargo.toml b/api/Cargo.toml index 7ef143a..a9efc71 100644 --- a/api/Cargo.toml +++ b/api/Cargo.toml @@ -9,12 +9,10 @@ default = ["sqlite"] sqlite = [ "infra/sqlite", "tower-sessions-sqlx-store/sqlite", - "sqlx/sqlite", ] postgres = [ "infra/postgres", "tower-sessions-sqlx-store/postgres", - "sqlx/postgres", "k-core/postgres", ] broker-nats = ["infra/broker-nats"] @@ -65,7 +63,6 @@ tracing = "0.1" tracing-subscriber = { version = "0.3.22", features = ["env-filter"] } # Database -sqlx = { version = "0.8.6", features = ["sqlite", "runtime-tokio"] } dotenvy = "0.15.7" # Configuration diff --git a/api/src/main.rs b/api/src/main.rs index 300caa9..0e5d11c 100644 --- a/api/src/main.rs +++ b/api/src/main.rs @@ -21,52 +21,38 @@ use crate::state::AppState; #[tokio::main] async fn main() -> anyhow::Result<()> { - // 1. Initialize logging - logging::init("template-api"); + logging::init("api"); - // 2. Load configuration - // We use dotenvy explicitly here since config crate might not pick up .env automatically reliably dotenvy::dotenv().ok(); let config = Config::new().expect("Failed to load configuration"); info!("Starting server on {}:{}", config.host, config.port); - // 3. Connect to database - // k-core handles the "Which DB are we using?" logic internally based on feature flags - // and returns the correct Enum variant. let db_config = k_core::db::DatabaseConfig { url: config.database_url.clone(), max_connections: 5, acquire_timeout: StdDuration::from_secs(30), }; - // Returns k_core::db::DatabasePool let db_pool = k_core::db::connect(&db_config).await?; - // 4. Run migrations (using the re-export if you kept it, or direct k_core) infra::db::run_migrations(&db_pool).await?; - // 5. Initialize Services let user_repo = build_user_repository(&db_pool).await?; let user_service = UserService::new(user_repo.clone()); - // 6. Setup Session Store let session_store = build_session_store(&db_pool).await?; let session_layer = SessionManagerLayer::new(session_store) .with_secure(false) // Set to true in production with HTTPS .with_expiry(Expiry::OnInactivity(time::Duration::hours(1))); - // 7. Setup Auth let auth_layer = auth::setup_auth_layer(session_layer, user_repo.clone()).await?; - // 8. Create App State let state = AppState::new(user_service, config.clone()); - // 9. Build Router let app = routes::api_v1_router().layer(auth_layer).with_state(state); - // 10. Start Server let addr: SocketAddr = format!("{}:{}", config.host, config.port).parse()?; let listener = TcpListener::bind(addr).await?; axum::serve(listener, app).await?;