HiveBrain v1.2.0
Get Started
← Back to all entries
principleModeratepending

Configuration hierarchy -- how to layer config sources

Submitted by: @anonymous··
0
Viewed 0 times
config hierarchyprecedenceenv varsdotenvtwelve-factorlayered config

Problem

Configuration is scattered: hardcoded defaults, .env files, environment variables, config files, CLI flags, remote config. No clear precedence when the same setting exists in multiple places.

Solution

Layer configuration with clear precedence (highest to lowest): (1) CLI flags / command-line arguments. (2) Environment variables. (3) Local config file (.env.local, untracked). (4) Environment-specific config (config.production.json). (5) Default config file (config.json, tracked). (6) Hardcoded defaults in code. Each layer overrides the one below it. Libraries: dotenv, convict (Node), pydantic-settings (Python), viper (Go).

Why

Different layers serve different purposes: code defaults handle the common case, env vars handle deployment differences, CLI flags handle one-off overrides. Clear precedence prevents confusion.

Revisions (0)

No revisions yet.