{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://threatline-model.aidan-marlin.chatgpt.site/threat-model.schema.json",
  "title": "Threat Strata document",
  "description": "Portable JSON interchange format for a data-flow threat model.",
  "type": "object",
  "required": ["format", "schemaVersion", "metadata", "nodes", "edges", "threats"],
  "properties": {
    "format": { "const": "threat-model-studio" },
    "schemaVersion": { "type": "string", "const": "1.0.0" },
    "layout": { "type": "string", "enum": ["auto", "manual"], "description": "The viewer computes an automatic layout by default. Set manual only to preserve explicit node positions." },
    "metadata": {
      "type": "object",
      "required": ["name"],
      "properties": {
        "name": { "type": "string" },
        "description": { "type": "string" },
        "source": { "type": "string", "description": "For example, APK filename or analysis source." },
        "generatedAt": { "type": "string", "format": "date-time" }
      },
      "additionalProperties": true
    },
    "nodes": { "type": "array", "items": { "$ref": "#/$defs/node" } },
    "boundaries": { "type": "array", "items": { "$ref": "#/$defs/boundary" } },
    "edges": { "type": "array", "items": { "$ref": "#/$defs/edge" } },
    "threats": { "type": "array", "items": { "$ref": "#/$defs/threat" } }
  },
  "$defs": {
    "evidence": {
      "type": "object",
      "required": ["source", "detail"],
      "properties": {
        "source": { "type": "string" },
        "detail": { "type": "string" },
        "location": { "type": "string" },
        "uri": { "type": "string", "format": "uri-reference" }
      },
      "additionalProperties": true
    },
    "position": {
      "type": "object",
      "description": "Optional layout hint. The viewer ignores it when layout is auto.",
      "properties": {
        "x": { "type": "number" }, "y": { "type": "number" },
        "width": { "type": "number", "exclusiveMinimum": 0 },
        "height": { "type": "number", "exclusiveMinimum": 0 }
      },
      "additionalProperties": true
    },
    "node": {
      "type": "object",
      "required": ["id", "type", "label"],
      "properties": {
        "id": { "type": "string" },
        "type": { "type": "string", "description": "Examples: external-actor, mobile-app, activity, webview, service, data-store, secure-storage, library." },
        "label": { "type": "string" },
        "subtitle": { "type": "string" },
        "description": { "type": "string" },
        "source": { "type": "string" },
        "confidence": { "type": "string", "enum": ["high", "medium", "low", "unknown"] },
        "evidence": { "type": "array", "items": { "$ref": "#/$defs/evidence" } },
        "position": { "$ref": "#/$defs/position" }
      },
      "additionalProperties": true
    },
    "boundary": {
      "type": "object",
      "required": ["id", "label"],
      "properties": {
        "id": { "type": "string" }, "label": { "type": "string" },
        "description": { "type": "string" },
        "contains": { "type": "array", "items": { "type": "string" } },
        "position": { "$ref": "#/$defs/position" }
      },
      "additionalProperties": true
    },
    "edge": {
      "type": "object",
      "required": ["id", "source", "target"],
      "properties": {
        "id": { "type": "string" }, "source": { "type": "string" },
        "target": { "type": "string" }, "label": { "type": "string" },
        "kind": { "type": "string" },
        "confidence": { "type": "string", "enum": ["high", "medium", "low", "unknown"] },
        "evidence": { "type": "array", "items": { "$ref": "#/$defs/evidence" } }
      },
      "additionalProperties": true
    },
    "threat": {
      "type": "object",
      "required": ["id", "title"],
      "properties": {
        "id": { "type": "string" }, "title": { "type": "string" },
        "severity": { "type": "string", "enum": ["critical", "high", "medium", "low", "info"] },
        "stride": { "type": "string" }, "status": { "type": "string" },
        "description": { "type": "string" },
        "nodeIds": { "type": "array", "items": { "type": "string" } },
        "edgeIds": { "type": "array", "items": { "type": "string" } },
        "confidence": { "type": "string", "enum": ["high", "medium", "low", "unknown"] },
        "evidence": { "type": "array", "items": { "$ref": "#/$defs/evidence" } },
        "suggestions": { "type": "array", "items": { "type": "object", "required": ["title"], "properties": { "title": { "type": "string" }, "detail": { "type": "string" } }, "additionalProperties": true } }
      },
      "additionalProperties": true
    }
  },
  "additionalProperties": true
}
