ddd schema (v0.2)
The models/ddd.json file is validated by the normative JSON Schema published at its canonical URL:
- $id: https://contextbrew.dev/schemas/ddd/v0.2/schema.json
- Format version:
0.2.0 - Schema dialect: draft-07
- Validate with:
ctx schema dddor any JSON Schema validator (ajv, VS Code, …)
Root object: DddFile
Section titled “Root object: DddFile”| Property | Type | Required | Description |
|---|---|---|---|
kind | "ddd-file" | yes | |
schemaVersion | "0.2.0" | "0.1.0" | yes | 0.2.0 — additive: optional notes annotations (model-comments spec). 0.1.0 stays accepted for legacy JSON files; text parses always emit current. |
aggregates | DddAggregate[] | yes | |
VisualisationSetup | VisualisationSetup | no | |
comments | DddComment[] | no | |
notes | ModelNote[] | no |
Definitions
Section titled “Definitions”CommentTrivia
Section titled “CommentTrivia”| Property | Type | Required | Description |
|---|---|---|---|
kind | "comment" | yes | |
text | string | yes | Comment content without the marker, trimmed. |
position | "leading" | "trailing" | yes |
DddAggregate
Section titled “DddAggregate”| Property | Type | Required | Description |
|---|---|---|---|
comments | DddComment[] | no | |
notes | ModelNote[] | no | Node notes (see parser/model-note.ts) — omit-when-empty. |
kind | "aggregate" | yes | |
name | string | yes | |
boundedContext | string | no | Optional bounded-context slug. When set, foreign references FROM this aggregate carry the BC as their homeInstance qualifier (e.g. ddd:AGGR-Order@orders), disambiguating same-named foreign objects across multiple BCs. Additive + optional: legacy data and projects that don't model BCs explicitly leave this undefined, in which case the foreign label renders without an @<instance> slot (current behaviour). The field is not yet populated by the DDD parser — it lands via the bounded-context ingest or a future @BC <slug> DSL annotation; until then it's set by importers (event-storming, context-map migrate) and the IDE bulk-edit. |
properties | DddProperty[] | yes | |
entities | DddEntity[] | no | Non-root entities contained within the aggregate's consistency boundary. Optional for backward compatibility: legacy 0.1.0 models (and any construction site that doesn't model internal entities) omit this field and the migrator normalizes it to [] at parse time. The aggregate *root* is the DddAggregate itself; its own attributes live in properties. |
repositories | DddRepository[] | no | Repositories that persist this aggregate. Optional for backward compatibility — legacy models omit it and the migrator normalizes to [] at parse time. One repository per aggregate root is the DDD canon; we allow multiple for flexibility (e.g. read-optimized vs write repos), but the validator enforces name uniqueness within the aggregate. |
valueObjects | DddValueObject[] | yes | |
invariants | DddInvariant[] | yes | |
domainEvents | DddDomainEvent[] | yes | |
secondaryObjects | DddSecondaryObject[] | no | Secondary DDD objects — Actor / Command / Query / ReadModel / Policy. |
services | DddDomainService[] | no | Domain services declared within (or alongside) this aggregate. |
DddAnnotation
Section titled “DddAnnotation”Type: object
DddComment
Section titled “DddComment”A source comment attached to the AST node it annotates (Model Text View F5). Trivia, not semantics — see ../comment-trivia.ts. comments? fields are optional and OMITTED when empty (conditional spread, like inputTypes/expression on DddDomainService) — never defaulted to [] — so comment-free sources produce byte-identical ASTs and legacy consumers see no shape change.
Type: CommentTrivia
DddDomainEvent
Section titled “DddDomainEvent”| Property | Type | Required | Description |
|---|---|---|---|
comments | DddComment[] | no | |
kind | "domain-event" | yes | |
name | string | yes | |
properties | DddProperty[] | yes |
DddDomainService
Section titled “DddDomainService”A domain service: stateless domain logic that spans (or sits outside) the aggregate’s own state — e.g. a pricing calculation or a funds transfer between two accounts.
| Property | Type | Required | Description |
|---|---|---|---|
comments | DddComment[] | no | |
kind | "domain-service" | yes | |
name | string | yes | |
inputTypes | DddType[] | no | Domain types the service operates on (its inputs). |
returnType | DddType | no | What the service returns. |
expression | string | no | Optional prose/formula sketch of the service's logic. |
DddEntity
Section titled “DddEntity”A non-root entity inside an aggregate’s consistency boundary.
| Property | Type | Required | Description |
|---|---|---|---|
comments | DddComment[] | no | |
kind | "entity" | yes | |
name | string | yes | |
properties | DddProperty[] | yes |
DddInvariant
Section titled “DddInvariant”| Property | Type | Required | Description |
|---|---|---|---|
comments | DddComment[] | no | |
kind | "invariant" | yes | |
name | string | yes | |
expression | string | yes |
DddMethodParameter
Section titled “DddMethodParameter”A named parameter on a repository method. Structurally a property with a distinct kind so the parser can distinguish method signatures from aggregate properties in mixed contexts.
| Property | Type | Required | Description |
|---|---|---|---|
kind | "method-parameter" | yes | |
name | string | yes | |
type | DddType | yes |
DddProperty
Section titled “DddProperty”| Property | Type | Required | Description |
|---|---|---|---|
comments | DddComment[] | no | |
kind | "property" | yes | |
name | string | yes | |
type | DddType | yes | |
annotations | DddAnnotation[] | yes |
DddRepository
Section titled “DddRepository”A repository: the persistence boundary for an aggregate root. Provides collection-like access (findById, save, etc.) while hiding storage details behind a domain-meaningful interface. One repository per aggregate root is the DDD canon; DddAggregate.repositories is an array for flexibility.
| Property | Type | Required | Description |
|---|---|---|---|
comments | DddComment[] | no | |
kind | "repository" | yes | |
name | string | yes | |
aggregateName | string | no | The aggregate this repository persists. Inferred from the enclosing aggregate if omitted. |
methods | DddRepositoryMethod[] | yes |
DddRepositoryMethod
Section titled “DddRepositoryMethod”A single method on a repository — typically a finder (findByCustomer) or a mutation (save, remove). Parameters and return type use the same DddType vocabulary as properties so the model is uniform.
| Property | Type | Required | Description |
|---|---|---|---|
kind | "repository-method" | yes | |
name | string | yes | |
parameters | DddMethodParameter[] | yes | |
returnType | DddType | yes |
DddSecondaryKind
Section titled “DddSecondaryKind”The supported kinds of DddSecondaryObject . Each maps 1:1 to a DSL keyword (COMMAND / ACTOR / QUERY / READ_MODEL / POLICY) and to a visual- grammar registry entry (code + glyph + family) in the surfaces layer.
Type: "command" | "actor" | "query" | "read-model" | "policy"
DddSecondaryObject
Section titled “DddSecondaryObject”A secondary DDD object (Actor / Command / Query / ReadModel / Policy).
| Property | Type | Required | Description |
|---|---|---|---|
comments | DddComment[] | no | |
kind | DddSecondaryKind | yes | |
name | string | yes | |
properties | DddProperty[] | yes |
DddType
Section titled “DddType”Type: object
DddValueObject
Section titled “DddValueObject”| Property | Type | Required | Description |
|---|---|---|---|
comments | DddComment[] | no | |
kind | "value-object" | yes | |
name | string | yes | |
properties | DddProperty[] | yes |
ModelNote
Section titled “ModelNote”| Property | Type | Required | Description |
|---|---|---|---|
kind | "model-note" | yes | |
id | string | yes | Stable id ("note-" + 12 hex chars); survives JSON round-trips. |
audience | ModelNoteAudience | yes | Who the note is for. Drives delivery: only "agent" reaches agent payloads. |
text | string | yes | Markdown body. |
author | string | no | |
createdAt | string | no | ISO 8601 timestamps. |
updatedAt | string | no | |
resolved | boolean | no | Lifecycle flag — resolved ≠ deleted. |
field | string | no | Optional sub-node scope: a member/property name of the anchored node. |
ModelNoteAudience
Section titled “ModelNoteAudience”Type: "user" | "agent"
VisualisationSetup
Section titled “VisualisationSetup”INTERNAL: Context Studio canvas state only; never emitted to coding agents.
| Property | Type | Required | Description |
|---|---|---|---|
nodePositions | Record<string, object> | yes | |
zoomLevel | number | yes | |
viewport | object | no | |
updatedAt | string | no |
Sample documents
Section titled “Sample documents”Representative models/ddd.json files committed under samples/ddd/. Each demo shows four views — pick the one you want: Canvas (rendered through the same SvelteFlow component the IDE uses), Mermaid (a static-flowchart fallback), Interactive (the live artifact ctx diagram <file> compiles — pan, zoom, click-to-trace, guided stories, exports), or Raw JSON. All assets are locally served; no GitHub redirect.
Live artifact compiled by ctx diagram — pan & zoom,/ to find a node, click one to trace reach, T theme, P guided story, ? for all shortcuts.
Open the raw JSON in a new tab(demo-01-todo-aggregate.json). The full source is also expanded in the <details> below this preview.
Demo 1 — minimal DDD file: a single aggregate (Todo) with properties, annotations, invariants, and a domain event. The smallest viable DDD shape.
demo-01-todo-aggregate.json — Demo 1 — minimal DDD file: a single aggregate (Todo) with properties, annotations, invariants, and a domain event. The smallest viable DDD shape. (expand for full JSON)
{ "kind": "ddd-file", "schemaVersion": "0.1.0", "aggregates": [ { "kind": "aggregate", "name": "Todo", "properties": [ { "kind": "property", "name": "id", "type": { "kind": "primitive", "name": "UUID" }, "annotations": [ { "kind": "pk" }, { "kind": "required" } ] }, { "kind": "property", "name": "title", "type": { "kind": "primitive", "name": "string" }, "annotations": [ { "kind": "required" }, { "kind": "min", "value": 1 } ] }, { "kind": "property", "name": "completed", "type": { "kind": "primitive", "name": "boolean" }, "annotations": [ { "kind": "default", "value": "false" } ] } ], "entities": [], "repositories": [], "valueObjects": [], "invariants": [ { "kind": "invariant", "name": "title-not-blank", "expression": "A todo's title must not be blank." } ], "domainEvents": [], "services": [], "secondaryObjects": [] } ]}Live artifact compiled by ctx diagram — pan & zoom,/ to find a node, click one to trace reach, T theme, P guided story, ? for all shortcuts.
Open the raw JSON in a new tab(demo-02-booking-aggregate.json). The full source is also expanded in the <details> below this preview.
Demo 2 — DDD aggregate with multiple properties, two invariants, and a list of domain events. The canonical 'small but realistic' example.
demo-02-booking-aggregate.json — Demo 2 — DDD aggregate with multiple properties, two invariants, and a list of domain events. The canonical ‘small but realistic’ example. (expand for full JSON)
{ "kind": "ddd-file", "schemaVersion": "0.1.0", "aggregates": [ { "kind": "aggregate", "name": "Booking", "properties": [ { "kind": "property", "name": "id", "type": { "kind": "primitive", "name": "UUID" }, "annotations": [ { "kind": "pk" } ] }, { "kind": "property", "name": "customerId", "type": { "kind": "primitive", "name": "UUID" }, "annotations": [ { "kind": "required" } ] }, { "kind": "property", "name": "status", "type": { "kind": "primitive", "name": "string" }, "annotations": [ { "kind": "default", "value": "pending" } ] }, { "kind": "property", "name": "totalAmount", "type": { "kind": "primitive", "name": "number" }, "annotations": [] }, { "kind": "property", "name": "createdAt", "type": { "kind": "primitive", "name": "Date" }, "annotations": [] } ], "entities": [], "repositories": [], "valueObjects": [], "invariants": [ { "kind": "invariant", "name": "confirmed-has-payment", "expression": "Confirmed bookings must reference a settled payment." }, { "kind": "invariant", "name": "amount-non-negative", "expression": "totalAmount must be ≥ 0." } ], "domainEvents": [ { "kind": "domain-event", "name": "BookingCreated", "properties": [] }, { "kind": "domain-event", "name": "BookingConfirmed", "properties": [] }, { "kind": "domain-event", "name": "BookingCancelled", "properties": [] } ], "services": [], "secondaryObjects": [] } ]}Live artifact compiled by ctx diagram — pan & zoom,/ to find a node, click one to trace reach, T theme, P guided story, ? for all shortcuts.
Open the raw JSON in a new tab(demo-03-order-aggregate.json). The full source is also expanded in the <details> below this preview.
Demo 3 — DDD with value objects (Customer, LineItem, Money), enum properties, multiple invariants, and a repository. Exercises every property-kind primitive.
demo-03-order-aggregate.json — Demo 3 — DDD with value objects (Customer, LineItem, Money), enum properties, multiple invariants, and a repository. Exercises every property-kind primitive. (expand for full JSON)
{ "kind": "ddd-file", "schemaVersion": "0.1.0", "aggregates": [ { "kind": "aggregate", "name": "Order", "properties": [ { "kind": "property", "name": "id", "type": { "kind": "primitive", "name": "UUID" }, "annotations": [ { "kind": "pk" } ] }, { "kind": "property", "name": "customer", "type": { "kind": "reference", "name": "Customer" }, "annotations": [] }, { "kind": "property", "name": "lineItems", "type": { "kind": "array", "elementType": { "kind": "reference", "name": "LineItem" } }, "annotations": [] }, { "kind": "property", "name": "total", "type": { "kind": "reference", "name": "Money" }, "annotations": [] }, { "kind": "property", "name": "status", "type": { "kind": "primitive", "name": "string" }, "annotations": [ { "kind": "default", "value": "draft" } ] }, { "kind": "property", "name": "submittedAt", "type": { "kind": "primitive", "name": "Date" }, "annotations": [] } ], "entities": [], "repositories": [ { "kind": "repository", "name": "OrderRepository", "methods": [], "aggregateName": "Order" } ], "valueObjects": [], "invariants": [ { "kind": "invariant", "name": "submitted-has-at-least-one-line", "expression": "An order in 'submitted' status must have at least one line item." }, { "kind": "invariant", "name": "cancelled-after-paid-needs-refund", "expression": "Cancelling a paid order must schedule a refund." }, { "kind": "invariant", "name": "total-positive", "expression": "Order total must be > 0." } ], "domainEvents": [ { "kind": "domain-event", "name": "OrderDrafted", "properties": [] }, { "kind": "domain-event", "name": "OrderSubmitted", "properties": [] }, { "kind": "domain-event", "name": "OrderPaid", "properties": [] }, { "kind": "domain-event", "name": "OrderShipped", "properties": [] }, { "kind": "domain-event", "name": "OrderCancelled", "properties": [] } ], "services": [], "secondaryObjects": [] } ]}Live artifact compiled by ctx diagram — pan & zoom,/ to find a node, click one to trace reach, T theme, P guided story, ? for all shortcuts.
Open the raw JSON in a new tab(demo-04-two-aggregates.json). The full source is also expanded in the <details> below this preview.
Demo 4 — DDD with two aggregates (Customer + Payment) cross-referenced via foreign-style relationships. Exercises multi-aggregate composition.
demo-04-two-aggregates.json — Demo 4 — DDD with two aggregates (Customer + Payment) cross-referenced via foreign-style relationships. Exercises multi-aggregate composition. (expand for full JSON)
{ "kind": "ddd-file", "schemaVersion": "0.1.0", "aggregates": [ { "kind": "aggregate", "name": "Customer", "properties": [ { "kind": "property", "name": "id", "type": { "kind": "primitive", "name": "UUID" }, "annotations": [ { "kind": "pk" } ] }, { "kind": "property", "name": "email", "type": { "kind": "primitive", "name": "string" }, "annotations": [ { "kind": "required" }, { "kind": "unique" } ] }, { "kind": "property", "name": "loyaltyTier", "type": { "kind": "primitive", "name": "string" }, "annotations": [ { "kind": "default", "value": "bronze" } ] } ], "entities": [], "repositories": [], "valueObjects": [], "invariants": [], "domainEvents": [ { "kind": "domain-event", "name": "CustomerRegistered", "properties": [] }, { "kind": "domain-event", "name": "LoyaltyTierChanged", "properties": [] } ], "services": [], "secondaryObjects": [] }, { "kind": "aggregate", "name": "Payment", "properties": [ { "kind": "property", "name": "id", "type": { "kind": "primitive", "name": "UUID" }, "annotations": [ { "kind": "pk" } ] }, { "kind": "property", "name": "bookingId", "type": { "kind": "primitive", "name": "UUID" }, "annotations": [ { "kind": "required" } ] }, { "kind": "property", "name": "amount", "type": { "kind": "primitive", "name": "number" }, "annotations": [ { "kind": "required" } ] }, { "kind": "property", "name": "currency", "type": { "kind": "primitive", "name": "string" }, "annotations": [ { "kind": "default", "value": "USD" } ] }, { "kind": "property", "name": "status", "type": { "kind": "primitive", "name": "string" }, "annotations": [] } ], "entities": [], "repositories": [], "valueObjects": [], "invariants": [ { "kind": "invariant", "name": "amount-positive", "expression": "Payment amount must be > 0." }, { "kind": "invariant", "name": "refund-only-after-capture", "expression": "Only captured payments can be refunded." } ], "domainEvents": [ { "kind": "domain-event", "name": "PaymentAuthorized", "properties": [] }, { "kind": "domain-event", "name": "PaymentCaptured", "properties": [] }, { "kind": "domain-event", "name": "PaymentRefunded", "properties": [] } ], "services": [], "secondaryObjects": [] } ]}What this model produces
Section titled “What this model produces”The ddd model is one of the richly-curated records — every downstream surface (CLI, MCP, docs, tests) reads from one record. The pasteable snippet below is the Door 1 anchor a downstream agent should see before touching this model.
- **DDD v0.2.0** — `models/ddd.json`. Produces: Gherkin features + Vitest behavior tests + per-invariant valid/invalid/boundary tests, TypeScript types, OpenAPI, Semgrep + ESLint rule packs, CI workflow, architecture doc. Oracle: the generated per-invariant tests must fail first and end green — the playbook exit gate. Downstream: `ctxbrew semantics ddd` · `ctxbrew://semantics/ddd/v0.2.0` — read the record first.The full record (every door — anchor template, tool description hint, response annotations, behavior tripwire, and the complete produced-surface list) is served as JSON at:
- CLI —
ctxbrew semantics ddd --schema-version 0.2.0 - MCP —
ctxbrew://semantics/ddd/v0.2.0 - HTTP —
https://contextbrew.dev/schemas/ddd/v0.2/semantics.json
See the schemas overview for the versioning policy and how these files are generated and kept in sync.








