Architecture
This page is a guided tour of the system. You don’t need to read it to use ContextBrew — but if you want to understand why things work the way they do, start here.
The five-minute version
Section titled “The five-minute version”You write specs ContextBrew compiles them An AI agent receives in the IDE into tests + types + recipes a recipe, writes code ────────────── ─────────────────────────── ─────────────────── DDD, USM, CBRL, generators + DeltaEngine, until the tests pass, SCM, DSM, … trace, Recipe Server gets reviewed by youThree things matter here:
- Specs are the source of truth. Code is a downstream artifact.
- Generators are deterministic. Same spec in, same artifacts out. If the artifacts changed, the spec changed.
- Recipes are the contract. The agent gets failing tests and context; it implements until the tests pass. No ambiguity.
The architecture, top to bottom
Section titled “The architecture, top to bottom”┌──────────────────────────────────────────────────────────────────┐│ Context Studio (the IDE — apps/web) ││ ││ Models phase ─┐ ││ Plan phase ────┤ ││ Build phase ───┼── reads specs, drives generators + execution ││ Observe phase ─┤ ││ Settings ──────┘ │└───────┬───────────────────────────────────────────────┬──────────┘ │ │ │ edits specs (.domain, .usm, .requirements, .scm, .dsm, …)│ ▼ │┌──────────────────────────────────────────┐ ││ Parser layer (packages/core/src/parser/) │ ││ - ddd/ - usm/ - scm/ - cbrl/ │ ││ - dsm/ - sim/ - absl/ - c4/ │ ││ - context-map/ - esdm/ - decision/ │ │└───────┬──────────────────────────────────┘ │ │ AST │ ▼ │┌──────────────────────────────────────────┐ ││ Generators + DeltaEngine │ ││ - gherkin, unit, e2e, nav, schema tests│ ││ - type stubs, OpenAPI specs │ ││ - recipe assembler │ ││ - semantic diff │ │└───────┬──────────────────────────────────┘ │ │ artifacts + recipe │ ▼ │┌──────────────────────────────────────────┐ recipe ││ Recipe Server (services/recipe_server) │── export ─▶│ AI Agent│ - LakeFS-inspired zero-copy branching │ │ (Claude Code,│ - semantic diffing │ │ Cursor, …)│ - 3-way merge │ │└──────────────────────────────────────────┘ │ ▲ │ │ tests pass │ └───────────── review + accept ◀─────────────────┘What each layer does
Section titled “What each layer does”Specs (your models directory)
Section titled “Specs (your models directory)”The models directory holds one file per modeling language — plain JSON or plain text. You can edit these files by hand, through the IDE, through the CLI, or by importing from another tool. The files are the canonical source; everything else is derived.
A single line in models/ddd.json:
{ "kind": "ddd-file", "schemaVersion": "0.1.0", "aggregates": [ { "kind": "aggregate", "name": "Order", "properties": [...], "invariants": [...] } ]}That’s all the platform needs. Everything else flows from there.
Parser layer
Section titled “Parser layer”Each spec language has its own parser. The parser reads the file and returns an AST (abstract syntax tree) — a strongly-typed representation that the rest of the platform uses uniformly.
Two important properties:
- Every parser produces the same AST shape for the same language. If you write the spec by hand or generate it from somewhere else, the parser sees the same thing.
- Every AST validates against a schema. If your spec is invalid, the parser tells you why with a precise error.
Generators + DeltaEngine
Section titled “Generators + DeltaEngine”This is where specs become artifacts. The generators take ASTs and produce:
- Tests — unit, behavior, navigation, schema, migration, access
- Type stubs — TypeScript interfaces for every model element
- OpenAPI specs — derived from aggregate operations and screen flows
- Recipes — bundled context + failing tests + work items
The DeltaEngine tracks what’s changed between two versions of a spec and only regenerates the affected artifacts. This is how iterative development stays fast — you change one invariant and only the affected tests need to come along for the ride.
Recipe Server
Section titled “Recipe Server”Recipes are version-controlled. The Recipe Server stores every version of every recipe with zero-copy branching (the same trick LakeFS uses for objects):
- A branch is just a pointer — it costs nothing to create
- A tag is an immutable reference to a specific state
- A merge combines two recipe histories using 3-way merge
- A semantic diff shows what changed in domain terms (“this invariant was added”), not line terms
The Recipe Server is the Git-for-specs piece. If you’ve used Git, you already know how to use it.
AI agent (the consumer)
Section titled “AI agent (the consumer)”A recipe has one consumer: an AI coding agent. The agent receives:
- The full context (the model elements the recipe touches, in full)
- The failing tests (so it knows what “done” means)
- The type stubs (so it doesn’t have to guess at interfaces)
- The work items (so it knows the order to do things)
- The prose prompt (so it has a sentence to anchor the work)
The agent’s job is to make the tests pass. When they pass, you review the diff and either accept or iterate.
The Execution Engine (services/recipe_server + apps/cli)
Section titled “The Execution Engine (services/recipe_server + apps/cli)”The Execution Engine is the part that automates the agent loop. You give it a recipe id; it picks a provider (Anthropic, OpenAI, Google, Ollama); it sends the prompt; it captures the response; it runs the generated tests; it stores everything as a generation.
The Execution Engine is optional. You can always run the agent loop manually (paste the prompt, write the code, run the tests). The Execution Engine is the workflow for when you don’t want to.
The IDE (Context Studio, apps/web)
Section titled “The IDE (Context Studio, apps/web)”Context Studio is the browser-based IDE. It has:
- A visual canvas for every model (DDD, USM, SCM, DSM, C4, context-map)
- A text editor for CBRL, ABSL (split/text mode), and decision
- Read-only panes for Decision (
.dec) and ESDM (YAML) files - A DSM ERD editor plus a DSM DSL authoring form (the serialized file stays
.dsm.json) - A version timeline panel: browse Recipe Server versions, preview any version, and pin a DDD aggregate for focused time travel
- The Plan phase for poker sessions and release planning
- The Build phase for running the Execution Engine
- The Observe phase for diff, replay, and audit log
- Settings for keys, theme, agents, keybindings
The IDE is a thin layer over the spec files. Every save writes a file to disk. Closing the tab and opening Vim gives you the same editing experience as the IDE. (You will lose the visual canvas, but the files are still the source of truth.)
The two guarantees, restated
Section titled “The two guarantees, restated”1. Specs are the source of truth
Section titled “1. Specs are the source of truth”Every artifact ContextBrew produces is derived from a spec. The artifact has a hash; the hash is in the spec; the spec is in git. If you trust your spec, you trust the artifacts. If you don’t trust an artifact, find the spec that generates it and fix that.
2. The tooling refuses rather than warns
Section titled “2. The tooling refuses rather than warns”Drift fails the build. Lost work fails the commit. A checker that can fail open is itself a defect. The Methodology page explains how this discipline developed and what it costs.
Where to go next
Section titled “Where to go next”| You want to… | Go to |
|---|---|
| Look up a term | Glossary |
| Try it | Quick Start |
| Decide which model to start with | Which model do I need? |
| See questions answered | FAQ |
| See the methodology | The ContextBrew SDLC |
