Runtime and Configuration Contract Baseline
Goal
Establish and enforce a single, unified configuration contract for the BacMR backend. This ensures that all environments (local, testing, staging, and production) share exactly the same set of environment variables, with explicit preflight checks to prevent silent failures or misconfigurations in production.
Target State
- Python Version: Python 3.12 (as specified in
Dockerfile). - Environment Variables Alignment:
.env.example,render.yaml, andapp/core/config.pymust contain identical keys. Unused or obsolete variables (like Pinecone configuration, following the PGVector migration) will be removed. - Preflight Checks: The application must actively validate the presence of critical credentials (
OPENAI_API_KEY,SUPABASE_URL,SUPABASE_SERVICE_ROLE_KEY) during startup, particularly whenENV=prod. - Resiliency: The application should fail fast and explicitly if configuration constraints are violated in production.
Implementation Steps
- Refactor
app/core/config.pyto use amodel_validatorthat performs strict checks on required keys ifENVisprodorproduction. - Clean up
.env.exampleto remove outdated variables and ensure it strictly matches the properties defined inapp/core/config.py. - Update
render.yamlto ensure consistency with.env.example. - Run
pytestandmkdocs build --strictto verify functionality.