{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://standards.rootblocks.com/schemas/templates/template.v1.schema.json",
  "title": "RootBlocks Template v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "templateId",
    "version",
    "type",
    "profile",
    "parameters",
    "files",
    "customizationZones",
    "compatibility"
  ],
  "properties": {
    "schemaVersion": {
      "const": "rootblocks.template/v1"
    },
    "templateId": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9.-]{2,127}$"
    },
    "version": {
      "$ref": "#/$defs/semver"
    },
    "type": {
      "enum": ["software", "infrastructure", "cicd", "workflow", "component"]
    },
    "profile": {
      "type": "object",
      "additionalProperties": false,
      "required": ["language", "architecture"],
      "properties": {
        "language": {
          "enum": ["dotnet", "node", "python", "java", "go", "terraform", "opentofu", "bicep", "pulumi", "yaml", "custom"]
        },
        "framework": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9.+-]{1,80}$"
        },
        "architecture": {
          "enum": ["mvc", "clean-architecture", "ddd", "vertical-slice", "hexagonal", "layered", "iac-module", "pipeline", "custom"]
        }
      }
    },
    "parameters": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/parameter"
      }
    },
    "files": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/fileEntry"
      }
    },
    "customizationZones": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/customizationZone"
      }
    },
    "compatibility": {
      "type": "object",
      "additionalProperties": false,
      "required": ["minimumStandardVersion"],
      "properties": {
        "minimumStandardVersion": {
          "$ref": "#/$defs/semver"
        },
        "supportedProjectSchemaVersions": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^rootblocks\\.project/v[0-9]+$"
          }
        }
      }
    }
  },
  "$defs": {
    "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.-]+)?$"
    },
    "parameter": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "type", "required"],
      "properties": {
        "name": {
          "type": "string",
          "pattern": "^[a-zA-Z_][a-zA-Z0-9_.-]{0,80}$"
        },
        "type": {
          "enum": ["string", "number", "integer", "boolean", "choice", "secret-ref"]
        },
        "required": {
          "type": "boolean"
        },
        "allowedValues": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "fileEntry": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path", "mode"],
      "properties": {
        "path": {
          "type": "string",
          "pattern": "^(src|tests|docs|builderx|infra|\\.github|azure-pipelines|templates)/.+$"
        },
        "mode": {
          "enum": ["generated", "protected", "editable", "extension-point"]
        },
        "hash": {
          "type": "string",
          "pattern": "^[a-f0-9]{64,128}$"
        }
      }
    },
    "customizationZone": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "path", "mode"],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9.-]{2,127}$"
        },
        "path": {
          "type": "string",
          "minLength": 1
        },
        "mode": {
          "enum": ["editable", "extension-only", "protected"]
        },
        "description": {
          "type": "string",
          "maxLength": 500
        }
      }
    }
  }
}

