{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "./.argo/schema/SystemArchitecture.schema.json",
  "title": "SystemArchitecture Knowledge Graph Schema",
  "description": "Schema for design/KG/SystemArchitecture.json. The repository keeps its existing knowledge-graph shape, while ArchiMate 3.2 terminology is enforced for element and relationship concepts.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "name",
    "description",
    "elements",
    "relationships",
    "views"
  ],
  "properties": {
    "name": {
      "type": "string",
      "minLength": 1
    },
    "description": {
      "type": "string",
      "minLength": 1
    },
    "attributes": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/attribute"
      }
    },
    "elements": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/element"
      }
    },
    "relationships": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/relationship"
      }
    },
    "views": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/view"
      }
    }
  },
  "$defs": {
    "identifier": {
      "type": "string",
      "minLength": 1,
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]*$"
    },
    "nonEmptyString": {
      "type": "string",
      "minLength": 1
    },
    "archimateElementType": {
      "type": "string",
      "enum": [
        "Resource",
        "Capability",
        "Value Stream",
        "Course of Action",
        "Business Actor",
        "Business Role",
        "Business Collaboration",
        "Business Interface",
        "Business Process",
        "Business Function",
        "Business Interaction",
        "Business Event",
        "Business Service",
        "Business Object",
        "Contract",
        "Representation",
        "Product",
        "Application Component",
        "Application Collaboration",
        "Application Interface",
        "Application Process",
        "Application Function",
        "Application Interaction",
        "Application Event",
        "Application Service",
        "Data Object",
        "Node",
        "Device",
        "System Software",
        "Technology Collaboration",
        "Technology Interface",
        "Path",
        "Communication Network",
        "Technology Process",
        "Technology Function",
        "Technology Interaction",
        "Technology Event",
        "Technology Service",
        "Artifact",
        "Equipment",
        "Facility",
        "Distribution Network",
        "Material",
        "Stakeholder",
        "Driver",
        "Assessment",
        "Goal",
        "Outcome",
        "Principle",
        "Requirement",
        "Constraint",
        "Meaning",
        "Value",
        "Work Package",
        "Deliverable",
        "Implementation Event",
        "Plateau",
        "Gap",
        "Grouping",
        "Location",
        "And Junction",
        "Or Junction",
        "Skill",
        "Rule"
      ]
    },
    "archimateRelationshipType": {
      "type": "string",
      "enum": [
        "Association",
        "Composition",
        "Aggregation",
        "Assignment",
        "Realization",
        "Serving",
        "Access",
        "Influence",
        "Triggering",
        "Flow",
        "Specialization"
      ]
    },
    "attribute": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name"
      ],
      "description": "Generic EA-style attribute container. Use this for architecture annotations such as verification_focus, external_scope, acceptance_outcomes, and design_risks instead of introducing dedicated top-level fields.",
      "properties": {
        "name": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "description": {
          "type": "string"
        },
        "value": {
          "type": "string"
        },
        "content": {
          "type": "string"
        }
      }
    },
    "subdiagramView": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "view_id",
        "view_name"
      ],
      "properties": {
        "view_id": {
          "$ref": "#/$defs/identifier"
        },
        "view_name": {
          "$ref": "#/$defs/nonEmptyString"
        }
      }
    },
    "testcase": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "description",
        "type",
        "Input",
        "acceptanceCriteria"
      ],
      "properties": {
        "name": {
          "$ref": "#/$defs/nonEmptyString",
          "description": "Stable testcase identifier. Use the testcase name itself as the long-lived identity; do not add a separate testcase id field."
        },
        "description": {
          "$ref": "#/$defs/nonEmptyString",
          "description": "Place the intent being verified here. Each testcase should normally be mounted under exactly one element rather than using extra verifies_elements or verifies_intents fields."
        },
        "type": {
          "type": "string",
          "enum": [
            "Acceptance Test"
          ]
        },
        "Input": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "acceptanceCriteria": {
          "$ref": "#/$defs/nonEmptyString",
          "description": "By the end of implementation design, this must be the concrete workspace-relative executable testcase entrypoint for the testcase, optionally including a pytest node id selector such as tests/test_x.py::test_y, rather than descriptive prose."
        },
        "TestResults": {
          "$ref": "#/$defs/nonEmptyString"
        }
      }
    },
    "element": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "name",
        "type"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/identifier"
        },
        "name": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "parent": {
          "$ref": "#/$defs/identifier"
        },
        "type": {
          "$ref": "#/$defs/archimateElementType"
        },
        "alias": {
          "type": "string"
        },
        "classifier": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "attributes": {
          "type": "array",
          "description": "Use attributes to store additional architecture intent metadata, including verification_focus, external_scope, acceptance_outcomes, and design_risks.",
          "items": {
            "$ref": "#/$defs/attribute"
          }
        },
        "subdiagram_views": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/subdiagramView"
          }
        },
        "testcases": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/testcase"
          }
        }
      }
    },
    "relationshipAttribute": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name"
      ],
      "properties": {
        "name": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "description": {
          "$ref": "#/$defs/nonEmptyString"
        }
      }
    },
    "relationship": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "statement",
        "name",
        "type",
        "source_id",
        "target_id",
        "source_name",
        "target_name"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/identifier"
        },
        "statement": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "name": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "type": {
          "$ref": "#/$defs/archimateRelationshipType"
        },
        "description": {
          "type": "string"
        },
        "document": {
          "type": "string"
        },
        "attributes": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/relationshipAttribute"
          }
        },
        "source_id": {
          "$ref": "#/$defs/identifier"
        },
        "target_id": {
          "$ref": "#/$defs/identifier"
        },
        "source_name": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "target_name": {
          "$ref": "#/$defs/nonEmptyString"
        }
      }
    },
    "view": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "view_id",
        "view_name"
      ],
      "properties": {
        "view_id": {
          "$ref": "#/$defs/identifier"
        },
        "view_name": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "parent_element_id": {
          "$ref": "#/$defs/identifier"
        },
        "parent_element_name": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "included_elements": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/identifier"
          }
        },
        "included_relationships": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/identifier"
          }
        }
      }
    }
  }
}
