Skip to content

esdm schema (v0.2)

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

PropertyTypeRequiredDescription
kind"esdm-file"yes
schemaVersionEsdmSchemaVersionyes
boundedContextsEsdmBoundedContext[]yes
aggregatesEsdmAggregate[]yes
commandsEsdmCommand[]yes
domainEventsEsdmDomainEvent[]yes
readModelsEsdmReadModel[]yes
queriesEsdmQuery[]yes
policiesEsdmPolicy[]yes
domainServicesEsdmDomainService[]yes
processManagersEsdmProcessManager[]yes
externalSystemsEsdmExternalSystem[]yes
actorsEsdmActor[]yes
VisualisationSetupVisualisationSetupno
PropertyTypeRequiredDescription
kind"actor"yes
namestringyes
scopeEsdmScopeyes
descriptionstringno
PropertyTypeRequiredDescription
kind"aggregate"yes
namestringyes
scopeEsdmScopeyes
descriptionstringno
identifiedByEsdmIdentificationyesHow 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.)
stateRecord<string, unknown>yesJSON 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.
invariantsEsdmInvariant[]yes
PropertyTypeRequiredDescription
kind"bounded-context"yes
namestringyes
domainstringyes
descriptionstringno
PropertyTypeRequiredDescription
kind"command"yes
namestringyes
scopeEsdmScopeyes
descriptionstringno
dataRecord<string, unknown>yesJSON Schema describing the command payload. {} = no payload.
publishesstring[]yesBare event names this command may emit. At least one required by ESDM.
actorsstring[]noActor names allowed to issue this command.
constraintsEsdmInvariant[]noOrdering / mutual-exclusivity rules for event emission.
PropertyTypeRequiredDescription
boundedContextstringyes
aggregatestringnoEither aggregate or dynamicConsistencyBoundary — the target consistency boundary.
dynamicConsistencyBoundarystringno
commandstringyes

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.

PropertyTypeRequiredDescription
kind"compensation"yes
triggeringEventstringyesThe failure event this reaction listens for.
commandstringyesThe compensating command to emit.
descriptionstringno
PropertyTypeRequiredDescription
kind"domain-event"yes
namestringyes
scopeEsdmScopeyes
descriptionstringno
dataRecord<string, unknown>yesJSON Schema describing the immutable event payload. {} = no payload.
PropertyTypeRequiredDescription
kind"domain-service"yes
namestringyes
scopeEsdmScopeyes
descriptionstringno
PropertyTypeRequiredDescription
boundedContextstringyes
aggregatestringnoPresent when the source event is aggregate-owned.
eventstringyes
PropertyTypeRequiredDescription
kind"external-system"yes
namestringyes
scopeEsdmScopeyes
descriptionstringno
PropertyTypeRequiredDescription
owner"self" | "downstream" | "infrastructure" | "none" | "not-required"yes
strategystringno

Type: object

PropertyTypeRequiredDescription
kind"invariant"yes
namestringyes
rulestringyesProse statement of the constraint ("descriptive, not executable").
PropertyTypeRequiredDescription
kind"policy"yes
namestringyes
scopeobjectyesPolicies are scoped to a domain (not a specific BC).
descriptionstringno
deliveryGuarantee"at-least-once" | "at-most-once"yes
idempotencyEsdmIdempotencynoRequired when deliveryGuarantee is at-least-once.
handlesEsdmEventReference[]yesEvents this policy reacts to.
emitsEsdmCommandReference[]yesCommands this policy emits.
constraintsEsdmInvariant[]no
PropertyTypeRequiredDescription
kind"process-manager"yes
namestringyes
scopeEsdmScopeyes
descriptionstringno
handlesEsdmEventReference[]noEvents this process manager reacts to (0.2.0 — first-class sagas, D1).
emitsEsdmCommandReference[]noCommands this process manager emits (0.2.0).
compensationsEsdmCompensation[]noFirst-class compensation reactions (0.2.0, D1-approved).
PropertyTypeRequiredDescription
boundedContextstringyes
aggregatestringnoPresent when the source event is aggregate-owned.
eventstringyes
rulestringyesProse rule describing how the event is incorporated into the projection.
PropertyTypeRequiredDescription
kind"query"yes
namestringyes
scopeEsdmScopeyes
descriptionstringno
readModelstringnoThe read model this query targets.
dataRecord<string, unknown>yesJSON Schema describing the query parameters. {} = no parameters.
actorsstring[]noActor names allowed to issue this query.
PropertyTypeRequiredDescription
kind"read-model"yes
namestringyes
scopeEsdmScopeyes
descriptionstringno
projectionsEsdmProjection[]yesWhich events feed this projection and the rule for each.
paradigm"tabular" | "document" | "graph" | "stream" | "key-value" | "search-index" | "time-series" | "column" | "vector"noStorage paradigm hint.
schemaRecord<string, unknown>yesJSON Schema describing the read model's output shape.

Type: "0.1.0" | "0.2.0"

PropertyTypeRequiredDescription
domainstringyes
boundedContextstringyes
aggregatestringnoPresent on commands/events that are owned by an aggregate. Absent on free-standing events or BC-level artifacts.
dynamicConsistencyBoundarystringnoAlternative to aggregate — a dynamic consistency boundary. Mutually exclusive with aggregate.

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

PropertyTypeRequiredDescription
nodePositionsRecord<string, object>yes
zoomLevelnumberyes
viewportobjectno
updatedAtstringno

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.

↓ download
demo-01-bc-and-aggregates.esdm.json — Context Studio canvas view

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)
demo-01-bc-and-aggregates.esdm.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": []
}
↓ download
demo-02-commands-events.esdm.json — Context Studio canvas view

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)
demo-02-commands-events.esdm.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."
}
]
}
↓ download
demo-03-read-models-and-queries.esdm.json — Context Studio canvas view

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)
demo-03-read-models-and-queries.esdm.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"
}
}
]
}
↓ download
demo-04-policies-process-managers.esdm.json — Context Studio canvas view

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)
demo-04-policies-process-managers.esdm.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": []
}

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.

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