The federation
Federation runtime-config convention
How runtime config declared in a repo's data/ files — plans, storage, release notes — reaches the deployed environment.
Status: ratified 2026-09-23. Used by: forge-auth data/plans.yml, blueforge data/storage.yml + data/error-tracker.yml + data/release-notes.yml. Worked-example rollouts: forge-auth (4-PR beta cut, 2026-09-23), blueforge (3 migrations shipped).
TL;DR
Runtime config files live at <repo>/data/<purpose>.yml. They are loaded by the running app via a Zod-validated reader that mirrors src/services/socials/socials.ts. Env vars stay for secrets and build-time (NEXT_PUBLIC_*) values; everything else moves.
+----------------------------+ +-----------------------------+
| secrets (env var) | | runtime config (data/*.yml) |
| STRIPE_SECRET_KEY | | plans/prices/toggles/ttl |
| JWT_SECRET | | base URLs |
| *_API_KEY / *_TOKEN | | storage provider |
| DATABASE_URL | | feature flags |
| *_ADMIN_KEY | | service-endpoint choices |
+----------------------------+ +-----------------------------+
^ ^
| |
+-- vault-backed (forge-control vault) +-- versioned (git + PR)
per-host injection file watcher + cache()
When to use which
| Shape | Example | Why |
|---|---|---|
| env var (secret) | STRIPE_SECRET_KEY, JWT_SECRET, DATTER_*, *_ADMIN_KEY, *_TOKEN |
Per-host injection, vault-backed (source: vault), must NOT be in version control |
| env var (build-time) | NEXT_PUBLIC_SITE_URL |
Baked into the JS bundle at build time; per-env is fine because each env has its own build |
| env var (Node convention) | NODE_ENV, PORT |
Node tooling assumes these names |
| data/*.yml (runtime config) | plan prices, base URLs, feature toggles, TTLs, default IDs, storage provider choice | Versioned, PR-reviewable, changeable without redeploy |
| blueforge.config.json (deploy manifest) | server, ci.runner.packages, deploy.smoke.routes |
Read by the deploy runner, not the running app |
The line is: anything that's a secret or a deploy-time detail stays as an env var. Anything that's a policy or feature knob moves to data/*.yml.
Loader module pattern
// src/lib/<purpose>-config.ts
import { cache } from "react";
import fs from "fs";
import path from "path";
import yaml from "js-yaml";
import { z } from "zod";
const Schema = z.object({
schemaVersion: z.literal(1),
plans: z.array(z.object({ slug: z.string(), stripePriceId: z.string() /* ... */ })),
unmappedPaidPlan: z.string(),
});
export type PurposeConfig = z.infer<typeof Schema>;
export const loadPurposeConfig = cache((): PurposeConfig => {
const filePath = path.join(process.cwd(), "data", "<purpose>.yml");
const raw = fs.readFileSync(filePath, "utf-8");
return Schema.parse(yaml.load(raw) as unknown);
});
Lessons learned the hard way (forge-auth 2026-09-23 rollout)
- Resolve
process.cwd()at call time, not at module load time. If you cache it as aconstoutside the reader function, the value is captured once when the module loads. Tests thatprocess.chdir()to a temp directory (the usual test isolation pattern) will then read the wrong path. Usefunction dataFile(): string { return path.join(process.cwd(), "data", "<purpose>.yml"); }and call it inside the reader. - Export both a cached and an uncached reader. Tests use the uncached one to avoid vitest-worker-level React cache() memoisation. Production uses the cached one. Both share the same file-load + env-fallback + Zod logic; the cache is just a
cache(readFoo)wrapper.
// Recommended shape (split cached + uncached)
function loadFromFile(): FooConfig { ... }
function readFromEnv(): FooConfig | null { ... }
export function readFooConfig(): FooConfig {
try { return loadFromFile(); }
catch (fileErr) { /* env fallback, then loud throw */ }
}
export const loadFooConfig = cache(readFooConfig);
Memoisation primitive by stack
The convention is "memoised per process", but the mechanism is stack-specific:
| Stack | Use |
|---|---|
Next.js RSC (import "server-only" + server components) |
React.cache(readFooConfig) — memoises per request, naturally invalidated when the request lifecycle ends |
| Next.js route handlers (non-RSC) | Module-level singleton: let cached: T | null = null; function get(): T { return cached ??= readFooConfig(); } |
| Node services / standalone scripts | Module-level singleton (same as route handlers) |
forge-auth is a Next.js route-handler stack and confirmed (2026-09-23): module-level singleton is the right primitive for that case. The convention doc should distinguish "memoised per process" — the mechanism is stack-specific.
Caveats
Next.js standalone output bundle tracing
When output: "standalone" in next.config.ts, Turbopack traces static imports but cannot trace dynamic paths like path.join(process.cwd(), 'data', '<file>'). The result: the data file is NOT bundled into the standalone server, so the running container can't find it.
Fix — add an explicit outputFileTracingIncludes to next.config.ts:
const nextConfig = {
output: "standalone",
outputFileTracingIncludes: {
"/**": ["./data/<file>.yml"],
},
// ... rest
};
Forge-auth shipped this for data/plans.yml (2026-09-23). Blueforge has the same shape (output: "standalone" + data/storage.yml + data/error-tracker.yml + new data/release-notes.yml) and will need the same entry at the same time as the /release page PR.
Browser carve-out (Next.js specific)
NEXT_PUBLIC_* env vars are how Next.js inlines build-time config into the client JS bundle. Browser code cannot fs.readFileSync — there's no filesystem in the browser. So:
- Server-side runtime config →
data/*.ymlper this convention. - Client-bundled runtime config →
NEXT_PUBLIC_*env vars, baked at build time per environment.
The split point: if the value is read inside an import "server-only" module, YAML. If it's read inside a "use client" module or inline in a component, NEXT_PUBLIC_* env vars.
This is a Next.js framework carve-out, not a violation of the convention.
Scope-cutover protocol (when adding scope enforcement to existing routes)
If you have a route that mints keys/tokens with empty or default scopes, AND you add scope enforcement on routes that those keys call, the cutover breaks active sessions. Two options:
- (a) Mint with a default scope set — keys minted today work tomorrow. Users don't notice.
- (b) Ship a key-migration script — old keys are reissued with the new scopes on next use.
Forge-auth shipped (a) on 2026-09-23: device-flow mints with the default self-service scope set; users re-login get the default, existing keys break /me until they re-login. Document this as a "behavioural cutover" in the next handover so future-you knows it's intentional.
If you go with (a), make sure the default scope set is locked down before the enforcement ships — a default of ["*"] defeats the point.
Federation examples
| File | Repo | What it holds |
|---|---|---|
data/socials.yml |
blueforge | Social channels (X, LinkedIn, YouTube, etc.) |
data/products.yml |
blueforge | Catalog fallback for products not in registry |
data/ecosystems.yml |
blueforge | Ecosystem taxonomy |
data/taxonomies.yml |
blueforge | Categories + tags vocabulary |
data/plans.yml |
forge-auth | Plan prices, features, limits — replaces FORGE_AUTH_PLAN_PRICES (forge-auth main, commit 48433d9) |
data/storage.yml |
blueforge | Storage provider choice (fs/minio/s3) + bucket + fs root — replaces STORAGE_PROVIDER + ASSETS_DIR |
data/error-tracker.yml |
blueforge | Server-side error-tracker provider + endpoint — replaces FORGE_ERROR_TRACKER_URL |
data/release-notes.yml |
blueforge | Per-release notes (hand-seeded from forge-biz ROADMAP.md → ## Landed until taskmaster federation API lands — see forge-cloud docs/superpowers/specs/2026-09-16-task-loop-and-org-site-design.md §M4) |
data/stripe-prices.yml (planned) |
forge-control | Default price IDs — would replace STRIPE_DEFAULT_PRICE_ID |
Edge cases
- Missing file — during migration: fall back to env. After migration final: throw a loud error so CI catches it.
- YAML malformed — log error + return hardcoded fallback that fails loud (don't silently default — better to be loud than to silently downgrade pricing).
schemaVersionmismatch (file ahead of reader) — log error + return hardcoded fallback. Don't silently use newer fields you don't understand.- Per-env overrides — if you need staging/prod differences, prefer two separate files (
data/<purpose>.staging.yml,data/<purpose>.prod.yml) read by env-specific selector. Don't make one file that branches internally — it's a maintenance trap. - Secrets in YAML — never. If you find yourself wanting to put a secret in a runtime config file, that's a vault secret, not config.
When NOT to use this convention
- A single boolean toggle — put it in the env. Two-state config doesn't need a file.
- Per-host config (different on each deploy target) — env vars, possibly with vault-backed per-host injection.
- Config that's only read once at boot — env vars are fine.
- Config that's read by the deploy runner, not the running app —
blueforge.config.json(deploy manifest) is the right home.
Cross-session coordination
If a peer session proposes moving an env var to a runtime config file, the answer is yes, follow this convention. The peer should:
- Write the YAML file at
<repo>/data/<purpose>.yml - Add a
<purpose>-config.tsloader module - Migrate the consumer code
- Add a Zod test
- PR with the migration + a one-line note in this doc linking to the new example row in the table above
That keeps the federation consistent.
Related
- sidecar walker —
blueforge/docs/plans/2026-09-22-sidecar-walker.md(Phase A shipped). Validates sidecar V3 strict + V2 strict config + package.json freshness. - prod-audit —
blueforge-org/packages/audits/prod-audit/(Phase 1+2 shipped; Phase 3 = per-app landing flow). Runs the daily prod audit via.gitea/workflows/prod-audit.yml. - Newsletter / waitlist standard —
blueforge/claude/NEWSLETTER-WAITLIST.md. Federation wire shape for/api/send(POST → durable inbox → best-effort newsletter-os →{subscriberId|queued}).