feat: v0.3.0 — standardize codebase, centralize infra, merge QR into CMS
- Enforce axum best practices across all 13 workspace crates (max 200 LOC/file, no comments, no unwrap, clean architecture) - Fix domain→infrastructure dependency inversions in imphnen-iam and imphnen-dimentorin - Extract imphnen-storage (MinIO) and imphnen-email (Lettre) as standalone crates - Centralize all config in ENV struct: CDN_URL, CORS_ALLOWED_ORIGINS - Centralize SMTP through imphnen-email; remove dead HackathonConfig - Centralize database: QR crate now shares main DB pool (single DATABASE_URL) - Rename QR users table to qr_users to avoid collision with main users table - Merge imphnen-qr into imphnen-cms/src/qr (13 crates, down from 14) - Restructure imphnen-hackathon flat modules into clean architecture - Remove all stale env vars from .env.example (SurrealDB, QR_JWT, Hackathon infra) - Fix Dockerfile to include all current workspace crates - Bump all crate versions 0.2.0 → 0.3.0 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
2ae43b3bcc
commit
331a4a4e88
+66
-69
@@ -1,90 +1,87 @@
|
||||
use axum::{
|
||||
Extension,
|
||||
Router,
|
||||
middleware::from_fn,
|
||||
response::Redirect,
|
||||
routing::get,
|
||||
Extension, Router, middleware::from_fn, response::Redirect, routing::get,
|
||||
};
|
||||
use imphnen_cms::{
|
||||
events_protected_routes,
|
||||
events_public_routes,
|
||||
testimonials_protected_routes,
|
||||
testimonials_public_routes,
|
||||
events_protected_routes, events_public_routes, qr_router, testimonials_protected_routes,
|
||||
testimonials_public_routes,
|
||||
};
|
||||
use imphnen_dimentorin::{
|
||||
mentors_public_routes, mentors_protected_routes,
|
||||
sessions_public_routes, sessions_protected_routes,
|
||||
mentors_protected_routes, mentors_public_routes, sessions_protected_routes,
|
||||
sessions_public_routes,
|
||||
};
|
||||
use imphnen_gacha::gacha_router;
|
||||
use imphnen_hackathon::{hackathon_router, HackathonConfig};
|
||||
use imphnen_qr::qr_router;
|
||||
use imphnen_libs::{MinioConfig, create_minio_service_from_config};
|
||||
use imphnen_hackathon::hackathon_router;
|
||||
use imphnen_iam::{
|
||||
auth_public_routes,
|
||||
permissions_protected_routes,
|
||||
roles_protected_routes,
|
||||
users_protected_routes,
|
||||
auth_public_routes, permissions_protected_routes, roles_protected_routes,
|
||||
users_protected_routes,
|
||||
};
|
||||
use imphnen_libs::services::PostgresAuthRepository as AuthRepoImpl;
|
||||
use imphnen_libs::PostgresUserLookupService;
|
||||
use imphnen_libs::services::PostgresAuthRepository as AuthRepoImpl;
|
||||
use imphnen_libs::{AppState, axum::PostgresClients};
|
||||
use imphnen_middleware::{auth_middleware, cors_middleware, rate_limiting_middleware, security_headers_middleware};
|
||||
use imphnen_middleware::{
|
||||
auth_middleware, cors_middleware, rate_limiting_middleware,
|
||||
security_headers_middleware,
|
||||
};
|
||||
use imphnen_storage::{MinioConfig, create_minio_service_from_config};
|
||||
use std::sync::Arc;
|
||||
use utoipa_swagger_ui::SwaggerUi;
|
||||
|
||||
pub mod docs;
|
||||
pub use docs::{ApiDoc, SecurityAddon, docs_router};
|
||||
|
||||
pub async fn gateway_service(
|
||||
postgres_clients: PostgresClients,
|
||||
) -> Router {
|
||||
let state = AppState {
|
||||
postgres_connection: postgres_clients.main.clone(),
|
||||
user_lookup_service: Arc::new(PostgresUserLookupService::new()),
|
||||
auth_repository: Arc::new(AuthRepoImpl::new()),
|
||||
};
|
||||
pub async fn gateway_service(postgres_clients: PostgresClients) -> Router {
|
||||
let state = AppState {
|
||||
postgres_connection: postgres_clients.main.clone(),
|
||||
user_lookup_service: Arc::new(PostgresUserLookupService::new()),
|
||||
auth_repository: Arc::new(AuthRepoImpl::new()),
|
||||
};
|
||||
|
||||
let db = state.postgres_connection.conn.clone();
|
||||
let state_arc = Arc::new(state.clone());
|
||||
let hackathon_config = Arc::new(HackathonConfig::from_env());
|
||||
let minio = Arc::new(
|
||||
create_minio_service_from_config(MinioConfig::from_env().expect("MinIO config required"))
|
||||
.await
|
||||
.expect("Failed to create MinIO service"),
|
||||
);
|
||||
let qr_pool = Arc::new(
|
||||
sqlx::PgPool::connect(
|
||||
&std::env::var("QR_DATABASE_URL").expect("QR_DATABASE_URL must be set"),
|
||||
)
|
||||
.await
|
||||
.expect("Failed to connect to QR database"),
|
||||
);
|
||||
let db = state.postgres_connection.conn.clone();
|
||||
let state_arc = Arc::new(state.clone());
|
||||
let minio = Arc::new(
|
||||
create_minio_service_from_config(
|
||||
MinioConfig::from_env().expect("MinIO config required"),
|
||||
)
|
||||
.await
|
||||
.expect("Failed to create MinIO service"),
|
||||
);
|
||||
let public_routes = Router::new()
|
||||
.merge(
|
||||
auth_public_routes(db.clone(), Arc::clone(&state_arc))
|
||||
.layer(from_fn(rate_limiting_middleware)),
|
||||
)
|
||||
.merge(testimonials_public_routes(db.clone()))
|
||||
.merge(events_public_routes(db.clone()))
|
||||
.merge(mentors_public_routes(db.clone(), Arc::clone(&state_arc)))
|
||||
.merge(sessions_public_routes(db.clone()));
|
||||
|
||||
let public_routes = Router::new()
|
||||
.merge(auth_public_routes(db.clone(), Arc::clone(&state_arc)).layer(from_fn(rate_limiting_middleware)))
|
||||
.merge(testimonials_public_routes(db.clone()))
|
||||
.merge(events_public_routes(db.clone()))
|
||||
.merge(mentors_public_routes(db.clone(), Arc::clone(&state_arc)))
|
||||
.merge(sessions_public_routes(db.clone()));
|
||||
let protected_routes = Router::new()
|
||||
.merge(users_protected_routes(db.clone(), Arc::clone(&state_arc)))
|
||||
.merge(roles_protected_routes(db.clone(), Arc::clone(&state_arc)))
|
||||
.merge(permissions_protected_routes(
|
||||
db.clone(),
|
||||
Arc::clone(&state_arc),
|
||||
))
|
||||
.merge(events_protected_routes(db.clone()))
|
||||
.merge(testimonials_protected_routes(db.clone()))
|
||||
.merge(mentors_protected_routes(db.clone(), Arc::clone(&state_arc)))
|
||||
.merge(sessions_protected_routes(
|
||||
db.clone(),
|
||||
Arc::clone(&state_arc),
|
||||
))
|
||||
.nest("/gacha", gacha_router(db.clone(), Arc::clone(&state_arc)))
|
||||
.layer(from_fn(auth_middleware));
|
||||
|
||||
let protected_routes = Router::new()
|
||||
.merge(users_protected_routes(db.clone(), Arc::clone(&state_arc)))
|
||||
.merge(roles_protected_routes(db.clone(), Arc::clone(&state_arc)))
|
||||
.merge(permissions_protected_routes(db.clone(), Arc::clone(&state_arc)))
|
||||
.merge(events_protected_routes(db.clone()))
|
||||
.merge(testimonials_protected_routes(db.clone()))
|
||||
.merge(mentors_protected_routes(db.clone(), Arc::clone(&state_arc)))
|
||||
.merge(sessions_protected_routes(db.clone(), Arc::clone(&state_arc)))
|
||||
.nest("/gacha", gacha_router(db.clone(), Arc::clone(&state_arc)))
|
||||
.layer(from_fn(auth_middleware));
|
||||
|
||||
Router::new()
|
||||
.route("/", get(Redirect::to("/docs")))
|
||||
.nest("/v1", public_routes.merge(protected_routes))
|
||||
.nest("/v1/hackathon", hackathon_router(db.clone(), hackathon_config, minio))
|
||||
.nest("/v1/qr", qr_router(qr_pool))
|
||||
.merge(SwaggerUi::new("/docs").url("/openapi.json", docs_router()))
|
||||
.layer(cors_middleware())
|
||||
.layer(from_fn(security_headers_middleware))
|
||||
.layer(Extension(state))
|
||||
Router::new()
|
||||
.route("/", get(Redirect::to("/docs")))
|
||||
.nest("/v1", public_routes.merge(protected_routes))
|
||||
.nest(
|
||||
"/v1/hackathon",
|
||||
hackathon_router(db.clone(), minio),
|
||||
)
|
||||
.nest("/v1/qr", qr_router(db.clone()))
|
||||
.merge(SwaggerUi::new("/docs").url("/openapi.json", docs_router()))
|
||||
.layer(cors_middleware())
|
||||
.layer(from_fn(security_headers_middleware))
|
||||
.layer(Extension(state))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user