{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://agentdirective.org/schemas/architecture-model-v1.schema.json",
  "title": "AgentDirective Architecture Model v1",
  "type": "object",
  "additionalProperties": false,
  "required": ["model_version", "project", "characteristics", "actors", "data", "components", "dependencies", "actions", "trust_boundaries", "assumptions", "unknowns"],
  "properties": {
    "$schema": { "type": "string", "format": "uri-reference" },
    "model_id": { "type": "string", "pattern": "^AM-[A-Z0-9]{6,32}$" },
    "model_version": { "$ref": "#/$defs/semver" },
    "methodology_version": { "$ref": "#/$defs/semver" },
    "created_at": { "type": "string", "format": "date-time" },
    "project": {
      "type": "object",
      "additionalProperties": false,
      "required": ["objective"],
      "properties": {
        "name": { "type": "string", "minLength": 1, "maxLength": 200 },
        "objective": { "type": "string", "minLength": 1, "maxLength": 10000 },
        "original_input_digest": { "type": "string", "pattern": "^sha256:[a-f0-9]{64}$" },
        "audience_context": { "type": "string", "enum": ["developer_engineering", "founder_startup", "product_design", "operations_business", "security_compliance", "research_education", "student_learner", "public_interest_nonprofit", "other"] }
      }
    },
    "characteristics": { "type": "array", "uniqueItems": true, "items": { "$ref": "#/$defs/characteristic" } },
    "actors": { "type": "array", "items": { "$ref": "#/$defs/entity" } },
    "data": { "type": "array", "items": { "$ref": "#/$defs/dataItem" } },
    "components": { "type": "array", "items": { "$ref": "#/$defs/entity" } },
    "dependencies": { "type": "array", "items": { "$ref": "#/$defs/dependency" } },
    "actions": { "type": "array", "items": { "$ref": "#/$defs/action" } },
    "trust_boundaries": { "type": "array", "items": { "$ref": "#/$defs/trustBoundary" } },
    "human_decision_points": { "type": "array", "items": { "$ref": "#/$defs/decisionPoint" } },
    "recovery_requirements": { "type": "array", "items": { "$ref": "#/$defs/statement" } },
    "monitoring_requirements": { "type": "array", "items": { "$ref": "#/$defs/statement" } },
    "assumptions": { "type": "array", "items": { "$ref": "#/$defs/statement" } },
    "unknowns": { "type": "array", "items": { "$ref": "#/$defs/unknown" } },
    "user_confirmed": { "type": "boolean", "default": false }
  },
  "$defs": {
    "semver": { "type": "string", "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?$" },
    "token": { "type": "string", "pattern": "^[A-Z][A-Z0-9_]{1,79}$" },
    "confidence": { "type": "number", "minimum": 0, "maximum": 1 },
    "provenance": { "enum": ["user_stated", "rule_inferred", "model_suggested", "user_corrected"] },
    "characteristic": {
      "type": "object", "additionalProperties": false, "required": ["id", "value", "provenance"],
      "properties": { "id": { "$ref": "#/$defs/token" }, "value": { "type": ["string", "number", "boolean", "null"] }, "confidence": { "$ref": "#/$defs/confidence" }, "provenance": { "$ref": "#/$defs/provenance" }, "reason": { "type": "string", "maxLength": 1000 } }
    },
    "entity": {
      "type": "object", "additionalProperties": false, "required": ["id", "type", "name"],
      "properties": { "id": { "type": "string", "pattern": "^[a-z][a-z0-9_-]{1,79}$" }, "type": { "$ref": "#/$defs/token" }, "name": { "type": "string", "minLength": 1, "maxLength": 200 }, "trust": { "enum": ["trusted", "partially_trusted", "untrusted", "unknown"] }, "provenance": { "$ref": "#/$defs/provenance" } }
    },
    "dataItem": {
      "type": "object", "additionalProperties": false, "required": ["id", "type", "sensitivity"],
      "properties": { "id": { "type": "string", "pattern": "^[a-z][a-z0-9_-]{1,79}$" }, "type": { "$ref": "#/$defs/token" }, "sensitivity": { "enum": ["public", "internal", "confidential", "restricted", "potentially_sensitive", "unknown"] }, "retention": { "type": ["string", "null"], "maxLength": 300 }, "residency": { "type": ["string", "null"], "maxLength": 120 }, "provenance": { "$ref": "#/$defs/provenance" } }
    },
    "dependency": {
      "type": "object", "additionalProperties": false, "required": ["id", "type", "name"],
      "properties": { "id": { "type": "string", "pattern": "^[a-z][a-z0-9_-]{1,79}$" }, "type": { "$ref": "#/$defs/token" }, "name": { "type": "string", "minLength": 1, "maxLength": 200 }, "external": { "type": "boolean" }, "failure_impact": { "enum": ["low", "moderate", "high", "critical", "unknown"] }, "provenance": { "$ref": "#/$defs/provenance" } }
    },
    "action": {
      "type": "object", "additionalProperties": false, "required": ["id", "name", "automation", "consequences", "reversibility"],
      "properties": { "id": { "type": "string", "pattern": "^[a-z][a-z0-9_-]{1,79}$" }, "name": { "type": "string", "minLength": 1, "maxLength": 200 }, "automation": { "enum": ["manual", "assisted", "autonomous", "unknown"] }, "consequences": { "type": "array", "uniqueItems": true, "items": { "enum": ["financial", "destructive", "privileged", "bulk", "external", "privacy", "safety", "cost", "other"] } }, "reversibility": { "enum": ["reversible", "partially_reversible", "irreversible", "unknown"] }, "human_approval": { "enum": ["required", "not_required", "conditional", "unknown"] }, "provenance": { "$ref": "#/$defs/provenance" } }
    },
    "trustBoundary": {
      "type": "object", "additionalProperties": false, "required": ["id", "from", "to"],
      "properties": { "id": { "type": "string", "pattern": "^[a-z][a-z0-9_-]{1,79}$" }, "from": { "type": "string", "minLength": 1 }, "to": { "type": "string", "minLength": 1 }, "description": { "type": "string", "maxLength": 1000 }, "provenance": { "$ref": "#/$defs/provenance" } }
    },
    "decisionPoint": {
      "type": "object", "additionalProperties": false, "required": ["id", "description", "status"],
      "properties": { "id": { "type": "string", "pattern": "^[a-z][a-z0-9_-]{1,79}$" }, "description": { "type": "string", "minLength": 1, "maxLength": 1000 }, "status": { "enum": ["confirmed", "recommended", "unresolved", "not_applicable", "explicitly_rejected"] }, "provenance": { "$ref": "#/$defs/provenance" } }
    },
    "statement": {
      "type": "object", "additionalProperties": false, "required": ["id", "text", "provenance"],
      "properties": { "id": { "type": "string", "pattern": "^[a-z][a-z0-9_-]{1,79}$" }, "text": { "type": "string", "minLength": 1, "maxLength": 2000 }, "provenance": { "$ref": "#/$defs/provenance" } }
    },
    "unknown": {
      "type": "object", "additionalProperties": false, "required": ["id", "description", "materiality"],
      "properties": { "id": { "type": "string", "pattern": "^[a-z][a-z0-9_-]{1,79}$" }, "description": { "type": "string", "minLength": 1, "maxLength": 1000 }, "materiality": { "enum": ["low", "moderate", "high", "critical"] }, "related_characteristics": { "type": "array", "uniqueItems": true, "items": { "$ref": "#/$defs/token" } } }
    }
  }
}
