{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://standards.rootblocks.com/schemas/project/project.v1.schema.json",
  "title": "RootBlocks Project v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "projectId",
    "name",
    "standard",
    "profile",
    "runner",
    "artifacts",
    "environments",
    "policies"
  ],
  "properties": {
    "schemaVersion": {
      "const": "rootblocks.project/v1"
    },
    "projectId": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9.-]{2,127}$"
    },
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 160
    },
    "description": {
      "type": "string",
      "maxLength": 1000
    },
    "standard": {
      "$ref": "#/$defs/standardRef"
    },
    "profile": {
      "type": "object",
      "additionalProperties": false,
      "required": ["language", "architecture"],
      "properties": {
        "language": {
          "enum": ["dotnet", "node", "python", "java", "go", "custom"]
        },
        "framework": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9.+-]{1,80}$"
        },
        "architecture": {
          "enum": ["mvc", "clean-architecture", "ddd", "vertical-slice", "hexagonal", "layered", "ddd-clean", "component-pack", "custom"]
        },
        "templateRef": {
          "$ref": "#/$defs/artifactRef"
        },
        "architectureProfile": {
          "$ref": "#/$defs/architectureProfileRef"
        }
      }
    },
    "runner": {
      "type": "object",
      "additionalProperties": false,
      "required": ["engine", "target", "requiredCapabilities"],
      "properties": {
        "engine": {
          "const": "builderx"
        },
        "target": {
          "enum": ["api", "console", "worker", "adapter", "custom"]
        },
        "requiredCapabilities": {
          "type": "array",
          "items": {
            "enum": [
              "validate",
              "compile",
              "run",
              "debug",
              "trace",
              "evidence",
              "regression-run",
              "regression-debug",
              "infra-orchestration",
              "cicd-orchestration"
            ]
          },
          "uniqueItems": true
        }
      }
    },
    "artifacts": {
      "type": "object",
      "additionalProperties": false,
      "required": ["workflows"],
      "properties": {
        "workflows": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/workflowRef"
          }
        },
        "regressionSuites": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/artifactRef"
          }
        },
        "sourceMaps": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/artifactRef"
          }
        },
        "evidencePolicy": {
          "$ref": "#/$defs/artifactRef"
        }
      }
    },
    "environments": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/environment"
      }
    },
    "policies": {
      "type": "object",
      "additionalProperties": false,
      "required": ["validationMode", "secretPolicy", "evidenceRequired"],
      "properties": {
        "validationMode": {
          "enum": ["advisory", "enforced"]
        },
        "secretPolicy": {
          "enum": ["references-only"]
        },
        "evidenceRequired": {
          "type": "boolean"
        },
        "criticalRegressionGate": {
          "enum": ["block-on-failed", "block-on-failed-or-inconclusive"]
        }
      }
    }
  },
  "$defs": {
    "standardRef": {
      "type": "object",
      "additionalProperties": false,
      "required": ["bundleId", "version", "hash"],
      "properties": {
        "bundleId": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9.-]{2,127}$"
        },
        "version": {
          "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}$"
        }
      }
    },
    "artifactRef": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "path"],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9.-]{2,127}$"
        },
        "path": {
          "type": "string",
          "pattern": "^(docs|builderx|src|tests|templates|components)/.+$"
        },
        "hash": {
          "type": "string",
          "pattern": "^[a-f0-9]{64,128}$"
        }
      }
    },
    "architectureProfileRef": {
      "type": "object",
      "additionalProperties": false,
      "required": ["profileId", "version", "path", "hash"],
      "properties": {
        "profileId": {
          "enum": ["ddd-clean", "component-pack", "custom"]
        },
        "version": {
          "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.-]+)?$"
        },
        "path": {
          "type": "string",
          "pattern": "^profiles/architecture/.+\\.json$"
        },
        "hash": {
          "type": "string",
          "pattern": "^[a-f0-9]{64,128}$"
        }
      }
    },
    "workflowRef": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "type", "path"],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9.-]{2,127}$"
        },
        "type": {
          "enum": ["application", "software-process", "infrastructure", "cicd", "test", "regression-support"]
        },
        "path": {
          "type": "string",
          "pattern": "^builderx/flows/.+\\.(yaml|yml|json)$"
        },
        "critical": {
          "type": "boolean",
          "default": false
        }
      }
    },
    "environment": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "profile", "secretRefs"],
      "properties": {
        "name": {
          "enum": ["dev", "qa", "prod"]
        },
        "profile": {
          "enum": ["development", "quality-assurance", "production"]
        },
        "secretRefs": {
          "type": "array",
          "items": {
            "$ref": "../security/secret-reference.v1.schema.json"
          }
        }
      }
    }
  }
}

