How silkagisomalepe/envinprod works
Purpose and Runtime
This is a minimal Python 3.12+ FastAPI teaching scaffold that prevents startup when required environment configuration is absent or invalid. It is run with Uvicorn, typically through uv run uvicorn app.main:app; dependency/runtime metadata is in pyproject.toml and uv.lock.
Entry Point and Boot Boundary
app/main.py exports the ASGI application object (app) and defines the HTTP surface, including the /health endpoint. Importing the application crosses the configuration boundary: settings validation occurs before the service can become available.
Paths: app/main.py, app/__init__.py
Configuration Contract
Settings centrally declares the required deployment inputs: database URL, API key, and debug mode. Pydantic Settings loads process environment values and .env, parses types, and reports missing/invalid fields.
Paths: app/config.py, .env.example
Fail-Fast Startup Gate
Configuration is instantiated during startup/import and validation errors cause an immediate process exit with status 1. This deliberately makes invalid configuration a deployment failure rather than allowing a partially configured server to accept traffic. Container/orchestration platforms can therefore block rollout based on process failure.
Paths: app/config.py, app/main.py
Secret Handling Boundary
The API key is modeled with Pydantic’s SecretStr, which masks its representation in diagnostic output. Code must explicitly unwrap the secret at the narrow external-client call site; this scaffold does not include database or third-party client integration.
Paths: app/config.py
Request Flow
With valid settings, Uvicorn loads app.main:app, FastAPI initializes, and requests reach the application routes. /health provides a simple liveness/readiness-style response and does not depend on the configured database or API key.
Paths: app/main.py, app/config.py
Deployment Inputs and External Dependencies
The service’s material external inputs are environment variables and optional local .env loading. .env.example documents the expected contract, while .gitignore keeps real .env secrets out of version control. The declared DATABASE_URL represents a downstream database dependency, but this repository does not establish a connection. No cloud service, database runtime, or secrets manager is implemented; those are explicitly future production concerns.
Paths: .env.example, .gitignore, app/config.py
Main entry points: config.py Settings · main.py ASGI app and routes · .env.example .env.example · .gitignore .gitignore
Components 12
Runtime
- Uvicorn
- Startup failure · Invalid or missing settings prevent the server from accepting traffic.
app/main.py
Application
- ASGI app and routes
app/main.py - /health · Responds without using database or API-key integrations.
app/main.py
Configuration
- Settings · Declares and validates required deployment inputs.
app/config.py - Process environment
- .env
- .env.example
.env.example - .gitignore · Excludes real .env secrets from version control.
.gitignore - API key · Masked unless explicitly unwrapped at an external-client call site.
app/config.py - Database URL · Represents a downstream dependency; no connection is implemented.
app/config.py
Other components
- Downstream database · Configured but not contacted by this scaffold.
Connections 11
- Uvicorn → ASGI app and routes: loads app.main:app
- ASGI app and routes → Settings: instantiates on import
- Process environment → Settings: loads values
- .env → Settings: optional load
- .env.example → Process environment: documents required values
- .gitignore → .env: keeps local secrets untracked
- Settings → API key: validates
- Settings → Database URL: validates
- Settings → Startup failure: validation error
- ASGI app and routes → /health: serves
- Database URL → Downstream database: declares target only