esdm schema (v0.2)
The models/esdm.json file is validated by the normative JSON Schema published at its canonical URL:
- $id: https://contextbrew.dev/schemas/esdm/v0.2/schema.json
- Format version:
0.2.0 - Schema dialect: draft-07
- Validate with:
ctx schema esdmor any JSON Schema validator (ajv, VS Code, …)
Root object: EsdmFile
Section titled “Root object: EsdmFile”| Property | Type | Required | Description |
|---|---|---|---|
kind | "esdm-file" | yes | |
schemaVersion | EsdmSchemaVersion | yes | |
boundedContexts | EsdmBoundedContext[] | yes | |
aggregates | EsdmAggregate[] | yes | |
commands | EsdmCommand[] | yes | |
domainEvents | EsdmDomainEvent[] | yes | |
readModels | EsdmReadModel[] | yes | |
queries | EsdmQuery[] | yes | |
policies | EsdmPolicy[] | yes | |
domainServices | EsdmDomainService[] | yes | |
processManagers | EsdmProcessManager[] | yes | |
externalSystems | EsdmExternalSystem[] | yes | |
actors | EsdmActor[] | yes | |
VisualisationSetup | VisualisationSetup | no |
Definitions
Section titled “Definitions”EsdmActor
Section titled “EsdmActor”| Property | Type | Required | Description |
|---|---|---|---|
kind | "actor" | yes | |
name | string | yes | |
scope | EsdmScope | yes | |
description | string | no |
EsdmAggregate
Section titled “EsdmAggregate”| Property | Type | Required | Description |
|---|---|---|---|
kind | "aggregate" | yes | |
name | string | yes | |
scope | EsdmScope | yes | |
description | string | no | |
identifiedBy | EsdmIdentification | yes | How the aggregate instance is identified. - state: ID lives in a state field - static: fixed ID (singleton) - generated: ID generated by a strategy (uuid, ulid, etc.) |
state | Record<string, unknown> | yes | JSON Schema describing the aggregate's state shape. Kept as an opaque record — ESDM declares state as a JSON Schema object and does not prescribe the internal structure. |
invariants | EsdmInvariant[] | yes |
EsdmBoundedContext
Section titled “EsdmBoundedContext”| Property | Type | Required | Description |
|---|---|---|---|
kind | "bounded-context" | yes | |
name | string | yes | |
domain | string | yes | |
description | string | no |
EsdmCommand
Section titled “EsdmCommand”| Property | Type | Required | Description |
|---|---|---|---|
kind | "command" | yes | |
name | string | yes | |
scope | EsdmScope | yes | |
description | string | no | |
data | Record<string, unknown> | yes | JSON Schema describing the command payload. {} = no payload. |
publishes | | yes | Bare event names this command may emit. At least one required by ESDM. |
actors | | no | Actor names allowed to issue this command. |
constraints | EsdmInvariant[] | no | Ordering / mutual-exclusivity rules for event emission. |
EsdmCommandReference
Section titled “EsdmCommandReference”| Property | Type | Required | Description |
|---|---|---|---|
boundedContext | string | yes | |
aggregate | string | no | Either aggregate or dynamicConsistencyBoundary — the target consistency boundary. |
dynamicConsistencyBoundary | string | no | |
command | string | yes |
EsdmCompensation
Section titled “EsdmCompensation”A first-class compensation reaction (0.2.0): on the failure event, emit the compensating command. The auto-compensation generator (generators/esdm-compensation.ts) PROPOSES these; authoring them into the model makes the saga’s compensation path explicit and lintable.
| Property | Type | Required | Description |
|---|---|---|---|
kind | "compensation" | yes | |
triggeringEvent | string | yes | The failure event this reaction listens for. |
command | string | yes | The compensating command to emit. |
description | string | no |
EsdmDomainEvent
Section titled “EsdmDomainEvent”| Property | Type | Required | Description |
|---|---|---|---|
kind | "domain-event" | yes | |
name | string | yes | |
scope | EsdmScope | yes | |
description | string | no | |
data | Record<string, unknown> | yes | JSON Schema describing the immutable event payload. {} = no payload. |
EsdmDomainService
Section titled “EsdmDomainService”| Property | Type | Required | Description |
|---|---|---|---|
kind | "domain-service" | yes | |
name | string | yes | |
scope | EsdmScope | yes | |
description | string | no |
EsdmEventReference
Section titled “EsdmEventReference”| Property | Type | Required | Description |
|---|---|---|---|
boundedContext | string | yes | |
aggregate | string | no | Present when the source event is aggregate-owned. |
event | string | yes |
EsdmExternalSystem
Section titled “EsdmExternalSystem”| Property | Type | Required | Description |
|---|---|---|---|
kind | "external-system" | yes | |
name | string | yes | |
scope | EsdmScope | yes | |
description | string | no |
EsdmIdempotency
Section titled “EsdmIdempotency”| Property | Type | Required | Description |
|---|---|---|---|
owner | "self" | "downstream" | "infrastructure" | "none" | "not-required" | yes | |
strategy | string | no |
EsdmIdentification
Section titled “EsdmIdentification”Type: object
EsdmInvariant
Section titled “EsdmInvariant”| Property | Type | Required | Description |
|---|---|---|---|
kind | "invariant" | yes | |
name | string | yes | |
rule | string | yes | Prose statement of the constraint ("descriptive, not executable"). |
EsdmPolicy
Section titled “EsdmPolicy”| Property | Type | Required | Description |
|---|---|---|---|
kind | "policy" | yes | |
name | string | yes | |
scope | object | yes | Policies are scoped to a domain (not a specific BC). |
description | string | no | |
deliveryGuarantee | "at-least-once" | "at-most-once" | yes | |
idempotency | EsdmIdempotency | no | Required when deliveryGuarantee is at-least-once. |
handles | EsdmEventReference[] | yes | Events this policy reacts to. |
emits | EsdmCommandReference[] | yes | Commands this policy emits. |
constraints | EsdmInvariant[] | no |
EsdmProcessManager
Section titled “EsdmProcessManager”| Property | Type | Required | Description |
|---|---|---|---|
kind | "process-manager" | yes | |
name | string | yes | |
scope | EsdmScope | yes | |
description | string | no | |
handles | EsdmEventReference[] | no | Events this process manager reacts to (0.2.0 — first-class sagas, D1). |
emits | EsdmCommandReference[] | no | Commands this process manager emits (0.2.0). |
compensations | EsdmCompensation[] | no | First-class compensation reactions (0.2.0, D1-approved). |
EsdmProjection
Section titled “EsdmProjection”| Property | Type | Required | Description |
|---|---|---|---|
boundedContext | string | yes | |
aggregate | string | no | Present when the source event is aggregate-owned. |
event | string | yes | |
rule | string | yes | Prose rule describing how the event is incorporated into the projection. |
EsdmQuery
Section titled “EsdmQuery”| Property | Type | Required | Description |
|---|---|---|---|
kind | "query" | yes | |
name | string | yes | |
scope | EsdmScope | yes | |
description | string | no | |
readModel | string | no | The read model this query targets. |
data | Record<string, unknown> | yes | JSON Schema describing the query parameters. {} = no parameters. |
actors | | no | Actor names allowed to issue this query. |
EsdmReadModel
Section titled “EsdmReadModel”| Property | Type | Required | Description |
|---|---|---|---|
kind | "read-model" | yes | |
name | string | yes | |
scope | EsdmScope | yes | |
description | string | no | |
projections | EsdmProjection[] | yes | Which events feed this projection and the rule for each. |
paradigm | "tabular" | "document" | "graph" | "stream" | "key-value" | "search-index" | "time-series" | "column" | "vector" | no | Storage paradigm hint. |
schema | Record<string, unknown> | yes | JSON Schema describing the read model's output shape. |
EsdmSchemaVersion
Section titled “EsdmSchemaVersion”Type: "0.1.0" | "0.2.0"
EsdmScope
Section titled “EsdmScope”| Property | Type | Required | Description |
|---|---|---|---|
domain | string | yes | |
boundedContext | string | yes | |
aggregate | string | no | Present on commands/events that are owned by an aggregate. Absent on free-standing events or BC-level artifacts. |
dynamicConsistencyBoundary | string | no | Alternative to aggregate — a dynamic consistency boundary. Mutually exclusive with aggregate. |
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/esdm.json files committed under samples/esdm/. Each demo shows three views — pick the one you want: Canvas (rendered through the same SvelteFlow component the IDE uses), Mermaid (a static-flowchart fallback), or Raw JSON. All assets are locally served; no GitHub redirect.
Open the raw JSON in a new tab(demo-01-bc-and-aggregates.esdm.json). The full source is also expanded in the <details> below this preview.
Demo 1 — Minimal ESDM file: two bounded contexts, one aggregate with invariants, identification (state/static/generated). Exercises bounded-context, aggregate, scope, identification, and invariant nodes.
demo-01-bc-and-aggregates.esdm.json — Demo 1 — Minimal ESDM file: two bounded contexts, one aggregate with invariants, identification (state/static/generated). Exercises bounded-context, aggregate, scope, identification, and invariant nodes. (expand for full JSON)
{ "kind": "esdm-file", "schemaVersion": "0.1.0", "boundedContexts": [ { "kind": "bounded-context", "name": "library", "domain": "books", "description": "Library catalog and circulation." } ], "aggregates": [ { "kind": "aggregate", "name": "Book", "scope": { "domain": "books", "boundedContext": "library" }, "description": "A title with a counter of available copies.", "identifiedBy": { "source": "generated", "generator": "uuid" }, "state": { "type": "object", "properties": { "title": { "type": "string" }, "availableCopies": { "type": "integer" } } }, "invariants": [ { "kind": "invariant", "name": "available-copies-non-negative", "rule": "The number of available copies must not be negative." } ] }, { "kind": "aggregate", "name": "Library", "scope": { "domain": "books", "boundedContext": "library" }, "description": "The singleton library.", "identifiedBy": { "source": "static", "value": "singleton" }, "state": { "type": "object", "properties": {} }, "invariants": [] }, { "kind": "aggregate", "name": "Patron", "scope": { "domain": "books", "boundedContext": "library" }, "description": "A library patron.", "identifiedBy": { "source": "state", "field": "email" }, "state": { "type": "object", "properties": { "email": { "type": "string", "format": "email" }, "name": { "type": "string" } } }, "invariants": [] } ], "commands": [], "domainEvents": [], "readModels": [], "queries": [], "policies": [], "domainServices": [], "processManagers": [], "externalSystems": [], "actors": []}Open the raw JSON in a new tab(demo-02-commands-events.esdm.json). The full source is also expanded in the <details> below this preview.
Demo 2 — ESDM with commands + domain events: aggregate-owned commands that publish events, with JSON-Schema data shapes. Exercises command, domain-event, scope (with aggregate), actors, and data shape nodes.
demo-02-commands-events.esdm.json — Demo 2 — ESDM with commands + domain events: aggregate-owned commands that publish events, with JSON-Schema data shapes. Exercises command, domain-event, scope (with aggregate), actors, and data shape nodes. (expand for full JSON)
{ "kind": "esdm-file", "schemaVersion": "0.1.0", "boundedContexts": [ { "kind": "bounded-context", "name": "orders", "domain": "commerce", "description": "Order placement and fulfilment." } ], "aggregates": [ { "kind": "aggregate", "name": "Order", "scope": { "domain": "commerce", "boundedContext": "orders" }, "description": "An order placed by a customer.", "identifiedBy": { "source": "generated", "generator": "ulid" }, "state": { "type": "object", "properties": { "customerId": { "type": "string" }, "status": { "type": "string", "enum": ["pending", "confirmed", "shipped", "cancelled"] } } }, "invariants": [] } ], "commands": [ { "kind": "command", "name": "PlaceOrder", "scope": { "domain": "commerce", "boundedContext": "orders", "aggregate": "Order" }, "description": "Customer places a new order.", "data": { "type": "object", "properties": { "customerId": { "type": "string" }, "items": { "type": "array", "items": { "type": "object", "properties": { "sku": { "type": "string" }, "qty": { "type": "integer", "minimum": 1 } } } } } }, "publishes": ["OrderPlaced"], "actors": ["Customer"] }, { "kind": "command", "name": "ConfirmOrder", "scope": { "domain": "commerce", "boundedContext": "orders", "aggregate": "Order" }, "description": "Marks an order as confirmed (after payment).", "data": { "type": "object", "properties": { "orderId": { "type": "string" } } }, "publishes": ["OrderConfirmed"], "actors": ["PaymentService"] }, { "kind": "command", "name": "CancelOrder", "scope": { "domain": "commerce", "boundedContext": "orders", "aggregate": "Order" }, "description": "Customer-initiated cancellation.", "data": { "type": "object", "properties": { "orderId": { "type": "string" }, "reason": { "type": "string" } } }, "publishes": ["OrderCancelled"], "constraints": [ { "kind": "invariant", "name": "cancel-only-pending-or-confirmed", "rule": "Cancellation is only valid for orders in `pending` or `confirmed` status." } ] } ], "domainEvents": [ { "kind": "domain-event", "name": "OrderPlaced", "scope": { "domain": "commerce", "boundedContext": "orders", "aggregate": "Order" }, "description": "An order was placed.", "data": { "type": "object", "properties": { "orderId": { "type": "string" }, "customerId": { "type": "string" }, "placedAt": { "type": "string", "format": "date-time" } } } }, { "kind": "domain-event", "name": "OrderConfirmed", "scope": { "domain": "commerce", "boundedContext": "orders", "aggregate": "Order" }, "data": { "type": "object", "properties": { "orderId": { "type": "string" }, "confirmedAt": { "type": "string", "format": "date-time" } } } }, { "kind": "domain-event", "name": "OrderCancelled", "scope": { "domain": "commerce", "boundedContext": "orders", "aggregate": "Order" }, "data": { "type": "object", "properties": { "orderId": { "type": "string" }, "reason": { "type": "string" }, "cancelledAt": { "type": "string", "format": "date-time" } } } } ], "readModels": [], "queries": [], "policies": [], "domainServices": [], "processManagers": [], "externalSystems": [], "actors": [ { "kind": "actor", "name": "Customer", "scope": { "domain": "commerce", "boundedContext": "orders" }, "description": "Human placing orders." }, { "kind": "actor", "name": "PaymentService", "scope": { "domain": "commerce", "boundedContext": "orders" }, "description": "External payment processor." } ]}Open the raw JSON in a new tab(demo-03-read-models-and-queries.esdm.json). The full source is also expanded in the <details> below this preview.
Demo 3 — ESDM with read models + queries + projections. Exercises read-model (with paradigm, schema, projections), query, projection, and event-reference nodes.
demo-03-read-models-and-queries.esdm.json — Demo 3 — ESDM with read models + queries + projections. Exercises read-model (with paradigm, schema, projections), query, projection, and event-reference nodes. (expand for full JSON)
{ "kind": "esdm-file", "schemaVersion": "0.1.0", "boundedContexts": [ { "kind": "bounded-context", "name": "orders", "domain": "commerce", "description": "Order placement." }, { "kind": "bounded-context", "name": "fulfillment", "domain": "commerce", "description": "Shipping and fulfilment." } ], "aggregates": [ { "kind": "aggregate", "name": "Order", "scope": { "domain": "commerce", "boundedContext": "orders" }, "identifiedBy": { "source": "generated", "generator": "ulid" }, "state": { "type": "object", "properties": {} }, "invariants": [] }, { "kind": "aggregate", "name": "Shipment", "scope": { "domain": "commerce", "boundedContext": "fulfillment" }, "identifiedBy": { "source": "generated", "generator": "ulid" }, "state": { "type": "object", "properties": {} }, "invariants": [] } ], "commands": [], "domainEvents": [ { "kind": "domain-event", "name": "OrderConfirmed", "scope": { "domain": "commerce", "boundedContext": "orders", "aggregate": "Order" }, "data": { "type": "object", "properties": {} } }, { "kind": "domain-event", "name": "ShipmentDispatched", "scope": { "domain": "commerce", "boundedContext": "fulfillment", "aggregate": "Shipment" }, "data": { "type": "object", "properties": {} } } ], "readModels": [ { "kind": "read-model", "name": "OrderFulfilmentTimeline", "scope": { "domain": "commerce", "boundedContext": "orders" }, "description": "Flattened view: every order with its shipping milestones.", "projections": [ { "boundedContext": "orders", "aggregate": "Order", "event": "OrderConfirmed", "rule": "Insert a row keyed by orderId; record confirmedAt." }, { "boundedContext": "fulfillment", "aggregate": "Shipment", "event": "ShipmentDispatched", "rule": "Update the matching orderId row with dispatchedAt; ignore if no row yet." } ], "paradigm": "tabular", "schema": { "type": "object", "properties": { "orderId": { "type": "string" }, "confirmedAt": { "type": "string", "format": "date-time" }, "dispatchedAt": { "type": "string", "format": "date-time" } } } } ], "queries": [ { "kind": "query", "name": "GetTimeline", "scope": { "domain": "commerce", "boundedContext": "orders" }, "description": "Returns the timeline for a single order.", "readModel": "OrderFulfilmentTimeline", "data": { "type": "object", "properties": { "orderId": { "type": "string" } }, "required": ["orderId"] }, "actors": ["Customer", "Ops"] }, { "kind": "query", "name": "ListUnshippedOrders", "scope": { "domain": "commerce", "boundedContext": "orders" }, "description": "Lists orders confirmed but not yet dispatched.", "readModel": "OrderFulfilmentTimeline", "data": { "type": "object", "properties": { "limit": { "type": "integer" } } }, "actors": ["Ops"] } ], "policies": [], "domainServices": [], "processManagers": [], "externalSystems": [], "actors": [ { "kind": "actor", "name": "Customer", "scope": { "domain": "commerce", "boundedContext": "orders" } }, { "kind": "actor", "name": "Ops", "scope": { "domain": "commerce", "boundedContext": "fulfillment" } } ]}Open the raw JSON in a new tab(demo-04-policies-process-managers.esdm.json). The full source is also expanded in the <details> below this preview.
Demo 4 — ESDM with policies + process managers + domain services + external systems. Exercises policy (with deliveryGuarantee + idempotency), process-manager, domain-service, external-system nodes.
demo-04-policies-process-managers.esdm.json — Demo 4 — ESDM with policies + process managers + domain services + external systems. Exercises policy (with deliveryGuarantee + idempotency), process-manager, domain-service, external-system nodes. (expand for full JSON)
{ "kind": "esdm-file", "schemaVersion": "0.1.0", "boundedContexts": [ { "kind": "bounded-context", "name": "orders", "domain": "commerce" }, { "kind": "bounded-context", "name": "shipping", "domain": "commerce" }, { "kind": "bounded-context", "name": "billing", "domain": "commerce" } ], "aggregates": [ { "kind": "aggregate", "name": "Order", "scope": { "domain": "commerce", "boundedContext": "orders" }, "identifiedBy": { "source": "generated", "generator": "ulid" }, "state": { "type": "object" }, "invariants": [] } ], "commands": [], "domainEvents": [], "readModels": [], "queries": [], "policies": [ { "kind": "policy", "name": "OnOrderConfirmedRequestShipment", "scope": { "domain": "commerce" }, "description": "When an order is confirmed, request shipment in the shipping BC.", "deliveryGuarantee": "at-least-once", "idempotency": { "owner": "infrastructure", "strategy": "kafka-exactly-once-via-producer-id" }, "handles": [ { "boundedContext": "orders", "aggregate": "Order", "event": "OrderConfirmed" } ], "emits": [ { "boundedContext": "shipping", "aggregate": "Shipment", "command": "RequestShipment" } ] }, { "kind": "policy", "name": "OnOrderPlacedChargeCard", "scope": { "domain": "commerce" }, "description": "Trigger card authorization on order placement (best-effort; failures retry).", "deliveryGuarantee": "at-most-once", "handles": [ { "boundedContext": "orders", "aggregate": "Order", "event": "OrderPlaced" } ], "emits": [ { "boundedContext": "billing", "aggregate": "Payment", "command": "AuthorizeCard" } ] } ], "domainServices": [ { "kind": "domain-service", "name": "PricingService", "scope": { "domain": "commerce", "boundedContext": "orders" }, "description": "Stateless fare/discount computation." } ], "processManagers": [ { "kind": "process-manager", "name": "OrderFulfilmentSaga", "scope": { "domain": "commerce", "boundedContext": "orders" }, "description": "Saga-style orchestrator: confirm → reserve inventory → charge → ship → notify. Tracks per-order state with compensating actions on failure." } ], "externalSystems": [ { "kind": "external-system", "name": "Stripe", "scope": { "domain": "commerce", "boundedContext": "billing" }, "description": "External payment processor." }, { "kind": "external-system", "name": "FedEx", "scope": { "domain": "commerce", "boundedContext": "shipping" }, "description": "External shipping carrier API." } ], "actors": []}What this model produces
Section titled “What this model produces”The esdm 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.
- **ESDM v0.2.0** — `models/esdm.json`. Produces: Event-sourcing test suites (command → event assertions) via ctxbrew generate-esdm-tests. Oracle: generated command/event tests must pass — a command that emits the wrong events (or none) fails closed. Downstream: `ctxbrew semantics esdm` · `ctxbrew://semantics/esdm/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 esdm --schema-version 0.2.0 - MCP —
ctxbrew://semantics/esdm/v0.2.0 - HTTP —
https://contextbrew.dev/schemas/esdm/v0.2/semantics.json
See the schemas overview for the versioning policy and how these files are generated and kept in sync.








