Skip to content

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

  1. Python Version: Python 3.12 (as specified in Dockerfile).
  2. Environment Variables Alignment: .env.example, render.yaml, and app/core/config.py must contain identical keys. Unused or obsolete variables (like Pinecone configuration, following the PGVector migration) will be removed.
  3. Preflight Checks: The application must actively validate the presence of critical credentials (OPENAI_API_KEY, SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY) during startup, particularly when ENV=prod.
  4. Resiliency: The application should fail fast and explicitly if configuration constraints are violated in production.

Implementation Steps

  1. Refactor app/core/config.py to use a model_validator that performs strict checks on required keys if ENV is prod or production.
  2. Clean up .env.example to remove outdated variables and ensure it strictly matches the properties defined in app/core/config.py.
  3. Update render.yaml to ensure consistency with .env.example.
  4. Run pytest and mkdocs build --strict to verify functionality.