{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://graffalo.io/schemas/document-v1.json",
  "title": "Graffalo document v1 — authoring",
  "description": "Structural authoring schema. Defaults are annotations; call validate_diagram to normalize and perform reference, uniqueness, size and graph checks. JSON Schema success alone is not server acceptance. Unknown extension properties are preserved. Rust currently measures some limits in UTF-8 bytes, so use ASCII stable IDs and conservative text sizes.",
  "type": "object",
  "required": [
    "schemaVersion",
    "id",
    "title",
    "activePageId",
    "background",
    "pages"
  ],
  "properties": {
    "schemaVersion": {
      "const": 1
    },
    "id": {
      "$ref": "#/$defs/id"
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200
    },
    "activePageId": {
      "$ref": "#/$defs/id"
    },
    "background": {
      "type": "string"
    },
    "pages": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/page"
      },
      "maxItems": 100,
      "minItems": 1
    },
    "slideScheme": {
      "enum": [
        "light",
        "dark"
      ]
    },
    "colorPalette": {
      "$ref": "#/$defs/palette"
    },
    "edgeLabelDefaults": {
      "$ref": "#/$defs/edgeLabelStyle"
    },
    "titleBlock": {
      "$ref": "#/$defs/titleBlock"
    }
  },
  "$defs": {
    "evidenceReference": {
      "type": "object",
      "required": [
        "label",
        "location"
      ],
      "properties": {
        "label": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "location": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2048
        },
        "locator": {
          "type": "string",
          "maxLength": 500
        },
        "revision": {
          "type": "string",
          "maxLength": 200
        }
      },
      "additionalProperties": false,
      "description": "Author-supplied source name and location, with optional page/section/line and revision/date. Name and location must contain non-whitespace text. Plain metadata, never fetched or executed."
    },
    "evidence": {
      "type": "object",
      "required": [
        "status",
        "references"
      ],
      "properties": {
        "status": {
          "enum": [
            "observed",
            "inferred",
            "unverified"
          ]
        },
        "summary": {
          "type": "string",
          "maxLength": 2000
        },
        "references": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/evidenceReference"
          },
          "maxItems": 16
        }
      },
      "additionalProperties": false,
      "allOf": [
        {
          "if": {
            "properties": {
              "status": {
                "const": "observed"
              }
            },
            "required": [
              "status"
            ]
          },
          "then": {
            "properties": {
              "references": {
                "minItems": 1
              }
            }
          }
        }
      ],
      "description": "Author assessment, not independent verification. Observed requires a source; inferred and unverified can retain gaps. Optional on nodes and edges. update_node/update_edge replace the complete evidence record; evidence:null removes it."
    },
    "edgeLabelStyle": {
      "type": "object",
      "required": [],
      "properties": {
        "labelFontSize": {
          "type": "number",
          "minimum": 8,
          "maximum": 72
        },
        "labelMaxWidth": {
          "type": "number",
          "minimum": 40,
          "maximum": 1200
        },
        "labelColor": {
          "type": "string",
          "maxLength": 80
        },
        "labelBackground": {
          "type": "string",
          "maxLength": 80,
          "description": "pill, halo, none, or a solid CSS name/hex color for a custom pill."
        }
      },
      "additionalProperties": false
    },
    "id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 199
    },
    "point": {
      "type": "object",
      "required": [
        "x",
        "y"
      ],
      "properties": {
        "x": {
          "type": "number",
          "minimum": -100000000,
          "maximum": 100000000
        },
        "y": {
          "type": "number",
          "minimum": -100000000,
          "maximum": 100000000
        }
      }
    },
    "data": {
      "type": "object",
      "maxProperties": 64,
      "propertyNames": {
        "minLength": 1,
        "maxLength": 80
      },
      "additionalProperties": {
        "type": [
          "string",
          "number",
          "boolean",
          "null"
        ],
        "maxLength": 10000
      }
    },
    "style": {
      "type": "object",
      "required": [],
      "properties": {
        "fill": {
          "type": "string",
          "default": "#ffffff"
        },
        "stroke": {
          "type": "string",
          "default": "#d9dce6"
        },
        "strokeWidth": {
          "type": "number",
          "minimum": 0,
          "maximum": 1000,
          "default": 1.5
        },
        "textColor": {
          "type": "string",
          "default": "#34394f"
        },
        "fontSize": {
          "type": "number",
          "minimum": 0,
          "maximum": 1000,
          "default": 14
        },
        "bold": {
          "type": "boolean",
          "default": false
        },
        "radius": {
          "type": "number",
          "minimum": 0,
          "maximum": 1000,
          "default": 12
        },
        "opacity": {
          "type": "number",
          "minimum": 0,
          "maximum": 1000,
          "default": 1
        },
        "shadow": {
          "type": "boolean",
          "default": true
        },
        "dashed": {
          "type": "boolean",
          "default": false
        }
      },
      "description": "Every omitted field is supplied by Graffalo. Supplied nulls and wrong types are rejected.",
      "default": {
        "fill": "#ffffff",
        "stroke": "#d9dce6",
        "strokeWidth": 1.5,
        "textColor": "#34394f",
        "fontSize": 14,
        "bold": false,
        "radius": 12,
        "opacity": 1,
        "shadow": true,
        "dashed": false
      }
    },
    "endpoint": {
      "type": "object",
      "required": [
        "x",
        "y"
      ],
      "properties": {
        "x": {
          "type": "number",
          "minimum": -100000000,
          "maximum": 100000000
        },
        "y": {
          "type": "number",
          "minimum": -100000000,
          "maximum": 100000000
        },
        "nodeId": {
          "$ref": "#/$defs/id"
        },
        "groupId": {
          "$ref": "#/$defs/id"
        },
        "port": {
          "enum": [
            "top",
            "right",
            "bottom",
            "left"
          ]
        },
        "socketId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        }
      },
      "description": "nodeId references a node; groupId references a group boundary on this page. They are mutually exclusive. Group endpoints require port, cannot use socketId, and need members or explicit emptyBounds. socketId is node-scoped and must exist; table row ports are left/right. Coordinates remain required even when attached.",
      "allOf": [
        {
          "if": {
            "required": [
              "groupId"
            ]
          },
          "then": {
            "required": [
              "port"
            ],
            "not": {
              "anyOf": [
                {
                  "required": [
                    "nodeId"
                  ]
                },
                {
                  "required": [
                    "socketId"
                  ]
                }
              ]
            }
          }
        }
      ]
    },
    "field": {
      "type": "object",
      "required": [
        "name"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "type": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "value": {
          "$ref": "#/$defs/boundedValue"
        },
        "description": {
          "type": "string"
        }
      }
    },
    "socket": {
      "type": "object",
      "required": [
        "id",
        "name"
      ],
      "properties": {
        "offset": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "description": "Optional socket height as a fraction of the node height; used for sequence lifeline events."
        },
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "type": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "value": {
          "$ref": "#/$defs/boundedValue"
        },
        "color": {
          "type": "string",
          "pattern": "^#[0-9a-fA-F]{6}$",
          "description": "Optional authored row/socket color. Omit to use the automatic type color. Preserved across theme changes; wire color is independently authored."
        }
      }
    },
    "boundedValue": {
      "description": "Additional server limits: nesting depth <=12, arrays <=1000, objects <=256 keys, keys <=200 characters, strings <=10000; no __proto__/constructor/prototype keys.",
      "oneOf": [
        {
          "type": [
            "null",
            "boolean",
            "number"
          ]
        },
        {
          "type": "string",
          "maxLength": 10000
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/boundedValue"
          },
          "maxItems": 1000
        },
        {
          "type": "object",
          "maxProperties": 256,
          "propertyNames": {
            "maxLength": 200,
            "not": {
              "enum": [
                "__proto__",
                "constructor",
                "prototype"
              ]
            }
          },
          "additionalProperties": {
            "$ref": "#/$defs/boundedValue"
          }
        }
      ]
    },
    "details": {
      "type": "object",
      "required": [],
      "properties": {
        "presentation": {
          "enum": [
            "table",
            "lifeline"
          ]
        },
        "description": {
          "type": "string"
        },
        "fields": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/field"
          },
          "maxItems": 128
        },
        "inputs": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/socket"
          },
          "maxItems": 256
        },
        "outputs": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/socket"
          },
          "maxItems": 256
        },
        "source": {
          "type": "object",
          "required": [
            "application",
            "id",
            "type"
          ],
          "properties": {
            "application": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            "id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            "type": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            "tree": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            }
          }
        }
      },
      "description": "Total details JSON <=100000 characters and bounded recursive values. Table fields require unique stable IDs; table height >=48+28*max(1,field count). Socket IDs are unique within each direction.",
      "allOf": [
        {
          "if": {
            "properties": {
              "presentation": {
                "const": "table"
              }
            },
            "required": [
              "presentation"
            ]
          },
          "then": {
            "properties": {
              "fields": {
                "items": {
                  "required": [
                    "id"
                  ]
                }
              }
            }
          }
        }
      ]
    },
    "node": {
      "type": "object",
      "required": [
        "id",
        "kind",
        "x",
        "y",
        "width",
        "height",
        "rotation",
        "text",
        "layerId"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "kind": {
          "enum": [
            "rounded",
            "rect",
            "ellipse",
            "diamond",
            "hexagon",
            "cylinder",
            "text",
            "sticky",
            "triangle",
            "right-triangle",
            "pentagon",
            "octagon",
            "star",
            "parallelogram",
            "trapezoid",
            "capsule",
            "document",
            "cloud",
            "right-arrow",
            "left-arrow",
            "plus",
            "mesh",
            "state-initial",
            "state-final",
            "state-fork",
            "state-join"
          ]
        },
        "x": {
          "type": "number",
          "minimum": -100000000,
          "maximum": 100000000
        },
        "y": {
          "type": "number",
          "minimum": -100000000,
          "maximum": 100000000
        },
        "width": {
          "type": "number",
          "minimum": 10,
          "maximum": 100000000
        },
        "height": {
          "type": "number",
          "minimum": 10,
          "maximum": 100000000
        },
        "rotation": {
          "type": "number",
          "minimum": -100000000,
          "maximum": 100000000
        },
        "text": {
          "type": "string",
          "maxLength": 10000
        },
        "layerId": {
          "$ref": "#/$defs/id"
        },
        "groupId": {
          "$ref": "#/$defs/id"
        },
        "paletteIndex": {
          "type": "integer",
          "minimum": 0,
          "maximum": 10000
        },
        "style": {
          "$ref": "#/$defs/style"
        },
        "evidence": {
          "$ref": "#/$defs/evidence"
        },
        "data": {
          "$ref": "#/$defs/data"
        },
        "details": {
          "$ref": "#/$defs/details"
        },
        "note": {
          "type": "string"
        },
        "vectorPath": {
          "type": "string",
          "minLength": 1,
          "maxLength": 250000,
          "pattern": "^[ML0-9., eE+\\-]+$"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "kind": {
                "const": "mesh"
              }
            },
            "required": [
              "kind"
            ]
          },
          "then": {
            "required": [
              "vectorPath"
            ]
          }
        }
      ]
    },
    "labelPlacement": {
      "type": "object",
      "required": [
        "dx",
        "dy",
        "mode"
      ],
      "properties": {
        "dx": {
          "type": "number",
          "minimum": -10000,
          "maximum": 10000
        },
        "dy": {
          "type": "number",
          "minimum": -10000,
          "maximum": 10000
        },
        "mode": {
          "enum": [
            "auto",
            "manual"
          ]
        }
      },
      "additionalProperties": false,
      "description": "Saved offset from the canonical connection label anchor. Automatic arrangement preserves manual placements."
    },
    "cardinality": {
      "type": "object",
      "required": [
        "start",
        "end"
      ],
      "properties": {
        "start": {
          "enum": [
            "one",
            "many"
          ]
        },
        "end": {
          "enum": [
            "one",
            "many"
          ]
        },
        "startMin": {
          "enum": [
            0,
            1
          ]
        },
        "endMin": {
          "enum": [
            0,
            1
          ]
        }
      },
      "description": "Each end counts attached entities per entity at the opposite end, independent of arrow direction. Optional startMin/endMin specify zero or one minimum; omission leaves the minimum unspecified. E.g. nullable FK to PK: start many/startMin 0, end one/endMin 0."
    },
    "markers": {
      "type": "object",
      "required": [
        "start",
        "end"
      ],
      "properties": {
        "start": {
          "enum": [
            "none",
            "open",
            "triangle",
            "triangle-open",
            "triangle-inverted",
            "triangle-inverted-open",
            "diamond",
            "diamond-open",
            "circle",
            "circle-open",
            "bar",
            "crow",
            "cross",
            "box",
            "box-open"
          ]
        },
        "end": {
          "enum": [
            "none",
            "open",
            "triangle",
            "triangle-open",
            "triangle-inverted",
            "triangle-inverted-open",
            "diamond",
            "diamond-open",
            "circle",
            "circle-open",
            "bar",
            "crow",
            "cross",
            "box",
            "box-open"
          ]
        }
      },
      "additionalProperties": false,
      "description": "Explicit endpoint notation. Mutually exclusive with cardinality; does not change graph connectivity."
    },
    "edge": {
      "type": "object",
      "required": [
        "id",
        "start",
        "end",
        "kind",
        "arrow",
        "color",
        "layerId"
      ],
      "properties": {
        "labelFontSize": {
          "type": "number",
          "minimum": 8,
          "maximum": 72
        },
        "labelMaxWidth": {
          "type": "number",
          "minimum": 40,
          "maximum": 1200
        },
        "labelColor": {
          "type": "string",
          "maxLength": 80
        },
        "labelBackground": {
          "type": "string",
          "maxLength": 80,
          "description": "pill, halo, none, or a solid CSS name/hex color for a custom pill."
        },
        "endpointLabelLayout": {
          "enum": [
            "measured-v1"
          ],
          "description": "Set by Arrange labels when it reserves measured endpoint caption space; absence preserves legacy saved geometry."
        },
        "startLabel": {
          "type": "string",
          "maxLength": 200
        },
        "endLabel": {
          "type": "string",
          "maxLength": 200
        },
        "markers": {
          "$ref": "#/$defs/markers"
        },
        "cardinality": {
          "$ref": "#/$defs/cardinality"
        },
        "labelPlacement": {
          "$ref": "#/$defs/labelPlacement"
        },
        "id": {
          "$ref": "#/$defs/id"
        },
        "start": {
          "$ref": "#/$defs/endpoint"
        },
        "end": {
          "$ref": "#/$defs/endpoint"
        },
        "kind": {
          "enum": [
            "elbow",
            "curve",
            "straight"
          ]
        },
        "arrow": {
          "enum": [
            "none",
            "end",
            "both"
          ]
        },
        "color": {
          "type": "string"
        },
        "label": {
          "type": "string",
          "default": ""
        },
        "width": {
          "type": "number",
          "exclusiveMinimum": 0,
          "maximum": 50,
          "default": 1.7
        },
        "dashed": {
          "type": "boolean",
          "default": false
        },
        "layerId": {
          "$ref": "#/$defs/id"
        },
        "route": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/point"
          },
          "maxItems": 1000,
          "minItems": 2
        },
        "evidence": {
          "$ref": "#/$defs/evidence"
        },
        "data": {
          "$ref": "#/$defs/data"
        }
      }
    },
    "layer": {
      "type": "object",
      "required": [
        "id",
        "name",
        "visible",
        "locked"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "name": {
          "type": "string"
        },
        "visible": {
          "type": "boolean"
        },
        "locked": {
          "type": "boolean"
        }
      }
    },
    "groupStyle": {
      "type": "object",
      "required": [],
      "properties": {
        "panelFill": {
          "type": "string",
          "maxLength": 80
        },
        "stroke": {
          "type": "string",
          "maxLength": 80
        },
        "strokeWidth": {
          "type": "number",
          "minimum": 0,
          "maximum": 8
        },
        "strokeDash": {
          "enum": [
            "solid",
            "dashed",
            "dotted"
          ]
        },
        "radius": {
          "type": "number",
          "minimum": 0,
          "maximum": 48
        },
        "titleBar": {
          "type": "object",
          "required": [],
          "properties": {
            "fill": {
              "type": "string",
              "maxLength": 80
            },
            "textColor": {
              "type": "string",
              "maxLength": 80
            },
            "fontSize": {
              "type": "number",
              "minimum": 8,
              "maximum": 40
            },
            "height": {
              "type": "number",
              "minimum": 22,
              "maximum": 160
            }
          },
          "additionalProperties": false
        },
        "divider": {
          "type": "object",
          "required": [],
          "properties": {
            "color": {
              "type": "string",
              "maxLength": 80
            },
            "width": {
              "type": "number",
              "minimum": 0,
              "maximum": 8
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false,
      "description": "Solid CSS color names or hex only. Group panel style is independent from child-node styles. Header grows to fit the complete wrapped title."
    },
    "group": {
      "type": "object",
      "required": [
        "id",
        "name"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 80
        },
        "parentId": {
          "$ref": "#/$defs/id"
        },
        "collapsed": {
          "type": "boolean"
        },
        "style": {
          "$ref": "#/$defs/groupStyle"
        },
        "data": {
          "$ref": "#/$defs/data"
        },
        "layoutPadding": {
          "type": "object",
          "required": [
            "x",
            "y"
          ],
          "properties": {
            "x": {
              "type": "number",
              "minimum": 0,
              "maximum": 10000
            },
            "y": {
              "type": "number",
              "minimum": 0,
              "maximum": 10000
            }
          },
          "description": "Extra relative content space reserved by automatic caption layout. Does not replace authored group styling."
        },
        "emptyBounds": {
          "type": "object",
          "required": [
            "x",
            "y",
            "width",
            "height"
          ],
          "properties": {
            "x": {
              "type": "number",
              "minimum": -100000000,
              "maximum": 100000000
            },
            "y": {
              "type": "number",
              "minimum": -100000000,
              "maximum": 100000000
            },
            "width": {
              "type": "number",
              "minimum": 10,
              "maximum": 100000000
            },
            "height": {
              "type": "number",
              "minimum": 10,
              "maximum": 100000000
            }
          },
          "description": "Content envelope used only when the group has no members or child frames. Expanded groups otherwise fit their content."
        }
      },
      "description": "parentId must exist on this page and must not create a cycle. Empty groups are supported. Legacy implicit node.groupId values are accepted."
    },
    "page": {
      "type": "object",
      "required": [
        "id",
        "name",
        "layers",
        "nodes",
        "edges"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "name": {
          "type": "string"
        },
        "layers": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/layer"
          },
          "minItems": 1
        },
        "nodes": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/node"
          },
          "maxItems": 10000
        },
        "edges": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/edge"
          },
          "maxItems": 20000
        },
        "groups": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/group"
          },
          "maxItems": 10000
        },
        "legend": {
          "$ref": "#/$defs/legend"
        },
        "deferred": false
      }
    },
    "legend": {
      "type": "object",
      "required": [
        "visible"
      ],
      "properties": {
        "visible": {
          "type": "boolean"
        },
        "position": {
          "type": "object",
          "required": [
            "x",
            "y"
          ],
          "properties": {
            "x": {
              "type": "number",
              "minimum": -1000000,
              "maximum": 1000000
            },
            "y": {
              "type": "number",
              "minimum": -1000000,
              "maximum": 1000000
            }
          },
          "additionalProperties": false
        },
        "labels": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "key",
              "label"
            ],
            "properties": {
              "key": {
                "type": "string",
                "minLength": 1,
                "maxLength": 600
              },
              "label": {
                "type": "string",
                "minLength": 1,
                "maxLength": 160
              }
            },
            "additionalProperties": false
          },
          "maxItems": 128
        }
      },
      "additionalProperties": false,
      "description": "Automatic node-style legend for this canvas. Labels have unique keys; string limits use UTF-16 units. Position is optional. Derivation uses visible node fill/stroke/dash styles, excluding text annotations and zero-opacity nodes. At most 64 styles rendered, with an explicit overflow count. Never part of graph topology."
    },
    "titleBlock": {
      "type": "object",
      "required": [
        "visible"
      ],
      "properties": {
        "visible": {
          "type": "boolean"
        },
        "subtitle": {
          "type": "string",
          "maxLength": 1000
        },
        "color": {
          "type": "string",
          "maxLength": 80
        }
      },
      "additionalProperties": false,
      "description": "Optional document heading. Uses the current document title, with an optional plain-text subtitle (1000 UTF-16 units max). Color accepts solid CSS names or hex; automatic color follows the canvas background. Independent of graph layout; included in exports."
    },
    "palette": {
      "type": "object",
      "required": [
        "id",
        "name",
        "colors"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 80
        },
        "colors": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^#[0-9a-fA-F]{6}$"
          },
          "maxItems": 64,
          "minItems": 1
        },
        "assignment": {
          "enum": [
            "families",
            "groups",
            "depth"
          ]
        }
      }
    }
  }
}
