Configuration Guide
This guide explains the SDD configuration system and how to use it effectively.
This guide explains the SDD configuration system and how to use it effectively.
This guide explains the SDD configuration system and how to use it effectively.
SDD uses a centralized configuration system where all config lives in a single component (`components/config/`). This provides:
Add to `components/config/envs/default/config.yaml`:
server-task-service:
port: 3000
logLevel: infoAdd to `components/config/envs/local/config.yaml`:
server-task-service:
logLevel: debug # More verbose for developmentAdd to `components/config/types/server.ts`:
export type ServerConfig = Readonly<{
port?: number;
logLevel?: 'debug' | 'info' | 'warn' | 'error';
}>;/sdd I want to generate config for localSDD_CONFIG_PATH=./local-config.yaml npm startcomponents/config/
├── package.json # Workspace package for type imports
├── tsconfig.json # TypeScript config
├── envs/
│ ├── default/
│ │ └── config.yaml # Base configuration (always merged first)
│ ├── local/
│ │ └── config.yaml # Local development overrides
│ └── {env}/
│ └── config.yaml # Other environments (add as needed)
├── schemas/
│ └── config.schema.json # JSON Schema for validation
└── types/
├── index.ts # Re-exports all config types
└── {component}.ts # Per-component type definitionsConfigs are merged in this order:
# envs/default/config.yaml
server-task-service:
port: 3000
database:
host: db.internal
pool: 10
# envs/local/config.yaml
server-task-service:
database:
host: localhost
# Result (merged):
server-task-service:
port: 3000 # Preserved from default
database:
host: localhost # Overridden by local
pool: 10 # Preserved from defaultTo add a new environment (e.g., staging):
/sdd I want to add a staging environmentThis creates `envs/staging/config.yaml` which inherits from `envs/default/`.
Components import types from the config package:
// In your server component
import type { ServerConfig } from '@my-project/config/types';
const config = loadConfig() as ServerConfig;
console.log(config.port); // TypeScript knows this is number | undefinedUpdate `schemas/config.schema.json` as your config evolves:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"server-task-service": {
"type": "object",
"properties": {
"port": { "type": "number", "minimum": 1, "maximum": 65535 },
"logLevel": { "enum": ["debug", "info", "warn", "error"] }
},
"required": ["port"]
}
}
}Validation runs:
Config contains secret **references**, not values:
server-task-service:
database:
host: db.production.internal
passwordSecret: "task-service-db-credentials" # K8s Secret nameAt deploy time, Helm maps references to actual secrets:
# In helm-task-service/templates/deployment.yaml
env:
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.config.database.passwordSecret }}
key: password /sdd I want to generate config for local SDD_CONFIG_PATH=./local-config.yaml npm run devThe generated `local-config.yaml` is gitignored.
/sdd I want to generate config for production helm install my-release ./components/helm-task-service \
-f values-production.yaml \
--set-file config=production-config.yamlTo see differences between environments:
/sdd I want to compare local and production configTo validate all environments:
/sdd I want to validate my configComponents should **never** know which environment they're running in. They receive config values and use them:
// Good - environment agnostic
const config = loadConfig();
if (config.features?.darkMode) {
enableDarkMode();
}
// Bad - checking environment
if (process.env.NODE_ENV === 'production') {
enableDarkMode();
}Only two places know about environments:
You need to set the path to your config file:
SDD_CONFIG_PATH=./local-config.yaml npm startGenerate the config file first:
/sdd I want to generate config for localCheck your config against the schema:
/sdd I want to validate my configThe error message will include which fields are invalid.
Ensure the config package is in your dependencies:
{
"dependencies": {
"@my-project/config": "workspace:*"
}
}Run `npm install` to link the workspace package.