env
Environment variables and .env strategy (full-stack)
This document explains how environment variables are managed across the monorepo (front, back, docs-site) and how to configure them for local development, Docker, and production.
Principles and precedence
- Per-service
.envfiles are the primary source for local development. Each service (front/, back/, docs-site/) should include a.env.exampledescribing required variables. - Runtime environment (CI, Docker build args, platform env) overrides per-service
.envvalues and is authoritative in production. - Root
.envis discouraged and not used; keep per-service examples and copy them to.envwhen developing locally. - Never commit real secrets. Use CI/Platform secret stores for production values.
Per-service notes
-
Frontend (front/)
- Template:
front/.env.local.example→ copy tofront/.env.localfor local dev. - Key var: PUBLIC_PARTYKIT_HOST (Mode A: localhost:1999; Mode B/Docker: localhost:4321 baked at build time)
- In Docker mode the build injects the correct host; do not rely on local
.env.localfor Docker builds.
- Template:
-
Backend (back/)
- Template:
back/.env.exampledocuments backend-only envs. - Durable Object bindings (KV, etc.) are configured in
wrangler.tomland secrets are created viawrangler secret putor set in CI. Do not rely on.envfor production DO bindings.
- Template:
-
Docs (docs-site/)
- Template:
docs-site/.env.example→ copy todocs-site/.envto mirror production (DOCS_BASE_URL=/docs) or set to/for root serving. - The Dockerfile accepts
--build-arg DOCS_BASE_URLto bake the base URL at build time.
- Template:
How to use locally
-
Copy the appropriate example into a
.env(or.env.localfor the front) in the service folder:cd front && cp .env.local.example .env.local cd back && cp .env.example .env cd docs-site && cp .env.example .env
-
Install dependencies and run the service (example for docs-site):
cd docs-site npm ci npm run build:local # uses DOCS_BASE_URL from .env npm run serve:build
Docker and CI
- Docker builds should pass necessary build args or envs explicitly; do not bake secrets into images.
Example:
docker build --build-arg DOCS_BASE_URL=/docs -t sommelier-docs . - CI should set required environment variables via secrets and pass them into build jobs. Runtime envs in CI override
.envfiles.
Troubleshooting
- If a local build yields incorrect base paths, ensure
DOCS_BASE_URLis set in the service's.envor passed via the build command. - To verify which vars are picked up, run a local script that prints key env vars (do not print secrets to logs).
Where to find examples
- front/.env.local.example
- back/.env.example
- docs-site/.env.example
Change log
- Consolidated environment guidance into this file; removed redundant CONTRIBUTING.md at repository root to avoid duplication.
If you want this doc promoted into a top-level CONTRIBUTING.md instead, say so and it can replace the deleted file.