{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://standards.rootblocks.com/schemas/domains/business-domain-registry.v1.schema.json",
  "title": "RootBlocks Business Domain Registry v1",
  "type": "object",
  "additionalProperties": false,
  "required": ["schemaVersion", "registryId", "standard", "version", "domains", "boundedContexts", "workflows", "dependencies", "evidence"],
  "properties": {
    "schemaVersion": {
      "const": "rootblocks.business-domain-registry/v1"
    },
    "registryId": {
      "$ref": "#/$defs/id"
    },
    "standard": {
      "$ref": "#/$defs/standardRef"
    },
    "version": {
      "$ref": "#/$defs/semver"
    },
    "domains": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/domain"
      }
    },
    "boundedContexts": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/boundedContext"
      }
    },
    "workflows": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/workflow"
      }
    },
    "components": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/componentRef"
      }
    },
    "dataResources": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/resourceRef"
      }
    },
    "dependencies": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/dependency"
      }
    },
    "evidence": {
      "$ref": "#/$defs/evidencePolicy"
    }
  },
  "$defs": {
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9.-]{2,127}$"
    },
    "semver": {
      "type": "string",
      "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(-[A-Za-z0-9.-]+)?(\\+[A-Za-z0-9.-]+)?$"
    },
    "hash": {
      "type": "string",
      "pattern": "^[a-f0-9]{64,128}$"
    },
    "path": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_./@-]+$"
    },
    "standardRef": {
      "type": "object",
      "additionalProperties": false,
      "required": ["bundleId", "version", "hash"],
      "properties": {
        "bundleId": {
          "$ref": "#/$defs/id"
        },
        "version": {
          "$ref": "#/$defs/semver"
        },
        "hash": {
          "$ref": "#/$defs/hash"
        }
      }
    },
    "owner": {
      "type": "object",
      "additionalProperties": false,
      "required": ["teamId", "contactRef"],
      "properties": {
        "teamId": {
          "$ref": "#/$defs/id"
        },
        "contactRef": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160
        }
      }
    },
    "slo": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "target", "window"],
      "properties": {
        "name": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9._-]{2,160}$"
        },
        "target": {
          "type": "number",
          "minimum": 0
        },
        "unit": {
          "enum": ["ms", "percent", "count", "ratio", "custom"]
        },
        "window": {
          "type": "string",
          "pattern": "^[0-9]+[mhd]$"
        }
      }
    },
    "domain": {
      "type": "object",
      "additionalProperties": false,
      "required": ["domainId", "displayName", "owner", "criticality", "lifecycle", "allowedTechnologies", "disallowedTechnologies"],
      "properties": {
        "domainId": {
          "$ref": "#/$defs/id"
        },
        "displayName": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160
        },
        "owner": {
          "$ref": "#/$defs/owner"
        },
        "criticality": {
          "enum": ["low", "medium", "high", "critical"]
        },
        "lifecycle": {
          "enum": ["planned", "active", "deprecated", "retired"]
        },
        "slos": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/slo"
          }
        },
        "dataClassifications": {
          "type": "array",
          "items": {
            "enum": ["public", "internal", "restricted", "sensitive"]
          },
          "uniqueItems": true
        },
        "allowedTechnologies": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/id"
          },
          "uniqueItems": true
        },
        "disallowedTechnologies": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/id"
          },
          "uniqueItems": true
        }
      }
    },
    "boundedContext": {
      "type": "object",
      "additionalProperties": false,
      "required": ["boundedContextId", "domainId", "owner", "responsibilities"],
      "properties": {
        "boundedContextId": {
          "$ref": "#/$defs/id"
        },
        "domainId": {
          "$ref": "#/$defs/id"
        },
        "owner": {
          "$ref": "#/$defs/owner"
        },
        "responsibilities": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          }
        }
      }
    },
    "workflow": {
      "type": "object",
      "additionalProperties": false,
      "required": ["workflowId", "domainId", "boundedContextId", "criticality", "owner", "sloRefs"],
      "properties": {
        "workflowId": {
          "$ref": "#/$defs/id"
        },
        "domainId": {
          "$ref": "#/$defs/id"
        },
        "boundedContextId": {
          "$ref": "#/$defs/id"
        },
        "criticality": {
          "enum": ["low", "medium", "high", "critical"]
        },
        "owner": {
          "$ref": "#/$defs/owner"
        },
        "sloRefs": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9._-]{2,160}$"
          }
        }
      }
    },
    "componentRef": {
      "type": "object",
      "additionalProperties": false,
      "required": ["componentId", "domainId", "boundedContextId", "technology"],
      "properties": {
        "componentId": {
          "$ref": "#/$defs/id"
        },
        "domainId": {
          "$ref": "#/$defs/id"
        },
        "boundedContextId": {
          "$ref": "#/$defs/id"
        },
        "technology": {
          "$ref": "#/$defs/id"
        }
      }
    },
    "resourceRef": {
      "type": "object",
      "additionalProperties": false,
      "required": ["resourceId", "domainId", "boundedContextId"],
      "properties": {
        "resourceId": {
          "$ref": "#/$defs/id"
        },
        "domainId": {
          "$ref": "#/$defs/id"
        },
        "boundedContextId": {
          "$ref": "#/$defs/id"
        }
      }
    },
    "dependency": {
      "type": "object",
      "additionalProperties": false,
      "required": ["from", "to", "type", "coupling"],
      "properties": {
        "from": {
          "$ref": "#/$defs/id"
        },
        "to": {
          "$ref": "#/$defs/id"
        },
        "type": {
          "enum": ["runtime", "deployment", "data", "ownership", "workflow", "external-integration"]
        },
        "coupling": {
          "enum": ["low", "medium", "high"]
        }
      }
    },
    "evidencePolicy": {
      "type": "object",
      "additionalProperties": false,
      "required": ["required", "evidenceRefs"],
      "properties": {
        "required": {
          "const": true
        },
        "evidenceRefs": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/path"
          }
        }
      }
    }
  }
}
