Scene schema
A diagram is a scene document in DSP, the Diagram Scene Protocol. Two JSON Schemas define it, and they are the machine-readable contract:
| Schema | Defines |
|---|---|
| scene.schema.json | Scene documents: elements, styles, assets, constraints |
| ops.schema.json | Operation envelopes and the typed operations |
Both use JSON Schema Draft 2020-12, and their URLs are stable. The schemas and the DSP spec are open source under the Apache License 2.0 at github.com/zindexai/diagram-scene-protocol; the Zindex engine and hosted service are not.
A scene document
{
"schemaVersion": "0.1",
"diagramFamily": "workflow",
"layoutStrategy": { "direction": "TB" },
"scene": {
"title": "My Diagram",
"units": "px",
"canvas": { "width": 1200, "height": 800, "background": "#ffffff" }
},
"elements": [],
"styles": {},
"constraints": []
}
schemaVersion,sceneandelementsare required.diagramFamilyis optional in the schema, but declare it on every scene:architecture,flowchart,workflow,entityRelationship,sequence,network,orgchartoruiflow. It selects family node types, rules and drawing; without it the diagram draws as an architecture diagram, and nothing warns you (Diagram families).layoutStrategysets the direction (TB,BT,LRorRL) and spacing of the layered layout that architecture, flowchart, workflow, entity-relationship and UI flow diagrams use (Layout engine). Without a direction, flowcharts run top to bottom and the others left to right. In an AWS diagram, an explicitLRdraws the Availability Zones as rows (Layout engine: AWS architecture diagrams).themeis the look every drawing of the diagram uses:clean(the default),dark,blueprintorsketch(Rendering: Render themes). A diagram incleanis read back without it. A canvas color doesn’t choose it (Rendering: Canvas color).sceneholds the title, the canvas andbrief, the diagram’s brief of up to 1,000 characters.scene.langis the language the text is in, a BCP 47 tag such asja,ko,zh-Hans,zh-Hantorzh-HK. When it names Chinese, Japanese or Korean, it picks the letterforms of Chinese characters for the whole diagram; no element sets its own. Without it, or with another language such asen, kana is read as Japanese, Hangul as Korean, and other Chinese characters as Simplified Chinese, Traditional Chinese or Japanese by the forms they use. A diagram whose Chinese characters Simplified Chinese, Traditional Chinese and Japanese all share is read as Simplified Chinese. Japanese written without kana can read as Traditional Chinese. Setlangwhen you know the language. Hong Kong forms needzh-HK.stylesholds named styles elements refer to,palettethe scene’s colors,constraintsthe constraints, andextensionsoptions such asautoGroup.computedis the engine’s drawing output (element boxes, edge routes, label positions). A read withview=dspleaves it out. Leave it out of scenes you write. A scene that carries it is still accepted: the engine ignores it, whatever it holds, and works it out again.
Element kinds
| Kind | Is |
|---|---|
node | A shape with a label |
edge | A connection between two elements |
group | A logical grouping, not drawn |
frame | A visual container with a title |
text | A standalone text block |
image | An image from the scene’s assets |
guide | A horizontal or vertical guide line |
Element types has every kind’s fields, shapes, node types and edge types.
Layout modes
- Auto-layout, the default: leave
layoutoff a node and the engine places it (a sequence diagram’s nodes are placed from its messages on every save). After the first save it keeps each position in the node’slayout, unless:- a node that grows needs the room
- a new node’s edge label needs more room than the column it joins
- an edit adds a line, or changes what its label needs, and the label has no room on its line, or
autoLayoutnames the line (Layout engine) - a new task in a pool needs room in its lane or a column of its own
- a node an edit inserts in a flowchart needs room along the flow
- a node an edit adds to a frame without a
layouthas no room there - an AWS diagram’s row or column grows for a node or a spanning frame’s header an edit adds, or for the room round a tier frame
- an edit moves an AWS diagram’s Region’s column right to keep a labeled line into the column clear
- a Google Cloud diagram’s row, zone column, Region or project’s box grows for what an edit adds or a group’s title it widens, a gap between two Regions, two projects or two zone columns opens, or a line crosses an item in a row or moves an item under it
- a layer in a stack of layers grows for a card an edit adds to it or moves into it, or an edit adds a layer, and what lies after it moves along by the growth (the card stands in that layer’s row)
- an edit moves it to another lane
- a frame added or deleted around it would leave frames overlapping or a frame holding a node that isn’t its member
- an
orderconstraint you add finds its two nodes the wrong way around
- Absolute:
layout: { "mode": "absolute", "x": 40, "y": 40, "width": 180, "height": 70 }. Nodes and frames also takex,y,widthandheightdirectly, which Zindex turns into an absolutelayout. Text and image elements need alayout. - Relative:
layout: { "mode": "relative", "place": { "rightOf": "api", "gap": 40 } }places an element against another (rightOf,leftOf,above,beloworinside).
A scene can mix them: fix some nodes and let the engine place the rest.
Checking a document
POST /v1/diagrams/validate, which needs no key, and the MCP tool diagram_validate, which needs sign-in or a key, check a scene against the schema and every rule (Validation rules). Any JSON Schema validator checks the schema alone. A version saved before 7.0.0, read with view=dsp or exported, carries ports: [] on every node, which this schema no longer has: the API drops it, so check such a version with POST /v1/diagrams/validate, or delete the field before checking it locally:
A version’s record from your repository can carry autoSize: "children" on a frame’s layout, which this schema doesn’t list. The API reads such a frame as one without a layout: send the record’s scene as it is, or delete that layout before checking it locally.
# ajv-cli reads local files: download the schema first.
# The schemas are Draft 2020-12 and use the uri and date-time formats.
curl -sO https://zindex.ai/schemas/scene.schema.json
npx -p ajv-cli -p ajv-formats ajv validate --spec=draft2020 --strict=false -c ajv-formats -s scene.schema.json -d my-scene.json
A version saved before 8.0.0 can hold sequence fragment operands with a y, which this schema refuses and the API doesn’t drop: replace each with startsAt, the ID of the message or note the operand starts at, before checking or sending it.
Types for other languages can be generated from the schemas, for example with npx -p json-schema-to-typescript json2ts -i scene.schema.json -o dsp-types.ts.