Skip to content

ddd schema (v0.2)

The models/ddd.json file is validated by the normative JSON Schema published at its canonical URL:

PropertyTypeRequiredDescription
kind"ddd-file"yes
schemaVersion"0.2.0" | "0.1.0"yes0.2.0 — additive: optional notes annotations (model-comments spec). 0.1.0 stays accepted for legacy JSON files; text parses always emit current.
aggregatesDddAggregate[]yes
VisualisationSetupVisualisationSetupno
commentsDddComment[]no
notesModelNote[]no
PropertyTypeRequiredDescription
kind"comment"yes
textstringyesComment content without the marker, trimmed.
position"leading" | "trailing"yes
PropertyTypeRequiredDescription
commentsDddComment[]no
notesModelNote[]noNode notes (see parser/model-note.ts) — omit-when-empty.
kind"aggregate"yes
namestringyes
boundedContextstringnoOptional 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.
propertiesDddProperty[]yes
entitiesDddEntity[]noNon-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.
repositoriesDddRepository[]noRepositories 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.
valueObjectsDddValueObject[]yes
invariantsDddInvariant[]yes
domainEventsDddDomainEvent[]yes
secondaryObjectsDddSecondaryObject[]noSecondary DDD objects — Actor / Command / Query / ReadModel / Policy.
servicesDddDomainService[]noDomain services declared within (or alongside) this aggregate.

Type: object

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

PropertyTypeRequiredDescription
commentsDddComment[]no
kind"domain-event"yes
namestringyes
propertiesDddProperty[]yes

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.

PropertyTypeRequiredDescription
commentsDddComment[]no
kind"domain-service"yes
namestringyes
inputTypesDddType[]noDomain types the service operates on (its inputs).
returnTypeDddTypenoWhat the service returns.
expressionstringnoOptional prose/formula sketch of the service's logic.

A non-root entity inside an aggregate’s consistency boundary.

PropertyTypeRequiredDescription
commentsDddComment[]no
kind"entity"yes
namestringyes
propertiesDddProperty[]yes
PropertyTypeRequiredDescription
commentsDddComment[]no
kind"invariant"yes
namestringyes
expressionstringyes

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.

PropertyTypeRequiredDescription
kind"method-parameter"yes
namestringyes
typeDddTypeyes
PropertyTypeRequiredDescription
commentsDddComment[]no
kind"property"yes
namestringyes
typeDddTypeyes
annotationsDddAnnotation[]yes

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.

PropertyTypeRequiredDescription
commentsDddComment[]no
kind"repository"yes
namestringyes
aggregateNamestringnoThe aggregate this repository persists. Inferred from the enclosing aggregate if omitted.
methodsDddRepositoryMethod[]yes

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.

PropertyTypeRequiredDescription
kind"repository-method"yes
namestringyes
parametersDddMethodParameter[]yes
returnTypeDddTypeyes

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"

A secondary DDD object (Actor / Command / Query / ReadModel / Policy).

PropertyTypeRequiredDescription
commentsDddComment[]no
kindDddSecondaryKindyes
namestringyes
propertiesDddProperty[]yes

Type: object

PropertyTypeRequiredDescription
commentsDddComment[]no
kind"value-object"yes
namestringyes
propertiesDddProperty[]yes
PropertyTypeRequiredDescription
kind"model-note"yes
idstringyesStable id ("note-" + 12 hex chars); survives JSON round-trips.
audienceModelNoteAudienceyesWho the note is for. Drives delivery: only "agent" reaches agent payloads.
textstringyesMarkdown body.
authorstringno
createdAtstringnoISO 8601 timestamps.
updatedAtstringno
resolvedbooleannoLifecycle flag — resolved ≠ deleted.
fieldstringnoOptional sub-node scope: a member/property name of the anchored node.

Type: "user" | "agent"

INTERNAL: Context Studio canvas state only; never emitted to coding agents.

PropertyTypeRequiredDescription
nodePositionsRecord<string, object>yes
zoomLevelnumberyes
viewportobjectno
updatedAtstringno

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.

↓ download

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.

demo-01-todo-aggregate.json — Context Studio canvas view

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)
demo-01-todo-aggregate.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": []
}
]
}
↓ download

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.

demo-02-booking-aggregate.json — Context Studio canvas view

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)
demo-02-booking-aggregate.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": []
}
]
}
↓ download

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.

demo-03-order-aggregate.json — Context Studio canvas view

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)
demo-03-order-aggregate.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": []
}
]
}
↓ download

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.

demo-04-two-aggregates.json — Context Studio canvas view

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)
demo-04-two-aggregates.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": []
}
]
}

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.

paste into AGENTS.md / CLAUDE.md
- **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.