Runtime
Process model
The backend runs as a single FastAPI process:
- app creation in
app/main.py - Docker startup command
uvicorn app.main:app --host 0.0.0.0 --port ${PORT} - health endpoint at
/health - CORS configured from
CORS_ALLOWED_ORIGINSin production and open in non-prod
There is no dedicated worker deployment in render.yaml. Long-running ingestion work is started through FastAPI BackgroundTasks, and periodic tasks are registered with APScheduler during startup.
Request pipeline
The request path is:
RequestIDMiddlewareassigns or propagatesX-Request-ID.RateLimitMiddlewareapplies in-memory per-path limits.- FastAPI routes dispatch into the relevant router.
- Auth dependencies validate Supabase JWTs when required.
- Routers call shared services from
app/core/dependencies.py.
Important runtime characteristics:
- rate limiting is process-local and resets on restart
- metrics are in-memory, not backed by Prometheus client storage
- dependency instances are module singletons, created at import time
Dependency wiring
app/core/dependencies.py initializes:
- OpenAI client
- Supabase service-role client
- Pinecone adapter
- retrieval pipeline and quiz generator
- wallet service
- scraping and ingestion services
This keeps router code short, but it also means misconfigured environment variables usually fail at import time, not only at first request.
Environment variables in active use
The runtime directly consumes values from app/core/config.py, including:
OPENAI_API_KEY,OPENAI_CHAT_MODEL,OPENAI_REASONING_MODEL,OPENAI_RERANK_MODEL,OPENAI_EMBEDDING_MODELPINECONE_API_KEY,PINECONE_INDEX_NAME,PINECONE_NAMESPACE_DEFAULTSUPABASE_URL,SUPABASE_SERVICE_ROLE_KEY,SUPABASE_JWT_SECRETBASE_CHAT_COST,TOKEN_BUFFERRETRIEVAL_TOP_K,RERANK_TOP_NCHUNK_SIZE,CHUNK_OVERLAPENV,CORS_ALLOWED_ORIGINS
.env.example contains additional values that are planned or historical; the settings class in app/core/config.py is the reliable list of app-level configuration currently loaded by code.
Background execution
Two background patterns exist today:
- request-scoped ingestion execution via
BackgroundTasksin admin routes - process-scoped scheduled work via
app/services/background_jobs.py
Operational note:
- the scheduled reservation reconciliation code path is present but not aligned with the current wallet service implementation, so it should not be assumed healthy without explicit verification