Skip to content

DDD — Samples

These are the samples for the DDD — Domain Model guide. See also Short info and the tutorial.

A flight has capacity 2 and 1 confirmed seat. A traveler requests 1 more seat.

  1. Put capacity and the confirmed-seat count inside the chosen seat-allocation consistency boundary.
  2. State the invariant: confirmed seats must remain between zero and capacity.
  3. Compare the request with the available capacity. The proposed new count is 2, so this request fits.
  4. Repeat with a request for 2 seats. The proposed count is 3, so confirmation must be refused.

The worked result is a domain decision with an allowed and a rejected case. A concurrent implementation still needs an atomic enforcement mechanism and tests. A CBRL requirement can express the promise that the last available seat is never confirmed twice.

For a concrete model file, download the travel-booking checkpoint and follow the travel-booking tutorial. The checkpoint is cumulative and may contain earlier model stages.

These four exercises are lesson briefs. Their dedicated CtxBazaar recipes and browser launch actions are planned; see Learning with models for available downloads and the meaning of each result.

Exercise Try this Expected observation
Booking capacity Add a Booking aggregate with a positive seat count and a capacity rule. Identify one valid booking and one over-capacity booking; inspect the invariant and generated test obligation.
Order total Describe an Order and the rule that its total matches its line items. Changing a line item exposes the total that must be recomputed.
Cancellation boundary Model an order that cannot be cancelled after shipment. Explain why cancelling a draft is allowed and cancelling a shipped order is rejected.
Value object and storage Represent Money as amount/currency and link the aggregate to a DSM representation. Distinguish the business value from the columns used to store it.

From the DDD model, ContextBrew generates:

Artifact Description
Unit tests (vitest) Failing-first scaffolds verifying each invariant under positive and negative conditions
Gherkin scenarios (gherkin) Behavior specifications from invariants and events
OpenAPI fragments (openapi) Endpoint stubs for aggregate CRUD operations
Prompt packs (prompts) Agent-ready context bundles for recipes