Environment Management
Purpose
Make configuration across environments predictable and safe: the same artifact everywhere, differing only by injected, validated config — so environments stay in parity and misconfiguration fails loudly at startup, not silently in production.
When to Use
- When defining how dev/staging/production configuration works for an app or service.
- Not for secret storage/rotation mechanics (
secrets-management) or test envs (../../testing/test-environment-management).
Inputs
- The environments (dev, staging, production, preview) and what legitimately differs.
- The apps and their runtimes (server config vs client-bundle constraints).
Discovery Questions
- What differs per environment (URLs, feature flags, limits) — and what must not (behavior, code)?
- Which config is public (safe in a client bundle) vs secret (server-only)?
- How is required config validated so a missing/malformed value stops boot rather than causing later failures?
Responsibilities
- Establish one immutable artifact configured by environment (
../../backend/backend-deployment, docker-foundation) — no per-environment builds; config injected at runtime.
- Define a typed, validated config schema: required vars present and well-formed, checked at boot (fail fast) with a clear error naming the missing/invalid var (
../../backend/backend-security, ../../environment-audit).
- Enforce the public/secret boundary: client bundles carry only public config (anything shipped to the browser/app is public); secrets stay server-side (
secrets-management). No NEXT_PUBLIC_/EXPO_PUBLIC_-style exposure of secrets.
- Maintain parity: staging mirrors production config shape (
staging-environment); differences are values, not structure — divergence is where "works in staging, breaks in prod" is born.
- Provide a documented config template (e.g.
.env.example) listing every var with type/purpose; real .env files git-ignored.
- Coordinate change: config changes are reviewed and rolled out like code, not hand-edited in a console untracked.
Required Workflow
- Enumerate environments + what legitimately differs.
- Define the typed config schema (required/optional, formats).
- Add boot-time validation that fails fast with clear messages.
- Enforce the public/secret split; keep secrets server-side.
- Ensure parity + a documented config template; git-ignore real values.
Decision Rules
- Same artifact, config-injected — per-environment builds break parity and reproducibility.
- Validate at boot: a false start with a clear error beats a silent misconfiguration surfacing hours later.
- Anything in a client bundle is public — treat it that way, no exceptions.
- Config structure is identical across environments; only values differ.
Rules
- Real secret values never committed; template lists vars without values.
- Required config validated before the app serves traffic.
- Config changes tracked and reviewed, not console-hand-edited.
Anti-Patterns
- Building a separate artifact per environment.
- Secrets shipped in client bundles via public env prefixes.
- Missing env var discovered as a runtime crash mid-request, not at boot.
- Staging config structurally diverging from production.
- Untracked console edits to production config.
Validation Checklist
Definition of Done
One artifact configured per environment with a typed, boot-validated config schema, a strict public/secret boundary, staging↔production parity, and a documented template — misconfiguration fails fast, secrets never reach clients.
Related Skills
secrets-management, staging-environment, ../../backend/backend-deployment, docker-foundation, ../../environment-audit, ../../backend/backend-security, ../../testing/test-environment-management.
Related Knowledge
../../../knowledge/ (environment topology, config inventory).
Related References
../../../references/devops/ (config templates, when populated).
Context Loading Guidance
- Requires: environment list, config inventory, app runtimes.
- Does not require: secret values, app feature code.
- May load:
secrets-management, staging-environment.
- Stop when: schema, validation, boundary, and parity are recorded.
Token Efficiency Guidance
The config schema table (var, type, required, public/secret, per-env differences) is the artifact.
1---2name: environment-management3description: Use to plan environment configuration across dev/staging/production — one immutable artifact configured by environment, validated typed env vars (fail fast at boot), no secrets in client bundles, and parity so behavior differs only by config. Secret storage itself is secrets-management.4---56# Environment Management78## Purpose910Make configuration across environments predictable and safe: the **same artifact** everywhere, differing only by injected, **validated** config — so environments stay in parity and misconfiguration fails loudly at startup, not silently in production.1112## When to Use1314- When defining how dev/staging/production configuration works for an app or service.15- **Not** for secret storage/rotation mechanics (`secrets-management`) or test envs (`../../testing/test-environment-management`).1617## Inputs1819- The environments (dev, staging, production, preview) and what legitimately differs.20- The apps and their runtimes (server config vs client-bundle constraints).2122## Discovery Questions2324- What differs per environment (URLs, feature flags, limits) — and what must **not** (behavior, code)?25- Which config is public (safe in a client bundle) vs secret (server-only)?26- How is required config validated so a missing/malformed value stops boot rather than causing later failures?2728## Responsibilities2930- Establish **one immutable artifact configured by environment** (`../../backend/backend-deployment`, `docker-foundation`) — no per-environment builds; config injected at runtime.31- Define a **typed, validated config schema**: required vars present and well-formed, checked at **boot (fail fast)** with a clear error naming the missing/invalid var (`../../backend/backend-security`, `../../environment-audit`).32- Enforce the **public/secret boundary**: client bundles carry only public config (anything shipped to the browser/app **is** public); secrets stay server-side (`secrets-management`). No `NEXT_PUBLIC_`/`EXPO_PUBLIC_`-style exposure of secrets.33- Maintain **parity**: staging mirrors production config shape (`staging-environment`); differences are values, not structure — divergence is where "works in staging, breaks in prod" is born.34- Provide a documented config template (e.g. `.env.example`) listing every var with type/purpose; real `.env` files git-ignored.35- Coordinate change: config changes are reviewed and rolled out like code, not hand-edited in a console untracked.3637## Required Workflow38391. Enumerate environments + what legitimately differs.402. Define the typed config schema (required/optional, formats).413. Add boot-time validation that fails fast with clear messages.424. Enforce the public/secret split; keep secrets server-side.435. Ensure parity + a documented config template; git-ignore real values.4445## Decision Rules4647- Same artifact, config-injected — per-environment builds break parity and reproducibility.48- Validate at boot: a false start with a clear error beats a silent misconfiguration surfacing hours later.49- Anything in a client bundle is public — treat it that way, no exceptions.50- Config structure is identical across environments; only values differ.5152## Rules5354- Real secret values never committed; template lists vars without values.55- Required config validated before the app serves traffic.56- Config changes tracked and reviewed, not console-hand-edited.5758## Anti-Patterns5960- Building a separate artifact per environment.61- Secrets shipped in client bundles via public env prefixes.62- Missing env var discovered as a runtime crash mid-request, not at boot.63- Staging config structurally diverging from production.64- Untracked console edits to production config.6566## Validation Checklist6768- [ ] Environments + legitimate differences enumerated.69- [ ] Typed config schema with boot-time fail-fast validation.70- [ ] Public/secret boundary enforced; no secrets in client bundles.71- [ ] Parity maintained; documented template; real values git-ignored.72- [ ] Config changes tracked/reviewed.7374## Definition of Done7576One artifact configured per environment with a typed, boot-validated config schema, a strict public/secret boundary, staging↔production parity, and a documented template — misconfiguration fails fast, secrets never reach clients.7778## Related Skills7980`secrets-management`, `staging-environment`, `../../backend/backend-deployment`, `docker-foundation`, `../../environment-audit`, `../../backend/backend-security`, `../../testing/test-environment-management`.8182## Related Knowledge8384`../../../knowledge/` (environment topology, config inventory).8586## Related References8788`../../../references/devops/` (config templates, when populated).8990## Context Loading Guidance9192- **Requires:** environment list, config inventory, app runtimes.93- **Does not require:** secret values, app feature code.94- **May load:** `secrets-management`, `staging-environment`.95- **Stop when:** schema, validation, boundary, and parity are recorded.9697## Token Efficiency Guidance9899The config schema table (var, type, required, public/secret, per-env differences) is the artifact.