Skip to content

Travel Booking App

This tutorial walks you through building a travel booking application using all five ContextBrew models. You will define the domain, user stories, requirements, screens, and data schema – then generate tests and export recipes for an AI coding agent.

  • ContextBrew CLI installed (ctxbrew --version should return a version number)
  • Basic familiarity with DDD concepts and CBRL syntax

There is no model command family — models are plain text files you own, one per format, under .contextbrew/. Every format has a deterministic parser and a normative JSON Schema (ctxbrew schema <format> prints it), and every format gets the same five-command toolkit:

Terminal window
ctxbrew <format> validate <file> # parse + validate (exit 1 on any error)
ctxbrew <format> stats <file> # collection sizes (aggregates, tables, screens…)
ctxbrew <format> export <file> # canonical DSL (default), --format json|yaml, or --to <exporterId>
ctxbrew <format> import <file> # canonicalization pass
ctxbrew <format> diff <a> <b> # semantic diff of two snapshots (report only)

You author in your editor (or on the Studio canvases), then validate. That loop is this whole tutorial.

Terminal window
mkdir travel-booking && cd travel-booking
ctxbrew init --name travel-booking

This creates .contextbrew/ with a folder per model family (ddd/, usm/, cbrl/, scm/, dsm/), plus generated/ and recipes/.

The travel booking domain has three core aggregates: Booking, Flight, and Passenger. Create .contextbrew/ddd/booking.domain:

AGGREGATE Flight {
PROPERTY id: UUID [pk]
PROPERTY flightNumber: string [required, unique]
PROPERTY origin: string [required]
PROPERTY destination: string [required]
PROPERTY departureTime: Date [required]
PROPERTY availableSeats: number [required, min=0]
PROPERTY basePrice: number [required, min=1]
INVARIANT "seats-non-negative"
EXPRESSION "availableSeats >= 0"
INVARIANT "route-valid"
EXPRESSION "origin != destination"
}
AGGREGATE Passenger {
PROPERTY id: UUID [pk]
PROPERTY firstName: string [required]
PROPERTY lastName: string [required]
PROPERTY email: string [required, unique]
PROPERTY passportNumber: string [unique]
INVARIANT "passport-format"
EXPRESSION "passportNumber matches /^[A-Z0-9]{9}$/"
}
AGGREGATE Booking {
PROPERTY id: UUID [pk]
PROPERTY passengerId: UUID [required]
PROPERTY flightId: UUID [required]
PROPERTY status: string [default="pending"]
PROPERTY bookingDate: Date [required]
PROPERTY totalPrice: number [required, min=0]
INVARIANT "valid-status"
EXPRESSION "status IN ('pending', 'confirmed', 'checked-in', 'completed')"
INVARIANT "cancellable-states"
EXPRESSION "status NOT IN ('completed') WHEN cancellationReason IS NOT NULL"
}

Then validate and inspect:

Terminal window
ctxbrew ddd validate .contextbrew/ddd/booking.domain # exit 1 on any parse/validation error
ctxbrew ddd stats .contextbrew/ddd/booking.domain # aggregates: 3

Create .contextbrew/usm/booking.usm.json — a Traveler persona and three stories with acceptance criteria:

{
"kind": "usm-file",
"schemaVersion": "0.2.0",
"title": "Travel Booking User Story Map",
"columns": ["Discovery", "Booking", "Management"],
"releases": [
{ "kind": "release", "id": "v1.0", "name": "MVP" }
],
"personas": [
{
"kind": "persona",
"id": "P1",
"name": "Traveler",
"stories": [
{
"kind": "user-story",
"id": "US-001",
"title": "Search for flights",
"priority": 1,
"acceptanceCriteria": [
{ "kind": "acceptance-criteria", "id": "AC-US1-01",
"description": "Given flights exist, when I search by route and date, then matching flights appear" },
{ "kind": "acceptance-criteria", "id": "AC-US1-02",
"description": "Given no flights match, when I search, then I see a 'no results' message" }
]
},
{
"kind": "user-story",
"id": "US-003",
"title": "Book a flight",
"priority": 1,
"acceptanceCriteria": [
{ "kind": "acceptance-criteria", "id": "AC-US3-01",
"description": "Given an available flight, when I book it, then a pending booking is created" }
]
},
{
"kind": "user-story",
"id": "US-006",
"title": "Check in for flight",
"priority": 2,
"acceptanceCriteria": [
{ "kind": "acceptance-criteria", "id": "AC-US6-01",
"description": "Given a confirmed booking, when I check in, then the booking status becomes checked-in" }
]
}
]
}
]
}
Terminal window
ctxbrew usm validate .contextbrew/usm/booking.usm.json

Create .contextbrew/cbrl/booking.requirements:

REQUIREMENT REQ-001 "Flight search"
ACCEPTANCE_CRITERIA AC-001 "Matching flights appear sorted by price"
ACCEPTANCE_CRITERIA AC-002 "No-match searches show an explicit empty state"
TEST_CASE TC-001 "Search by valid route and date returns matching flights"
TEST_CASE TC-002 "Search with no available seats returns empty"
INVOLVES_AGGREGATE Flight
LINKED_STORY US-001
ASPECT accessibility(level: "wcag-aa")
REQUIREMENT REQ-002 "Flight booking"
ACCEPTANCE_CRITERIA AC-003 "Booking an available flight creates a pending booking"
ACCEPTANCE_CRITERIA AC-004 "Available seats decrease by 1 on booking"
ACCEPTANCE_CRITERIA AC-005 "Booking a flight with 0 available seats is rejected"
TEST_CASE TC-003 "Create booking for fully booked flight fails"
INVOLVES_AGGREGATE Booking
INVOLVES_AGGREGATE Flight
LINKED_STORY US-003
ASPECT security(level: "critical")
ASPECT audit(action: "create", entity: "booking")
REQUIREMENT REQ-003 "Check-in"
ACCEPTANCE_CRITERIA AC-006 "Check-in moves a confirmed booking to checked-in"
INVOLVES_AGGREGATE Booking
LINKED_STORY US-006
ASPECT audit(action: "check-in", entity: "booking")

Validate it, and run the CI gate that fails on new error findings (warnings never gate):

Terminal window
ctxbrew cbrl validate .contextbrew/cbrl/booking.requirements
# CI gate: exit 1 on new error findings vs the baseline; --ddd makes the
# DDD aggregates the source of truth for strict INVOLVES_AGGREGATE resolution
ctxbrew cbrl check .contextbrew/cbrl/booking.requirements --ddd .contextbrew/ddd/booking.domain

Want a shareable requirements document? ctxbrew cbrl publish .contextbrew/cbrl/booking.requirements --title "Travel Booking Requirements" emits a self-contained HTML spec pack.

Create .contextbrew/scm/booking.scm.json — five screens and the navigation flow between them:

{
"kind": "scm-file",
"schemaVersion": "0.3.0",
"screens": [
{ "kind": "screen", "id": "flight-search", "name": "Flight Search",
"route": "/flights", "aggregate": "Flight", "stories": ["US-001"],
"requirements": ["REQ-001"] },
{ "kind": "screen", "id": "flight-results", "name": "Flight Results",
"route": "/flights/search", "aggregate": "Flight", "stories": ["US-001"] },
{ "kind": "screen", "id": "booking-form", "name": "Booking Form",
"route": "/bookings/new", "aggregate": "Booking", "stories": ["US-003"],
"requirements": ["REQ-002"] },
{ "kind": "screen", "id": "booking-confirmation", "name": "Booking Confirmation",
"route": "/bookings/:id", "aggregate": "Booking", "stories": ["US-003"] },
{ "kind": "screen", "id": "check-in", "name": "Check-In",
"route": "/bookings/:id/checkin", "aggregate": "Booking", "stories": ["US-006"],
"requirements": ["REQ-003"] }
],
"navigations": [
{ "kind": "navigation", "id": "nav-1", "source": "flight-search",
"target": "flight-results", "trigger": "User submits search", "navType": "push" },
{ "kind": "navigation", "id": "nav-2", "source": "flight-results",
"target": "booking-form", "trigger": "User selects a flight", "navType": "push" },
{ "kind": "navigation", "id": "nav-3", "source": "booking-form",
"target": "booking-confirmation", "trigger": "User confirms booking", "navType": "push" },
{ "kind": "navigation", "id": "nav-4", "source": "booking-confirmation",
"target": "check-in", "trigger": "User clicks check-in", "navType": "push" }
],
"flows": [
{ "kind": "flow", "id": "booking-flow", "name": "Booking Flow",
"description": "Search, book, and check in for a flight",
"steps": [
{ "screen": "flight-search", "action": "Enter search criteria" },
{ "screen": "flight-results", "action": "Select a flight" },
{ "screen": "booking-form", "action": "Fill passenger details" },
{ "screen": "booking-confirmation", "action": "Confirm booking" },
{ "screen": "check-in", "action": "Check in" }
] }
]
}
Terminal window
ctxbrew scm validate .contextbrew/scm/booking.scm.json

Already have an app? Skip hand-authoring and discover the screens from route-file conventions (Next.js App Router, Expo Router, React Router), optionally diffing against a committed SCM model:

Terminal window
ctxbrew scm discover src/app --framework auto \
--drift-vs .contextbrew/scm/booking.scm.json --fail-on-drift

Two honest paths, depending on where your schema lives:

Pull it from a live Postgres database — the catalog becomes a DSM model:

Terminal window
# Credentials come from the DATABASE_URL environment variable only —
# never a CLI flag, never printed, never logged
DATABASE_URL=postgres://user:pass@host:5432/travel ctxbrew db pull --dialect postgres

Or author .contextbrew/dsm/booking.dsm.json — tables, constraints, and the custom index for flight search:

{
"kind": "dsm-file",
"schemaVersion": "0.1.0",
"enums": [],
"tables": [
{ "kind": "table", "name": "flights",
"columns": [
{ "kind": "column", "name": "id", "dataType": "UUID", "primaryKey": true },
{ "kind": "column", "name": "origin", "dataType": "CHAR(3)", "nullable": false },
{ "kind": "column", "name": "destination", "dataType": "CHAR(3)", "nullable": false },
{ "kind": "column", "name": "departure_time", "dataType": "TIMESTAMP", "nullable": false }
],
"constraints": [
{ "kind": "constraint", "name": "chk_seats_non_negative",
"type": "check", "expression": "available_seats >= 0" }
],
"indexes": [
{ "kind": "index", "name": "idx_flight_route_date",
"columns": ["origin", "destination", "departure_time"] }
]
}
],
"migrations": []
}
Terminal window
ctxbrew dsm validate .contextbrew/dsm/booking.dsm.json

(Greenfield with no database yet? ctxbrew init --from-code . reverse-engineers hypothesis DDD and DSM specs from existing TypeScript source — explicitly marked unverified until you promote them with ctxbrew init --promote <file>; proposals are never merged in silently.)

Terminal window
ctxbrew generate

ContextBrew generates deterministically from the spec — no AI judgment involved:

  • Vitest scaffolds (--target vitest) — failing-first tests for every invariant and test case; each stub ends in an explicit expect.fail(...) marker and passes only once a real implementation exists
  • Gherkin scenarios (--target gherkin) — Given/When/Then from every acceptance criterion
  • OpenAPI fragments (--target openapi) — endpoint specs derived from SCM routes and DSM tables
  • Agent prompt packs (--target prompts) — recipe-ready context bundles
  • Plus security rules (semgrep), quality rules (eslint), and CI artifacts (ci)

Scope any run: ctxbrew generate --target vitest --aggregate Booking.

Recipes are created per aggregate and bundle the spec context, the failing tests, and a work item list:

Terminal window
# One recipe per aggregate (repeat for Flight and Passenger)
ctxbrew recipe create --aggregate Booking
ctxbrew recipe list
# .contextbrew/recipes/recipe-001.{json,md}
# Export for an AI agent
ctxbrew recipe export --recipe recipe-001 --format markdown --output recipe-001.md

Paste the exported recipe into Claude Code or your preferred AI agent — or let the CLI dispatch it directly:

Terminal window
ctxbrew recipe execute recipe-001 --agent claude-code --run

The agent receives full domain context, all failing tests, and a clear work item list.

You built a complete travel booking application specification using all five ContextBrew models:

  1. DDD – Three aggregates with invariants, authored in a .domain file and validated with ctxbrew ddd validate
  2. USM – Three stories with acceptance criteria for the Traveler persona
  3. CBRL – Three formal requirements with traceability links and aspects, gated with ctxbrew cbrl check
  4. SCM – Five screens with navigation flow (or discovered from an existing app with ctxbrew scm discover)
  5. DSM – Tables pulled from a live Postgres schema with ctxbrew db pull, or authored by hand

All models are connected through bidirectional traceability, and the generated tests are failing-first scaffolds that pass only when the implementation honors the spec.