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, computed data |
| 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.sceneholds the title, the canvas andbrief, the diagram’s brief of up to 1,000 characters.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.
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. 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, 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, 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, or an edit moves its Region’s column right to keep a labeled line into the column clear, 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, or anorderconstraint you add finds its two nodes the wrong way around. Sequence diagrams are laid out from their messages on every save. - 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 and diagram_validate check a scene against the schema and every rule, with no key (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:
# 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.