Documentation

This commit is contained in:
2026-06-07 11:56:16 +02:00
parent 177e959bbd
commit 8fd35f3e82
18 changed files with 677 additions and 166 deletions
+11 -6
View File
@@ -25,11 +25,12 @@ use crate::env::Env;
/// Shared application state passed to all route handlers.
///
/// Contains the database connection pool and environment configuration.
/// This is wrapped in Arc for thread-safe sharing across async tasks.
/// This is wrapped in Arc for thread-safe sharing across async tasks and cloned into each route
/// via `with_state`.
///
/// # Fields
/// - `db`: PostgreSQL connection pool for database access
/// - `env`: Configuration loaded from environment variables
/// - `db`: PostgreSQL connection pool for database access (via `sqlx::PgPool`)
/// - `env`: [`Env`] configuration loaded from environment variables
pub struct AppState {
db: PgPool,
env: Env,
@@ -39,15 +40,19 @@ pub struct AppState {
///
/// Initializes the server by:
/// 1. Loading environment variables from `.env` file
/// 2. Establishing database connection pool
/// 2. Establishing database connection pool to PostgreSQL
/// 3. Configuring CORS policy for cross-origin requests
/// 4. Starting HTTP server on port 8001
/// 4. Creating the router with [`create_router`] containing all endpoints
/// 5. Starting HTTP server on port 8001
///
/// # Server Configuration
/// - Binds to `0.0.0.0:8001` (all network interfaces)
/// - Allows: GET, POST, PATCH, DELETE methods
/// - Allows credentials and custom headers
/// - CORS origin configured from environment
/// - CORS origin configured from [`Env`]
///
/// # State Setup
/// Creates shared [`AppState`] wrapped in `Arc` and passes to all routes
///
/// # Panics
/// - If environment loading fails