{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tekyous.dev/schemas/diagram.v1.json",
  "title": "Tekyous diagram",
  "description": "A Tekyous stack diagram: either the spec (\"format\": \"tekyous-diagram\") or a full canvas file (\"format\": \"tekyous-canvas\", version 2). Opened with https://tekyous.dev/builder#doc=<encoded>. Generated by tekyous-frontend scripts/build-diagram-schema.mjs; do not edit by hand.",
  "oneOf": [
    {
      "$ref": "#/$defs/spec"
    },
    {
      "$ref": "#/$defs/canvas"
    }
  ],
  "$defs": {
    "color": {
      "description": "A palette key or a #rrggbb colour. Nothing else (no CSS).",
      "anyOf": [
        {
          "enum": [
            "none",
            "default",
            "slate",
            "amber",
            "sky",
            "violet",
            "emerald",
            "rose"
          ]
        },
        {
          "type": "string",
          "pattern": "^#[0-9a-fA-F]{6}$"
        }
      ]
    },
    "toolSlug": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9-]{0,79}$",
      "description": "A tool slug from the Tekyous catalogue, e.g. \"postgresql\". An unknown slug becomes a placeholder card and is reported back."
    },
    "categorySlug": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9-]{0,79}$",
      "description": "A catalogue category or subcategory slug, e.g. \"databases\"."
    },
    "id": {
      "type": "string",
      "pattern": "^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$",
      "description": "Your own id, unique in the diagram. Tool slugs are ids too."
    },
    "caption": {
      "type": "string",
      "maxLength": 120,
      "description": "A short line under the card."
    },
    "spec": {
      "type": "object",
      "properties": {
        "format": {
          "const": "tekyous-diagram"
        },
        "version": {
          "const": 1
        },
        "title": {
          "type": "string",
          "maxLength": 200,
          "description": "Shown as a heading above the diagram."
        },
        "template": {
          "enum": [
            "layered",
            "by-category"
          ],
          "default": "layered",
          "description": "layered: one frame per group, in the order given and the direction below; without groups, the catalogue layers (frontend, backend, data, hosting, AI). by-category: one frame per catalogue category; do not send groups with it."
        },
        "direction": {
          "enum": [
            "left-to-right",
            "top-to-bottom"
          ],
          "default": "left-to-right",
          "description": "How the groups follow each other. left-to-right: each group a column, side by side. top-to-bottom: each group a band, stacked. Order the groups the way the data flows either way."
        },
        "display": {
          "type": "object",
          "properties": {
            "preset": {
              "enum": [
                "detailed",
                "standard",
                "simple",
                "tile",
                "icon"
              ],
              "default": "simple",
              "description": "What a card shows: detailed (name, category, subcategory, pricing), standard (name, category, pricing), simple (logo and name), tile (logo over name), icon (logo only)."
            },
            "outline": {
              "enum": [
                "card",
                "none"
              ],
              "default": "card",
              "description": "none: logos and names without a card border."
            }
          },
          "required": [],
          "additionalProperties": false
        },
        "groups": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/specGroup"
          },
          "maxItems": 30,
          "description": "Frames, each holding its tools: a column (left-to-right) or a band (top-to-bottom)."
        },
        "tools": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/specToolRef"
          },
          "maxItems": 100,
          "description": "Tools outside any group."
        },
        "custom": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/specCustomTool"
          },
          "maxItems": 100,
          "description": "Custom tools outside any group."
        },
        "connectors": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/specConnector"
          },
          "maxItems": 300
        },
        "notes": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/specNote"
          },
          "maxItems": 50
        }
      },
      "required": [
        "format"
      ],
      "additionalProperties": false,
      "description": "The short form: tools by slug in groups, with custom tools, connectors and notes. No positions; Tekyous lays it out.",
      "if": {
        "required": [
          "template"
        ],
        "properties": {
          "template": {
            "const": "by-category"
          }
        }
      },
      "then": {
        "properties": {
          "groups": {
            "maxItems": 0
          }
        }
      }
    },
    "specToolRef": {
      "anyOf": [
        {
          "$ref": "#/$defs/toolSlug"
        },
        {
          "type": "object",
          "properties": {
            "slug": {
              "$ref": "#/$defs/toolSlug"
            },
            "caption": {
              "$ref": "#/$defs/caption"
            }
          },
          "required": [
            "slug"
          ],
          "additionalProperties": false
        }
      ]
    },
    "specCustomTool": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "name": {
          "type": "string",
          "maxLength": 200
        },
        "icon": {
          "type": "string",
          "maxLength": 16,
          "description": "One of database, server, cloud, globe, lock, mail, code, box, queue, chart, user, bolt; or one letter or digit; or up to four emoji."
        },
        "color": {
          "$ref": "#/$defs/color"
        },
        "category": {
          "$ref": "#/$defs/categorySlug"
        },
        "subcategory": {
          "$ref": "#/$defs/categorySlug"
        },
        "pricing": {
          "enum": [
            "freemium",
            "open_source",
            "paid",
            "usage_based"
          ]
        },
        "caption": {
          "$ref": "#/$defs/caption"
        }
      },
      "required": [
        "id",
        "name"
      ],
      "additionalProperties": false,
      "description": "Something the catalogue does not list, such as your own service."
    },
    "specGroup": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "title": {
          "type": "string",
          "maxLength": 200
        },
        "color": {
          "$ref": "#/$defs/color"
        },
        "tools": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/specToolRef"
          },
          "maxItems": 100
        },
        "custom": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/specCustomTool"
          },
          "maxItems": 100
        }
      },
      "required": [
        "id",
        "title"
      ],
      "additionalProperties": false
    },
    "specConnector": {
      "type": "object",
      "properties": {
        "from": {
          "type": "string",
          "maxLength": 64,
          "description": "A tool slug, custom tool id, group id or note id."
        },
        "to": {
          "type": "string",
          "maxLength": 64
        },
        "label": {
          "type": "string",
          "maxLength": 100
        },
        "line": {
          "enum": [
            "solid",
            "dashed"
          ],
          "default": "solid"
        },
        "arrow": {
          "enum": [
            "none",
            "end",
            "both"
          ],
          "default": "end"
        },
        "width": {
          "enum": [
            "thin",
            "medium",
            "thick"
          ],
          "default": "medium"
        },
        "color": {
          "$ref": "#/$defs/color"
        }
      },
      "required": [
        "from",
        "to"
      ],
      "additionalProperties": false
    },
    "specNote": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "text": {
          "type": "string",
          "maxLength": 2000,
          "minLength": 1
        },
        "near": {
          "type": "string",
          "maxLength": 64,
          "description": "The tool slug, custom tool id or group id the note sits beside."
        },
        "color": {
          "$ref": "#/$defs/color"
        }
      },
      "required": [
        "text"
      ],
      "additionalProperties": false
    },
    "canvas": {
      "type": "object",
      "properties": {
        "format": {
          "const": "tekyous-canvas"
        },
        "version": {
          "const": 2
        },
        "exportedAt": {
          "type": "string"
        },
        "entryMode": {
          "enum": [
            "direct",
            "questionnaire",
            null
          ]
        },
        "questionnaire": {
          "type": [
            "object",
            "null"
          ]
        },
        "display": {
          "type": [
            "object",
            "null"
          ],
          "description": "The card display: logo, name, layout, outline, category, pricing."
        },
        "layout": {
          "type": "object",
          "properties": {
            "organized": {
              "type": "boolean",
              "description": "Auto-sort: tools are kept in their category frames."
            },
            "template": {
              "enum": [
                "columns",
                "grid",
                "subcategories",
                "subcategories-wide",
                "layered",
                "blank"
              ]
            },
            "framesMoved": {
              "type": "boolean"
            },
            "originX": {
              "type": "number"
            },
            "direction": {
              "enum": [
                "left-to-right",
                "top-to-bottom"
              ],
              "description": "How frames sent without positions follow each other; left-to-right when absent."
            }
          },
          "required": []
        },
        "objects": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/canvasObject"
          },
          "maxItems": 500
        },
        "summary": {
          "type": "object",
          "description": "Derived on export, ignored on import."
        }
      },
      "required": [
        "format",
        "version",
        "objects"
      ]
    },
    "position": {
      "type": "object",
      "properties": {
        "x": {
          "type": "number"
        },
        "y": {
          "type": "number"
        }
      },
      "required": [
        "x",
        "y"
      ]
    },
    "cardSize": {
      "type": "object",
      "properties": {
        "w": {
          "type": "number"
        },
        "h": {
          "type": "number"
        }
      },
      "required": [
        "w",
        "h"
      ]
    },
    "cardStyle": {
      "type": "object",
      "properties": {
        "bg": {
          "anyOf": [
            {
              "$ref": "#/$defs/color"
            },
            {
              "const": "transparent"
            }
          ]
        },
        "nameColor": {
          "$ref": "#/$defs/color"
        },
        "logoScale": {
          "type": "number"
        },
        "caption": {
          "$ref": "#/$defs/caption"
        }
      },
      "required": []
    },
    "canvasObject": {
      "description": "An object leaves out `position` to be laid out on open: a frame then lists its tools in `contains`, a note may name a neighbour in `near`.",
      "oneOf": [
        {
          "$ref": "#/$defs/obj_tool"
        },
        {
          "$ref": "#/$defs/obj_custom_tool"
        },
        {
          "$ref": "#/$defs/obj_frame"
        },
        {
          "$ref": "#/$defs/obj_text"
        },
        {
          "$ref": "#/$defs/obj_note"
        },
        {
          "$ref": "#/$defs/obj_connector"
        }
      ]
    },
    "obj_tool": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "maxLength": 64
        },
        "kind": {
          "const": "tool"
        },
        "slug": {
          "$ref": "#/$defs/toolSlug"
        },
        "name": {
          "type": "string"
        },
        "categoryName": {
          "type": "string"
        },
        "position": {
          "anyOf": [
            {
              "$ref": "#/$defs/position"
            },
            {
              "type": "null"
            }
          ]
        },
        "state": {
          "enum": [
            "selected",
            "primary",
            "alternative"
          ]
        },
        "hostedOn": {
          "type": [
            "string",
            "null"
          ]
        },
        "size": {
          "$ref": "#/$defs/cardSize"
        },
        "style": {
          "$ref": "#/$defs/cardStyle"
        },
        "pinned": {
          "type": "boolean"
        }
      },
      "required": [
        "kind",
        "slug"
      ]
    },
    "obj_custom_tool": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "maxLength": 64
        },
        "kind": {
          "const": "custom_tool"
        },
        "name": {
          "type": "string",
          "maxLength": 200
        },
        "icon": {
          "type": "object",
          "properties": {
            "type": {
              "enum": [
                "emoji",
                "letter",
                "icon"
              ]
            },
            "value": {
              "type": "string",
              "maxLength": 16
            }
          },
          "required": []
        },
        "color": {
          "$ref": "#/$defs/color"
        },
        "category": {
          "$ref": "#/$defs/categorySlug"
        },
        "subcategory": {
          "$ref": "#/$defs/categorySlug"
        },
        "pricing": {
          "enum": [
            "freemium",
            "open_source",
            "paid",
            "usage_based"
          ]
        },
        "position": {
          "$ref": "#/$defs/position"
        },
        "placeholderFor": {
          "type": "string"
        },
        "size": {
          "$ref": "#/$defs/cardSize"
        },
        "style": {
          "$ref": "#/$defs/cardStyle"
        },
        "pinned": {
          "type": "boolean"
        }
      },
      "required": [
        "kind",
        "name"
      ]
    },
    "obj_frame": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "maxLength": 64
        },
        "kind": {
          "const": "frame"
        },
        "title": {
          "type": "string",
          "maxLength": 200
        },
        "color": {
          "$ref": "#/$defs/color"
        },
        "fill": {
          "enum": [
            "none",
            "soft",
            "strong",
            "solid"
          ]
        },
        "border": {
          "enum": [
            "dashed",
            "solid"
          ]
        },
        "titleAlign": {
          "enum": [
            "left",
            "center",
            "right"
          ]
        },
        "titlePlace": {
          "enum": [
            "inside",
            "above"
          ]
        },
        "titleColor": {
          "$ref": "#/$defs/color"
        },
        "titleSize": {
          "enum": [
            "sm",
            "md",
            "lg",
            "xl"
          ]
        },
        "rule": {
          "type": "object"
        },
        "position": {
          "$ref": "#/$defs/position"
        },
        "size": {
          "$ref": "#/$defs/cardSize"
        },
        "contains": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "maxItems": 500,
          "description": "Only without a position: ids of the tools and custom tools inside, in order."
        }
      },
      "required": [
        "kind"
      ]
    },
    "obj_text": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "maxLength": 64
        },
        "kind": {
          "const": "text"
        },
        "text": {
          "type": "string",
          "maxLength": 2000
        },
        "style": {
          "enum": [
            "heading",
            "label",
            "body"
          ]
        },
        "color": {
          "$ref": "#/$defs/color"
        },
        "align": {
          "enum": [
            "left",
            "center",
            "right"
          ]
        },
        "position": {
          "$ref": "#/$defs/position"
        },
        "size": {
          "type": "object",
          "properties": {
            "w": {
              "type": "number"
            }
          },
          "required": []
        }
      },
      "required": [
        "kind",
        "text"
      ]
    },
    "obj_note": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "maxLength": 64
        },
        "kind": {
          "const": "note"
        },
        "text": {
          "type": "string",
          "maxLength": 2000
        },
        "color": {
          "$ref": "#/$defs/color"
        },
        "position": {
          "$ref": "#/$defs/position"
        },
        "size": {
          "$ref": "#/$defs/cardSize"
        },
        "near": {
          "type": "string",
          "maxLength": 64,
          "description": "Only without a position: the id of the object the note sits beside."
        }
      },
      "required": [
        "kind",
        "text"
      ]
    },
    "obj_connector": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "maxLength": 64
        },
        "kind": {
          "const": "connector"
        },
        "from": {
          "type": "string",
          "maxLength": 64
        },
        "to": {
          "type": "string",
          "maxLength": 64
        },
        "label": {
          "type": "string",
          "maxLength": 100
        },
        "line": {
          "enum": [
            "solid",
            "dashed"
          ]
        },
        "arrow": {
          "enum": [
            "none",
            "end",
            "both"
          ]
        },
        "width": {
          "enum": [
            "thin",
            "medium",
            "thick"
          ]
        },
        "color": {
          "$ref": "#/$defs/color"
        },
        "fromHandle": {
          "enum": [
            "t",
            "r",
            "b",
            "l",
            null
          ]
        },
        "toHandle": {
          "enum": [
            "t",
            "r",
            "b",
            "l",
            null
          ]
        }
      },
      "required": [
        "kind",
        "from",
        "to"
      ]
    }
  }
}
