{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://developer.reits.tech/schemas/repository-manifest.v1.schema.json",
  "title": "REITs Tech Repository Manifest v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "id",
    "name",
    "organization",
    "workspacePath",
    "ownership",
    "source",
    "lifecycle",
    "runtime",
    "surfaces",
    "contracts",
    "tests",
    "slo",
    "idempotencyKey"
  ],
  "properties": {
    "schemaVersion": {
      "const": "repository.manifest/v1"
    },
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9-]*$"
    },
    "name": {
      "type": "string",
      "minLength": 1
    },
    "organization": {
      "enum": [
        "reits",
        "jx-im",
        "local"
      ]
    },
    "workspacePath": {
      "type": "string",
      "pattern": "^(?!/)(?!.*\\.\\.).+$"
    },
    "ownership": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "accountable",
        "workstream"
      ],
      "properties": {
        "accountable": {
          "type": "string",
          "minLength": 1
        },
        "workstream": {
          "type": "string",
          "pattern": "^W[0-7]$"
        }
      }
    },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "remote",
        "defaultBranch",
        "observedRevision",
        "posture",
        "verifiedAt"
      ],
      "properties": {
        "remote": {
          "type": [
            "string",
            "null"
          ],
          "format": "uri"
        },
        "defaultBranch": {
          "type": "string",
          "minLength": 1
        },
        "observedRevision": {
          "type": "string",
          "pattern": "^(?:[0-9a-f]{40}|local-worktree)$"
        },
        "posture": {
          "enum": [
            "exact-default",
            "divergent-worktree",
            "local-only"
          ]
        },
        "verifiedAt": {
          "type": "string",
          "format": "date-time"
        },
        "localObservation": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "branch",
            "revision",
            "ahead",
            "behind"
          ],
          "properties": {
            "branch": {
              "type": "string"
            },
            "revision": {
              "type": "string",
              "pattern": "^[0-9a-f]{40}$"
            },
            "ahead": {
              "type": "integer",
              "minimum": 0
            },
            "behind": {
              "type": "integer",
              "minimum": 0
            }
          }
        }
      }
    },
    "lifecycle": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "class",
        "status",
        "decision"
      ],
      "properties": {
        "class": {
          "enum": [
            "product",
            "platform",
            "shared-package",
            "prototype",
            "reference",
            "documentation",
            "developer-portal"
          ]
        },
        "status": {
          "enum": [
            "active",
            "candidate",
            "frozen",
            "reference-only",
            "local-active"
          ]
        },
        "decision": {
          "type": "string",
          "minLength": 1
        },
        "successor": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "uniqueItems": true
        }
      }
    },
    "runtime": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "kind",
        "production",
        "entrypoints"
      ],
      "properties": {
        "kind": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "minItems": 1,
          "uniqueItems": true
        },
        "production": {
          "enum": [
            "deployed",
            "hosted",
            "candidate-not-deployed",
            "source-only",
            "release-unverified"
          ]
        },
        "entrypoints": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "uniqueItems": true
        }
      }
    },
    "surfaces": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "kind",
          "name"
        ],
        "properties": {
          "kind": {
            "enum": [
              "web",
              "admin",
              "api",
              "native",
              "sdk",
              "worker",
              "docs",
              "library",
              "service"
            ]
          },
          "name": {
            "type": "string",
            "minLength": 1
          }
        }
      },
      "minItems": 1
    },
    "contracts": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "name",
          "role",
          "version"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1
          },
          "role": {
            "enum": [
              "producer",
              "consumer",
              "both",
              "reference"
            ]
          },
          "version": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    "tests": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "commands",
        "workflowCount",
        "status"
      ],
      "properties": {
        "commands": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "uniqueItems": true
        },
        "workflowCount": {
          "type": "integer",
          "minimum": 0
        },
        "status": {
          "enum": [
            "present",
            "partial",
            "missing"
          ]
        }
      }
    },
    "slo": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "tier",
        "status",
        "objectives"
      ],
      "properties": {
        "tier": {
          "enum": [
            "tier-0",
            "tier-1",
            "tier-2",
            "not-applicable"
          ]
        },
        "status": {
          "enum": [
            "defined",
            "partial",
            "missing",
            "not-applicable"
          ]
        },
        "objectives": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "uniqueItems": true
        }
      }
    },
    "idempotencyKey": {
      "type": "string",
      "pattern": "^d01-repository-manifest-v1-[a-z0-9-]+$"
    }
  }
}

