Ir al contenido

ADR-006 — Environment Variables

Accepted

The project needs environment variables to configure the database, security, CORS, and auth. Some are common to all environments, others are exclusive to local development, and others only exist in production. Mixing them or not documenting the separation leads to incomplete .env files or secrets accidentally committed to the repository.

A single .env at the project root (copied from .env.example). Docker Compose injects it into the api container. The Angular frontend does not use .env — build variables are configured in Amplify Console in production.

Common (dev and prod). Variables required in all environments.

VariableDescriptionDefault dev
DJANGO_SETTINGS_MODULEActive settings moduleconfig.settings.local
POSTGRES_DBDatabase namekdx_ng
POSTGRES_USERPostgreSQL userkdx_ng
POSTGRES_PASSWORDPostgreSQL passwordkdx_ng
POSTGRES_HOSTDatabase hostdb (Docker)
POSTGRES_PORTPostgreSQL port5432
LOCALTrue/False flag — affects cookies and CSPTrue
CORS_ALLOWED_ORIGINSCORS origins, comma-separatedhttp://localhost:4200
COVERIS_PAGE_SIZEDRF pagination page size25

Development only. Variables exclusive to local dev; not present in production.

VariableDescriptionDefault dev
DJANGO_SECRET_KEYDjango secret keyauto-generated (warning)
SUPERUSER_PASSWORDPassword for the superuser created at bootlocaldev123
SUPERUSER_EMAILSuperuser emailrequired
SUPERUSER_GIVEN_NAMESuperuser first namerequired
SUPERUSER_FAMILY_NAMESuperuser last namerequired
MOCK_USER_PASSWORDPassword for seeded mock usersclinic2026!

[!note] Dev secret key & superuser bootstrap DJANGO_SECRET_KEY is optional in dev — if not set, Django generates one in memory with a warning. Sessions do not persist between container restarts.

SUPERUSER_EMAIL, SUPERUSER_GIVEN_NAME, and SUPERUSER_FAMILY_NAME have no fallback defaults — the create_superuser command fails if they are missing. Recommended values are provided in .env.example.

Production only. Variables injected by AWS infrastructure ([[adr-003-a-backend-prod-stack|ADR-003-a]], [[adr-008-authentication|ADR-008]]); never set in .env.

VariableDescriptionSource
DJANGO_SECRET_KEYDjango secret keyAWS Secrets Manager
ALLOWED_HOSTSAllowed hosts, comma-separatedApp Runner env vars
POSTGRES_HOSTRDS endpointAWS Secrets Manager
POSTGRES_PASSWORDRDS passwordAWS Secrets Manager
WEB_CONCURRENCYUvicorn worker countApp Runner env vars
COGNITO_USER_POOL_IDCognito User Pool IDApp Runner env vars
COGNITO_CLIENT_IDCognito Client IDApp Runner env vars
COGNITO_REGIONAWS region for CognitoApp Runner env vars

[!note] Production settings In production, DJANGO_SETTINGS_MODULE=config.settings.production and LOCAL=False.

ALLOWED_HOSTS is only read from the environment in production settings. In development, it is hardcoded in local.py.

  • .env is never committed — it is in .gitignore. Only .env.example lives in the repository.
  • The Angular frontend has no .env; in production, build variables are injected in Amplify Console as NG_APP_* and accessed from environment.prod.ts.
  • Any new variable must appear first in .env.example (with a dev value) and in this ADR before being used in code.