{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:atlas:model:1",
  "title": "Atlas Model v1",
  "description": "Structural grammar. engine.mjs additionally validates semantic identity, references, column ownership, boundary cycles and view consistency.",
  "type": "object",
  "required": [
    "schemaVersion",
    "revision",
    "product",
    "entities",
    "relations",
    "views",
    "evidence",
    "requirements"
  ],
  "properties": {
    "schemaVersion": {
      "const": "atlas.model/1"
    },
    "revision": {
      "type": "integer",
      "minimum": 1
    },
    "product": {
      "type": "object",
      "required": [
        "id",
        "name",
        "defaultView"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9-]{0,63}$"
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "defaultView": {
          "$ref": "#/$defs/id"
        },
        "coverage": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "area",
              "state"
            ],
            "properties": {
              "area": {
                "type": "string",
                "minLength": 1
              },
              "state": {
                "enum": [
                  "covered",
                  "partial",
                  "not-applicable",
                  "uninspected"
                ]
              },
              "gap": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    "palette": {
      "type": "object",
      "additionalProperties": {
        "type": "string",
        "pattern": "^#[0-9a-fA-F]{6}$"
      }
    },
    "entities": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/entity"
      }
    },
    "relations": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/relation"
      }
    },
    "views": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/view"
      }
    },
    "evidence": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/evidence"
      }
    },
    "requirements": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/requirement"
      }
    }
  },
  "$defs": {
    "id": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9-]*:[a-zA-Z0-9._/:-]+$"
    },
    "refs": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/id"
      }
    },
    "record": {
      "type": "object",
      "required": [
        "id",
        "title"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "title": {
          "type": "string",
          "minLength": 1
        },
        "glyph": {
          "enum": [
            "agent-tool",
            "agent",
            "anchor",
            "api-contract",
            "api-gateway",
            "api-token",
            "audit-log",
            "backup",
            "batch-job",
            "cache",
            "cdn",
            "certificate",
            "cloud",
            "column",
            "commit",
            "consumer",
            "container-pod",
            "container",
            "data-warehouse",
            "database",
            "dead-letter-queue",
            "dns",
            "document-store",
            "edge-worker",
            "event-bus",
            "event-stream",
            "evidence",
            "external-system",
            "firewall",
            "fit-view",
            "foreign-key",
            "graph-database",
            "identity-provider",
            "index",
            "inspect",
            "key-value-store",
            "kubernetes-cluster",
            "layers",
            "load-balancer",
            "lock",
            "log",
            "mcp-server",
            "metric",
            "migration",
            "network",
            "object-storage",
            "organization",
            "physical-server",
            "primary-key",
            "private-host",
            "process",
            "producer",
            "queue",
            "relational-table",
            "relationship",
            "replica",
            "requirement",
            "retry",
            "reverse-proxy",
            "role",
            "scheduler",
            "search-index",
            "secret",
            "secure-tunnel",
            "serverless",
            "service",
            "share-link",
            "source-code",
            "source-file",
            "stateful-actor",
            "subnet",
            "subscription",
            "team",
            "test",
            "time-series-store",
            "topic",
            "trace",
            "unlock",
            "user",
            "vector-store",
            "version-diff",
            "virtual-machine",
            "volume",
            "webhook",
            "workflow",
            "workspace"
          ]
        },
        "color": {
          "type": "string",
          "pattern": "^#[0-9a-fA-F]{6}$"
        }
      }
    },
    "claim": {
      "allOf": [
        {
          "$ref": "#/$defs/record"
        }
      ],
      "required": [
        "status",
        "evidence"
      ],
      "properties": {
        "status": {
          "enum": [
            "source",
            "contract",
            "proposed",
            "unverified",
            "synthetic"
          ]
        },
        "evidence": {
          "$ref": "#/$defs/refs"
        }
      }
    },
    "column": {
      "type": "object",
      "required": [
        "id",
        "name",
        "type",
        "nullable",
        "pk"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "type": {
          "type": "string"
        },
        "nullable": {
          "type": "boolean"
        },
        "pk": {
          "type": "boolean"
        }
      }
    },
    "entity": {
      "allOf": [
        {
          "$ref": "#/$defs/claim"
        }
      ],
      "required": [
        "kind",
        "summary"
      ],
      "properties": {
        "kind": {
          "enum": [
            "component",
            "interface",
            "boundary",
            "table",
            "external",
            "actor",
            "store"
          ]
        },
        "summary": {
          "type": "string"
        },
        "boundary": {
          "$ref": "#/$defs/id"
        },
        "tables": {
          "$ref": "#/$defs/refs"
        },
        "columns": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/column"
          }
        },
        "externalRef": {
          "type": "object",
          "required": [
            "product",
            "entity",
            "scope"
          ],
          "properties": {
            "product": {
              "type": "string",
              "minLength": 1
            },
            "entity": {
              "type": "string",
              "minLength": 1
            },
            "scope": {
              "type": "string",
              "minLength": 1
            }
          }
        },
        "technology": {
          "type": "string",
          "minLength": 1
        },
        "hostedBy": {
          "$ref": "#/$defs/id"
        },
        "drillView": {
          "$ref": "#/$defs/id"
        }
      },
      "if": {
        "properties": {
          "kind": {
            "const": "table"
          }
        }
      },
      "then": {
        "required": [
          "columns"
        ],
        "properties": {
          "columns": {
            "minItems": 1
          }
        }
      }
    },
    "relation": {
      "allOf": [
        {
          "$ref": "#/$defs/claim"
        }
      ],
      "required": [
        "kind",
        "from",
        "to"
      ],
      "properties": {
        "kind": {
          "type": "string",
          "minLength": 1
        },
        "from": {
          "$ref": "#/$defs/id"
        },
        "to": {
          "$ref": "#/$defs/id"
        },
        "fromColumn": {
          "$ref": "#/$defs/id"
        },
        "toColumn": {
          "$ref": "#/$defs/id"
        },
        "protocol": {
          "type": "string",
          "minLength": 1
        },
        "mode": {
          "enum": [
            "sync",
            "async"
          ]
        }
      }
    },
    "view": {
      "allOf": [
        {
          "$ref": "#/$defs/claim"
        }
      ],
      "required": [
        "kind"
      ],
      "properties": {
        "kind": {
          "enum": [
            "map",
            "deployment",
            "flow",
            "sequence",
            "tables",
            "spec"
          ]
        },
        "entities": {
          "$ref": "#/$defs/refs"
        },
        "relations": {
          "$ref": "#/$defs/refs"
        },
        "requirements": {
          "$ref": "#/$defs/refs"
        },
        "messages": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "relation"
            ],
            "properties": {
              "relation": {
                "$ref": "#/$defs/id"
              },
              "note": {
                "type": "string"
              }
            }
          }
        },
        "steps": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "id",
              "entity",
              "title"
            ],
            "properties": {
              "id": {
                "$ref": "#/$defs/id"
              },
              "entity": {
                "$ref": "#/$defs/id"
              },
              "title": {
                "type": "string"
              },
              "tables": {
                "$ref": "#/$defs/refs"
              }
            }
          }
        },
        "transitions": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "from",
              "to"
            ],
            "properties": {
              "from": {
                "$ref": "#/$defs/id"
              },
              "to": {
                "$ref": "#/$defs/id"
              },
              "label": {
                "type": "string"
              }
            }
          }
        },
        "presentation": {
          "const": "technical"
        },
        "containers": {
          "$ref": "#/$defs/refs"
        },
        "gridColumns": {
          "type": "integer",
          "minimum": 1,
          "maximum": 24
        },
        "inventory": {
          "type": "boolean"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "kind": {
                "enum": [
                  "map",
                  "deployment",
                  "tables",
                  "sequence"
                ]
              }
            }
          },
          "then": {
            "required": [
              "entities",
              "relations"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "spec"
              }
            }
          },
          "then": {
            "required": [
              "requirements"
            ]
          }
        }
      ]
    },
    "evidence": {
      "allOf": [
        {
          "$ref": "#/$defs/record"
        }
      ],
      "required": [
        "kind",
        "locator",
        "scope"
      ],
      "properties": {
        "kind": {
          "enum": [
            "source",
            "requirement",
            "observation",
            "inference",
            "synthetic"
          ]
        },
        "locator": {
          "type": "string",
          "minLength": 1
        },
        "scope": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "requirement": {
      "allOf": [
        {
          "$ref": "#/$defs/claim"
        }
      ],
      "required": [
        "statement",
        "entities",
        "acceptance",
        "verification"
      ],
      "properties": {
        "statement": {
          "type": "string",
          "minLength": 1
        },
        "entities": {
          "$ref": "#/$defs/refs"
        },
        "acceptance": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "verification": {
          "enum": [
            "source-inspected",
            "local-tested",
            "reported-local",
            "not-verified",
            "synthetic"
          ]
        }
      }
    }
  }
}
