{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://calm.finos.org/release/1.2/meta/core.json",
  "title": "Common Architecture Language Model (CALM) Vocab",
  "type": "object",
  "properties": {
    "nodes": {
      "type": "array",
      "items": {
        "$ref": "#/defs/node"
      }
    },
    "relationships": {
      "type": "array",
      "items": {
        "$ref": "#/defs/relationship"
      }
    },
    "metadata": {
      "$ref": "#/defs/metadata"
    },
    "controls": {
      "$ref": "control.json#/defs/controls"
    },
    "flows": {
      "type": "array",
      "items": {
        "$ref": "flow.json#/defs/flow"
      }
    },
    "adrs": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "External links to ADRs (Architecture Decision Records) or similar documents that provide context or decisions related to the architecture. These can be URLs or references to internal documentation."
    },
    "additionalProperties": false
  },
  "defs": {
    "node": {
      "type": "object",
      "properties": {
        "unique-id": {
          "type": "string"
        },
        "node-type": {
          "$ref": "#/defs/node-type-definition"
        },
        "name": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "details": {
          "type": "object",
          "properties": {
            "detailed-architecture": {
              "type": "string"
            },
            "required-pattern": {
              "type": "string"
            }
          },
          "additionalProperties": false
        },
        "interfaces": {
          "type": "array",
          "items": {
            "anyOf": [
              {
                "$ref": "interface.json#/defs/interface-definition"
              },
              {
                "$ref": "interface.json#/defs/interface-type"
              }
            ]
          }
        },
        "controls": {
          "$ref": "control.json#/defs/controls"
        },
        "metadata": {
          "$ref": "#/defs/metadata"
        }
      },
      "required": [
        "unique-id",
        "node-type",
        "name",
        "description"
      ],
      "additionalProperties": true
    },
    "relationship": {
      "type": "object",
      "properties": {
        "unique-id": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "relationship-type": {
          "type": "object",
          "properties": {
            "interacts": {
              "$ref": "#/defs/interacts-type"
            },
            "connects": {
              "$ref": "#/defs/connects-type"
            },
            "deployed-in": {
              "$ref": "#/defs/deployed-in-type"
            },
            "composed-of": {
              "$ref": "#/defs/composed-of-type"
            },
            "options": {
              "$ref": "#/defs/option-type"
            }
          },
          "oneOf": [
            {
              "required": [
                "deployed-in"
              ]
            },
            {
              "required": [
                "composed-of"
              ]
            },
            {
              "required": [
                "interacts"
              ]
            },
            {
              "required": [
                "connects"
              ]
            },
            {
              "required": [
                "options"
              ]
            }
          ]
        },
        "protocol": {
          "$ref": "#/defs/protocol"
        },
        "metadata": {
          "$ref": "#/defs/metadata"
        },
        "controls": {
          "$ref": "control.json#/defs/controls"
        }
      },
      "required": [
        "unique-id",
        "relationship-type"
      ],
      "additionalProperties": true
    },
    "protocol": {
      "enum": [
        "HTTP",
        "HTTPS",
        "FTP",
        "SFTP",
        "JDBC",
        "WebSocket",
        "SocketIO",
        "LDAP",
        "AMQP",
        "TLS",
        "mTLS",
        "TCP"
      ]
    },
    "node-type-definition": {
      "anyOf": [
        {
          "enum": [
            "actor",
            "ecosystem",
            "system",
            "service",
            "database",
            "network",
            "ldap",
            "webclient",
            "data-asset"
          ]
        },
        {
          "type": "string"
        }
      ]
    },
    "interacts-type": {
      "type": "object",
      "properties": {
        "actor": {
          "type": "string"
        },
        "nodes": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "actor",
        "nodes"
      ]
    },
    "connects-type": {
      "type": "object",
      "properties": {
        "source": {
          "$ref": "interface.json#/defs/node-interface"
        },
        "destination": {
          "$ref": "interface.json#/defs/node-interface"
        }
      },
      "required": [
        "source",
        "destination"
      ]
    },
    "deployed-in-type": {
      "type": "object",
      "properties": {
        "container": {
          "type": "string"
        },
        "nodes": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "container",
        "nodes"
      ]
    },
    "composed-of-type": {
      "type": "object",
      "properties": {
        "container": {
          "type": "string"
        },
        "nodes": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "container",
        "nodes"
      ]
    },
    "option-type": {
      "type": "array",
      "items": {
        "$ref": "#/defs/decision"
      }
    },
    "decision": {
      "type": "object",
      "properties": {
        "description": {
          "type": "string"
        },
        "nodes": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "relationships": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "controls": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "description",
        "nodes",
        "relationships"
      ]
    },
    "metadata": {
      "oneOf": [
        {
          "type": "array",
          "items": {
            "type": "object"
          }
        },
        {
          "type": "object",
          "additionalProperties": true
        }
      ]
    }
  }
}