dsm schema (v0.2)
The models/dsm.json file is validated by the normative JSON Schema published at its canonical URL:
- $id: https://contextbrew.dev/schemas/dsm/v0.2/schema.json
- Format version:
0.2.0 - Schema dialect: draft-07
- Validate with:
ctx schema dsmor any JSON Schema validator (ajv, VS Code, …)
Root object: DsmFile
Section titled “Root object: DsmFile”| Property | Type | Required | Description |
|---|---|---|---|
kind | "dsm-file" | yes | |
schemaVersion | "0.2.0" | "0.1.0" | yes | Current DSM schema version. Accepts 0.1.0 (legacy) and 0.2.0 (current — additive: optional notes annotations). Parse normalizes output to 0.2.0 (read old, write current). |
tables | DsmTable[] | yes | |
enums | DsmEnum[] | yes | |
migrations | DsmMigration[] | yes | |
storageTypes | StorageType[] | no | v1 (TS-core-128): optional. When absent, inferred from tables (legacy shape — all tables default to relational_sql on a synthetic default container). When present, may be omitted entirely and the parser will infer types from data sources. |
dataContainers | DataContainer[] | no | v1: optional. The physical/logical media hosting one or more data sources. May be omitted; a synthetic default container is created. |
containerEdges | ContainerEdge[] | no | v1: optional. Typed relationships between data containers. |
dataSources | DataSource[] | no | v1: optional. Addressable instances of storage types. When absent, synthesized from the legacy tables array. |
notes | ModelNote[] | no | Node notes (see parser/model-note.ts). |
VisualisationSetup | VisualisationSetup | no |
Definitions
Section titled “Definitions”ConsistencyModel
Section titled “ConsistencyModel”Consistency model. Documentation-only in v1.
Type: string — known values: "strong", "serializable", "snapshot", "read_committed", "eventual", "causal", "read_your_writes", "crdt", "lww", "quorum", "append_only", "wom" (others allowed)
ContainerEdge
Section titled “ContainerEdge”| Property | Type | Required | Description |
|---|---|---|---|
kind | "container_edge" | yes | |
from | string | yes | |
to | string | yes | |
type | ContainerEdgeType | yes | |
via | string | no | |
protocol | string | no | Optional transport hint for the edge (e.g. "tcp", "grpc") — surfaced in the topology artifact's metadata.protocol. |
lag_target_ms | number | no | |
note | string | no | |
notes | ModelNote[] | no | Node notes (see parser/model-note.ts). |
ContainerEdgeType
Section titled “ContainerEdgeType”Container Edge type — a typed relationship between two Data Containers. v1 ships 3 types: composition, streaming, gateway. Other types (mirror, federation, cache, migration, alias, parent_child) are deferred.
Type: string — known values: "composition", "streaming", "gateway" (others allowed)
DataContainer
Section titled “DataContainer”| Property | Type | Required | Description |
|---|---|---|---|
kind | "data_container" | yes | |
id | string | yes | |
type | string | yes | |
host | string | no | |
base_url | string | no | |
brokers | | no | |
root | string | no | |
credentials_ref | string | no | |
description | string | no | |
notes | ModelNote[] | no | Node notes (see parser/model-note.ts). |
DataSource
Section titled “DataSource”| Property | Type | Required | Description |
|---|---|---|---|
kind | "data_source" | yes | |
id | string | yes | |
type | StorageType | yes | |
container | string | yes | |
schema | DataSourceSchema | no | |
access | DataSourceAccess | no | |
ownership | OwnershipModel | no | |
consistency | ConsistencyModel | no | |
description | string | no | |
traceability | DsmTraceability | no | |
notes | ModelNote[] | no | Node notes (see parser/model-note.ts). |
DataSourceAccess
Section titled “DataSourceAccess”Access pattern declaration. Optional, documentation-only in v1. Future v1.1+ may use this to influence generator choices.
| Property | Type | Required | Description |
|---|---|---|---|
patterns | ( | no | |
freshness | "realtime" | "near-realtime" | "batch" | "manual" | no |
DataSourceSchema
Section titled “DataSourceSchema”A typed schema declaration within a Data Source. The shape depends on the source’s type. For v1:
Type: RelationalSqlSchema | FilesystemSchema | Record<string, unknown>
DsmColumn
Section titled “DsmColumn”| Property | Type | Required | Description |
|---|---|---|---|
kind | "column" | yes | |
name | string | yes | |
dataType | string | yes | |
primaryKey | boolean | no | |
unique | boolean | no | |
nullable | boolean | no | |
defaultValue | string | no | |
references | DsmReference | no |
DsmConstraint
Section titled “DsmConstraint”| Property | Type | Required | Description |
|---|---|---|---|
kind | "constraint" | yes | |
name | string | yes | |
type | "check" | "unique" | "not_null" | yes | |
expression | string | no |
DsmEnum
Section titled “DsmEnum”| Property | Type | Required | Description |
|---|---|---|---|
kind | "enum" | yes | |
name | string | yes | |
values | | yes | |
default | string | no | |
notes | ModelNote[] | no | Node notes (see parser/model-note.ts). |
DsmIndex
Section titled “DsmIndex”| Property | Type | Required | Description |
|---|---|---|---|
kind | "index" | yes | |
name | string | yes | |
columns | | yes | |
unique | boolean | no |
DsmMigration
Section titled “DsmMigration”| Property | Type | Required | Description |
|---|---|---|---|
kind | "migration" | yes | |
version | string | yes | |
description | string | no | |
deltaFrom | string | no | |
changes | | yes |
DsmReference
Section titled “DsmReference”| Property | Type | Required | Description |
|---|---|---|---|
table | string | yes | |
column | string | yes |
DsmTable
Section titled “DsmTable”| Property | Type | Required | Description |
|---|---|---|---|
kind | "table" | yes | |
name | string | yes | |
id | string | no | Optional canvas-node id. The DsmFile itself only uses name as the identifier; the canvas UI (apps/web/src/lib/canvas/validate-dsm-canvas.ts and friends) injects the Svelte Flow node id here so validation results can be linked back to the visual node. Not part of the on-disk format. |
aggregate | string | no | |
description | string | no | |
columns | DsmColumn[] | yes | |
constraints | DsmConstraint[] | yes | |
indexes | DsmIndex[] | yes | |
traceability | DsmTraceability | no | |
notes | ModelNote[] | no | Node notes (see parser/model-note.ts). |
DsmTraceability
Section titled “DsmTraceability”| Property | Type | Required | Description |
|---|---|---|---|
ddd | | no | |
cbrl | | no | |
aspects | | no |
FilesystemSchema
Section titled “FilesystemSchema”| Property | Type | Required | Description |
|---|---|---|---|
kind | "filesystem" | yes | |
path | string | yes | |
format | "jsonl" | "json" | "csv" | "parquet" | "text" | "binary" | yes | |
encoding | string | no | |
append_only | boolean | no | |
keys | | no | |
mime | string | no | |
etag | string | no |
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"
OwnershipModel
Section titled “OwnershipModel”Ownership model. Documentation-only in v1.
Type: string — known values: "owned", "borrowed", "federated", "cached", "shared", "public", "user_generated", "agent_generated", "synthetic" (others allowed)
RelationalSqlSchema
Section titled “RelationalSqlSchema”| Property | Type | Required | Description |
|---|---|---|---|
kind | "relational_sql" | yes | |
table | string | yes | |
columns | array | no | |
constraints | array | no | |
indexes | array | no |
StorageType
Section titled “StorageType”Storage Type — the schema grammar + operations vocabulary for a category of data source. ADR-026: extends DSM beyond relational-only.
Type: string — known values: "relational_sql", "filesystem", "rest_api", "queue_stream", "object_store", "vector_store", "log", "kv" (others allowed)
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/dsm.json files committed under samples/dsm/. 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-todos-table.json). The full source is also expanded in the <details> below this preview.
Demo 1 — minimal DSM file: a single table (todos) with columns, a CHECK constraint, and an auto-default. The smallest viable DSM shape.
demo-01-todos-table.json — Demo 1 — minimal DSM file: a single table (todos) with columns, a CHECK constraint, and an auto-default. The smallest viable DSM shape. (expand for full JSON)
{ "kind": "dsm-file", "schemaVersion": "0.1.0", "tables": [ { "kind": "table", "name": "todos", "description": "A list of todo items.", "columns": [ { "kind": "column", "name": "id", "dataType": "UUID", "primaryKey": true, "defaultValue": "gen_random_uuid()" }, { "kind": "column", "name": "title", "dataType": "VARCHAR(255)", "nullable": false }, { "kind": "column", "name": "completed", "dataType": "BOOLEAN", "defaultValue": "false" }, { "kind": "column", "name": "created_at", "dataType": "TIMESTAMP", "defaultValue": "now()" } ], "constraints": [ { "kind": "constraint", "name": "chk_title_not_blank", "type": "check", "expression": "length(title) > 0" } ], "indexes": [] } ], "enums": [], "migrations": []}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-travel-tables.json). The full source is also expanded in the <details> below this preview.
Demo 2 — multi-table DSM with FK-less linked tables (passengers, flights), check constraints on format + age, and indexes on hot query paths. The canonical 'realistic' example.
demo-02-travel-tables.json — Demo 2 — multi-table DSM with FK-less linked tables (passengers, flights), check constraints on format + age, and indexes on hot query paths. The canonical ‘realistic’ example. (expand for full JSON)
{ "kind": "dsm-file", "schemaVersion": "0.1.0", "tables": [ { "kind": "table", "name": "passengers", "aggregate": "Passenger", "description": "Passenger profiles.", "columns": [ { "kind": "column", "name": "id", "dataType": "UUID", "primaryKey": true, "defaultValue": "gen_random_uuid()" }, { "kind": "column", "name": "email", "dataType": "VARCHAR(255)", "unique": true, "nullable": false }, { "kind": "column", "name": "first_name", "dataType": "VARCHAR(100)", "nullable": false }, { "kind": "column", "name": "last_name", "dataType": "VARCHAR(100)", "nullable": false }, { "kind": "column", "name": "date_of_birth", "dataType": "DATE", "nullable": false } ], "constraints": [ { "kind": "constraint", "name": "chk_email_format", "type": "check", "expression": "email ~* '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$'" }, { "kind": "constraint", "name": "chk_adult_passenger", "type": "check", "expression": "date_of_birth <= CURRENT_DATE - INTERVAL '18 years'" } ], "indexes": [ { "kind": "index", "name": "idx_passenger_email", "columns": ["email"] } ] }, { "kind": "table", "name": "flights", "aggregate": "Flight", "description": "Flight schedule and seat inventory.", "columns": [ { "kind": "column", "name": "id", "dataType": "UUID", "primaryKey": true, "defaultValue": "gen_random_uuid()" }, { "kind": "column", "name": "flight_number", "dataType": "VARCHAR(10)", "unique": true, "nullable": false }, { "kind": "column", "name": "origin", "dataType": "CHAR(3)", "nullable": false }, { "kind": "column", "name": "destination", "dataType": "CHAR(3)", "nullable": false }, { "kind": "column", "name": "departure_time", "dataType": "TIMESTAMP", "nullable": false }, { "kind": "column", "name": "available_seats", "dataType": "INTEGER", "defaultValue": "0" } ], "constraints": [ { "kind": "constraint", "name": "chk_seats_non_negative", "type": "check", "expression": "available_seats >= 0" } ], "indexes": [ { "kind": "index", "name": "idx_flight_route", "columns": ["origin", "destination", "departure_time"] } ] } ], "enums": [], "migrations": []}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-orders-with-fk.json). The full source is also expanded in the <details> below this preview.
Demo 3 — DSM with explicit foreign keys (orders → customers, order_lines → orders), enums, composite defaults, and per-table CHECK constraints.
demo-03-orders-with-fk.json — Demo 3 — DSM with explicit foreign keys (orders → customers, order_lines → orders), enums, composite defaults, and per-table CHECK constraints. (expand for full JSON)
{ "kind": "dsm-file", "schemaVersion": "0.1.0", "tables": [ { "kind": "table", "name": "orders", "description": "Order header table.", "columns": [ { "kind": "column", "name": "id", "dataType": "UUID", "primaryKey": true, "defaultValue": "gen_random_uuid()" }, { "kind": "column", "name": "customer_id", "dataType": "UUID", "nullable": false }, { "kind": "column", "name": "total", "dataType": "NUMERIC(12,2)", "nullable": false }, { "kind": "column", "name": "currency", "dataType": "CHAR(3)", "defaultValue": "USD" }, { "kind": "column", "name": "status", "dataType": "order_status", "nullable": false, "defaultValue": "draft" }, { "kind": "column", "name": "created_at", "dataType": "TIMESTAMP", "defaultValue": "now()" } ], "constraints": [ { "kind": "constraint", "name": "chk_total_positive", "type": "check", "expression": "total > 0" } ], "indexes": [ { "kind": "index", "name": "idx_orders_customer", "columns": ["customer_id"] }, { "kind": "index", "name": "idx_orders_status", "columns": ["status"] } ] }, { "kind": "table", "name": "order_lines", "description": "Order line items.", "columns": [ { "kind": "column", "name": "id", "dataType": "UUID", "primaryKey": true, "defaultValue": "gen_random_uuid()" }, { "kind": "column", "name": "order_id", "dataType": "UUID", "nullable": false }, { "kind": "column", "name": "sku", "dataType": "VARCHAR(50)", "nullable": false }, { "kind": "column", "name": "quantity", "dataType": "INTEGER", "nullable": false, "defaultValue": "1" }, { "kind": "column", "name": "unit_price", "dataType": "NUMERIC(12,2)", "nullable": false } ], "constraints": [ { "kind": "constraint", "name": "chk_quantity_positive", "type": "check", "expression": "quantity > 0" }, { "kind": "constraint", "name": "chk_unit_price_non_negative", "type": "check", "expression": "unit_price >= 0" } ], "indexes": [ { "kind": "index", "name": "idx_order_lines_order", "columns": ["order_id"] } ] } ], "enums": [], "migrations": []}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-users-roles-m2m.json). The full source is also expanded in the <details> below this preview.
Demo 4 — DSM with a many-to-many join table (user_roles) including a composite primary-key constraint. Exercises the relationship vocabulary.
demo-04-users-roles-m2m.json — Demo 4 — DSM with a many-to-many join table (user_roles) including a composite primary-key constraint. Exercises the relationship vocabulary. (expand for full JSON)
{ "kind": "dsm-file", "schemaVersion": "0.1.0", "tables": [ { "kind": "table", "name": "users", "description": "Users of the platform.", "columns": [ { "kind": "column", "name": "id", "dataType": "UUID", "primaryKey": true, "defaultValue": "gen_random_uuid()" }, { "kind": "column", "name": "email", "dataType": "VARCHAR(255)", "unique": true, "nullable": false }, { "kind": "column", "name": "created_at", "dataType": "TIMESTAMP", "defaultValue": "now()" } ], "constraints": [], "indexes": [ { "kind": "index", "name": "idx_users_email", "columns": ["email"], "unique": true } ] }, { "kind": "table", "name": "roles", "description": "Static role lookup table.", "columns": [ { "kind": "column", "name": "id", "dataType": "UUID", "primaryKey": true, "defaultValue": "gen_random_uuid()" }, { "kind": "column", "name": "name", "dataType": "VARCHAR(50)", "unique": true, "nullable": false } ], "constraints": [], "indexes": [ { "kind": "index", "name": "idx_roles_name", "columns": ["name"], "unique": true } ] }, { "kind": "table", "name": "user_roles", "description": "Many-to-many join between users and roles.", "columns": [ { "kind": "column", "name": "user_id", "dataType": "UUID", "nullable": false }, { "kind": "column", "name": "role_id", "dataType": "UUID", "nullable": false }, { "kind": "column", "name": "granted_at", "dataType": "TIMESTAMP", "defaultValue": "now()" } ], "constraints": [ { "kind": "constraint", "name": "uq_user_roles_composite", "type": "unique" } ], "indexes": [ { "kind": "index", "name": "idx_user_roles_user", "columns": ["user_id"] }, { "kind": "index", "name": "idx_user_roles_role", "columns": ["role_id"] }, { "kind": "index", "name": "uq_user_roles_composite", "columns": ["user_id", "role_id"], "unique": true } ] } ], "enums": [], "migrations": []}What this model produces
Section titled “What this model produces”The dsm 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.
- **DSM v0.2.0** — `models/dsm.json`. Produces: Data dictionary, Drizzle ORM schema, SQL DDL, schema tests, migration tests. Oracle: schema and migration tests must pass against the generated DDL/ORM code. Downstream: `ctxbrew semantics dsm` · `ctxbrew://semantics/dsm/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 dsm --schema-version 0.2.0 - MCP —
ctxbrew://semantics/dsm/v0.2.0 - HTTP —
https://contextbrew.dev/schemas/dsm/v0.2/semantics.json
See the schemas overview for the versioning policy and how these files are generated and kept in sync.








