Skip to content

STD-DAT-002: Configuration Management

1. Context

"Magic Numbers" (e.g., let taxRate = 0.15) buried in code are the root cause of silent compliance failures. Business Rules must be auditable configurations, not compiled bytecode.

2. The Standard (The Floor)

  • [MUST] No Magic Numbers: Business constants (Tax Rates, Quorum %, Timeouts, Fee Amounts) MUST NOT exist in function bodies.
  • [MUST] Configuration Injection: Services must receive configuration as an input or read from a typed configuration object/service.
  • [MUST] Environment Awareness: Configuration that varies by environment (API Keys, Hostnames) MUST come from Environment Variables (.env).
  • [MUST] Business Awareness: Configuration that varies by business policy (Fee Amounts, Quorum Settings) MUST come from a Database or a const file in a dedicated config/ directory.

3. The Config Hierarchy

  1. Level 1: System Config (ENV Variables)
    • Examples: DB Connection strings, feature flags.
    • Location: process.env.
  2. Level 2: Domain Policy (Code Constants)
    • Examples: "Default Quorum = 0.51".
    • Location: packages/modules/[domain]/src/config.ts.
  3. Level 3: Runtime Config (Database)
    • Examples: "Current Fiscal Year Tax Rate".
    • Location: Settings table / PolicyEngine.

4. Implementation Pattern

// BAD
function calculateFee(amount) {
  return amount * 0.03; // Magic Number!
}

// GOOD
import { FINANCE_CONFIG } from "./config";
function calculateFee(amount) {
  return amount * FINANCE_CONFIG.FEES.DEFAULT_TRANSACTION_RATE;
}

5. Version History

Version Date Author Change
1.0 2026-02-03 Antigravity Initial Standard