First Project
First Project
Section titled “First Project”This walkthrough takes you from zero to a complete recipe ready for an AI coding agent. You will create a project, author a DDD aggregate, connect it to a USM story, validate a CBRL requirement, generate tests, and export a recipe.
Step 1: Create the Project
Section titled “Step 1: Create the Project”mkdir bookstore && cd bookstorectxbrew init --name bookstoreContextBrew creates the .contextbrew/ project structure in the current
directory, with directories for model files, recipes, and generated artifacts. All five first-class specification models are enabled by default.
Step 2: Define a DDD Aggregate
Section titled “Step 2: Define a DDD Aggregate”Models are plain text files on disk — author them in whatever editor you like. Create .contextbrew/ddd/book.domain:
AGGREGATE Book { PROPERTY id: UUID [pk] PROPERTY title: string [required] PROPERTY isbn: string [required, unique] PROPERTY price: number [required] PROPERTY status: string [default="draft"]
INVARIANT "isbn-format" EXPRESSION "isbn =~ /^[0-9]{10}([0-9]{3})?$/"}Validate the file:
ctx ddd validate .contextbrew/ddd/book.domainContextBrew parses the model and exits non-zero on any syntax or validation error — the same file also drives test generation later. Prefer drawing to typing? The same aggregate can be edited visually in Context Studio (the web UI) on the Svelte Flow canvas, where aggregates appear as nodes and associations as edges. AI agents can author models too, through the MCP server’s author tool.
Step 3: Add a USM Story
Section titled “Step 3: Add a USM Story”The USM model is JSON. Create .contextbrew/usm/bookstore.usm.json with a persona and a story that connects to the domain:
{ "kind": "usm-file", "schemaVersion": "0.2.0", "title": "Bookstore Story Map", "columns": ["Backlog", "Doing", "Done"], "releases": [ { "kind": "release", "id": "v1.0", "name": "MVP" } ], "personas": [ { "kind": "persona", "id": "P1", "name": "Bookstore Manager", "stories": [ { "kind": "user-story", "id": "US-001", "title": "Add new book to catalog", "description": "As a Bookstore Manager, I want to add books with a valid ISBN so the catalog stays clean", "column": "Backlog", "release": "v1.0", "acceptanceCriteria": [ "Given a valid ISBN, when I add a book, then it appears in the catalog", "Given an invalid ISBN, when I add a book, then I see a validation error" ] } ] } ]}ctx usm validate .contextbrew/usm/bookstore.usm.jsonNot sure who your users are? ctxbrew personas list shows the ten persona archetypes that ship with the starter library.
Step 4: Write a CBRL Requirement
Section titled “Step 4: Write a CBRL Requirement”Formalize the requirement in the ContextBrew Requirements Language. Create .contextbrew/cbrl/bookstore.requirements:
REQUIREMENT REQ-001 "Book catalog management" ACCEPTANCE_CRITERIA AC-001 "Only books with a valid ISBN are added to the catalog" ACCEPTANCE_CRITERIA AC-002 "Adding a book with an invalid ISBN shows a validation error" TEST_CASE TC-001 "Add book with valid ISBN succeeds" TEST_CASE TC-002 "Add book with invalid ISBN fails" INVOLVES_AGGREGATE Book LINKED_STORY US-001ctx cbrl validate .contextbrew/cbrl/bookstore.requirementsThe INVOLVES_AGGREGATE and LINKED_STORY lines create traceability links between the CBRL requirement, the DDD aggregate, and the USM story. ContextBrew computes these links bidirectionally. In CI, ctx cbrl check .contextbrew/cbrl/bookstore.requirements fails the build when a new error finding appears relative to a committed baseline.
Step 5: Generate Tests and Artifacts
Section titled “Step 5: Generate Tests and Artifacts”ctxbrew generateFrom the CBRL and DDD files, ContextBrew generates (into .contextbrew/generated/<target>/):
- Vitest unit tests pinning the ISBN invariant on the
Bookaggregate — failing-first scaffolds that pass once the implementation is real - Gherkin scenarios from the acceptance criteria
- OpenAPI fragments from the SCM/DSM models
- Prompt packs, Semgrep and ESLint rules, and CI pipeline artifacts (the other generation targets)
Generate one target at a time with --target vitest, or scope to a single aggregate with --aggregate Book.
Step 6: Create and Export a Recipe
Section titled “Step 6: Create and Export a Recipe”Bundle everything into a recipe for an AI coding agent:
ctxbrew recipe create --aggregate BookExport the recipe as a pasteable prompt:
ctxbrew recipe export --recipe 1The exported recipe contains:
- Domain context (the
Bookaggregate, its properties, and invariant) - The user story and its acceptance criteria
- The generated failing tests
- A work item checklist
Paste this into Claude Code, Cursor, or any AI agent — or hand it to the Execution Engine with ctxbrew generation create. The agent implements the code to make all tests pass.
You have:
- Created a ContextBrew project
- Authored a DDD aggregate with a business invariant — and validated it
- Connected it to a USM story with acceptance criteria
- Written a CBRL requirement with traceability links
- Generated failing-first tests, scenarios, and API fragments from your models
- Exported a recipe for an AI coding agent
Next Steps
Section titled “Next Steps”- Core Concepts to understand how the twelve models relate
- CBRL Syntax to learn the full requirements language
- Travel Booking Tutorial for a larger worked example
