{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://get-design-done.example/schemas/graph.schema.json",
  "title": ".design/graph/graph.json",
  "description": "Native gdd-graph store. Schema version 1.0 — frozen at Phase 30.6 per D-03.",
  "type": "object",
  "required": ["schemaVersion", "metadata", "nodes", "edges"],
  "additionalProperties": false,
  "properties": {
    "schemaVersion": {
      "type": "string",
      "const": "1.0",
      "description": "Pinned to 1.0 at ship; future migrations bump explicitly (D-03)."
    },
    "metadata": {
      "type": "object",
      "required": ["generatedAt", "nodeCount", "edgeCount"],
      "additionalProperties": true,
      "properties": {
        "generatedAt": { "type": "string", "description": "ISO 8601 timestamp" },
        "intelSource": { "type": "string", "description": "Path to source intel file, e.g. .design/intel/graph.json" },
        "nodeCount": { "type": "integer", "minimum": 0 },
        "edgeCount": { "type": "integer", "minimum": 0 },
        "builderVersion": { "type": "string", "description": "gdd-graph version that wrote this file" }
      }
    },
    "nodes": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["id", "type"],
        "additionalProperties": true,
        "properties": {
          "id":     { "type": "string", "minLength": 1, "description": "Stable globally-unique node ID" },
          "type":   { "type": "string", "description": "Node category (component, token, decision, etc.) — lenient enum per D-03" },
          "label":  { "type": "string", "description": "Human-readable display name" },
          "attrs":  { "type": "object", "additionalProperties": true, "description": "Free-form node attributes" },
          "source": {
            "oneOf": [
              { "type": "string", "description": "Source file path or origin marker" },
              { "type": "object", "additionalProperties": true, "description": "Structured source descriptor per D-03.a" }
            ]
          }
        }
      }
    },
    "edges": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["from", "to", "kind"],
        "additionalProperties": true,
        "properties": {
          "from":   { "type": "string", "minLength": 1, "description": "Source node id (matches a nodes[].id)" },
          "to":     { "type": "string", "minLength": 1, "description": "Target node id" },
          "kind":   { "type": "string", "description": "Edge type per D-03.b" },
          "weight": { "type": "number", "description": "Optional edge weight per D-03.c; used by query ranking + budget eviction" },
          "attrs":  { "type": "object", "additionalProperties": true },
          "source": {
            "oneOf": [
              { "type": "string" },
              { "type": "object", "additionalProperties": true }
            ]
          }
        }
      }
    }
  }
}
