{
  "type": "object",
  "properties": {
    "apiVersion": {
      "const": "cloud.example/v1alpha1"
    },
    "kind": {
      "const": "Application"
    },
    "metadata": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9-]{0,62}$"
        },
        "project": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9-]{0,62}$"
        },
        "environment": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9-]{0,62}$"
        }
      },
      "required": [
        "name",
        "project",
        "environment"
      ],
      "additionalProperties": false
    },
    "spec": {
      "type": "object",
      "properties": {
        "source": {
          "type": "object",
          "properties": {
            "image": {
              "type": "string",
              "pattern": "@sha256:[a-f0-9]{64}$"
            }
          },
          "required": [
            "image"
          ],
          "additionalProperties": false
        },
        "placement": {
          "type": "object",
          "properties": {
            "nodePool": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9-]{0,62}$"
            },
            "allowedRegions": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1
              },
              "minItems": 1
            },
            "preferredDataLocality": {
              "type": "boolean"
            }
          },
          "required": [
            "nodePool"
          ],
          "additionalProperties": false
        },
        "processes": {
          "type": "object",
          "minProperties": 1,
          "propertyNames": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9-]{0,62}$"
          },
          "additionalProperties": {
            "type": "object",
            "properties": {
              "command": {
                "type": "array",
                "items": {
                  "type": "string",
                  "minLength": 1
                },
                "minItems": 1
              },
              "port": {
                "type": "integer",
                "minimum": 1,
                "maximum": 65535
              },
              "resources": {
                "type": "object",
                "properties": {
                  "cpuMillis": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "memoryMiB": {
                    "type": "integer",
                    "minimum": 1
                  }
                },
                "required": [
                  "cpuMillis",
                  "memoryMiB"
                ],
                "additionalProperties": false
              }
            },
            "required": [
              "command",
              "resources"
            ],
            "additionalProperties": false
          }
        },
        "domains": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "host": {
                "type": "string",
                "minLength": 1
              },
              "process": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9-]{0,62}$"
              },
              "tls": {
                "type": "boolean"
              }
            },
            "required": [
              "host",
              "process",
              "tls"
            ],
            "additionalProperties": false
          },
          "minItems": 0
        },
        "dependencies": {
          "type": "object",
          "propertyNames": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9-]{0,62}$"
          },
          "additionalProperties": {
            "type": "object",
            "properties": {
              "kind": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9-]{0,62}$"
              },
              "plan": {
                "enum": [
                  "shared",
                  "dedicated",
                  "external"
                ]
              },
              "config": {
                "type": "object",
                "description": "Validated against provider-specific schema; no embedded secrets allowed."
              },
              "bindings": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "process": {
                      "type": "string",
                      "pattern": "^[a-z][a-z0-9-]{0,62}$"
                    },
                    "env": {
                      "type": "string",
                      "pattern": "^[A-Z_][A-Z0-9_]*$"
                    },
                    "credential": {
                      "type": "string",
                      "minLength": 1
                    }
                  },
                  "required": [
                    "process",
                    "env",
                    "credential"
                  ],
                  "additionalProperties": false
                },
                "minItems": 1
              }
            },
            "required": [
              "kind",
              "plan",
              "config",
              "bindings"
            ],
            "additionalProperties": false
          }
        },
        "operations": {
          "type": "object",
          "properties": {
            "probes": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "pattern": "^[a-z][a-z0-9-]{0,62}$"
                  },
                  "process": {
                    "type": "string",
                    "pattern": "^[a-z][a-z0-9-]{0,62}$"
                  },
                  "path": {
                    "type": "string",
                    "pattern": "^/"
                  },
                  "checkRef": {
                    "type": "string",
                    "minLength": 1
                  },
                  "intervalSeconds": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "freshnessSeconds": {
                    "type": "integer",
                    "minimum": 1
                  }
                },
                "required": [
                  "name",
                  "process",
                  "intervalSeconds",
                  "freshnessSeconds"
                ],
                "additionalProperties": false,
                "oneOf": [
                  {
                    "required": [
                      "path"
                    ]
                  },
                  {
                    "required": [
                      "checkRef"
                    ]
                  }
                ]
              },
              "minItems": 1
            },
            "recovery": {
              "type": "object",
              "properties": {
                "required": {
                  "type": "boolean"
                },
                "backupPolicyRef": {
                  "type": "string",
                  "minLength": 1
                },
                "restorePolicyRef": {
                  "type": "string",
                  "minLength": 1
                },
                "requireVerifiedBeforeDataChange": {
                  "type": "boolean"
                }
              },
              "required": [
                "required",
                "backupPolicyRef",
                "restorePolicyRef",
                "requireVerifiedBeforeDataChange"
              ],
              "additionalProperties": false
            },
            "rollback": {
              "type": "object",
              "properties": {
                "autoStateless": {
                  "type": "boolean"
                }
              },
              "required": [
                "autoStateless"
              ],
              "additionalProperties": false
            },
            "agentPolicyRef": {
              "type": "string",
              "minLength": 1
            }
          },
          "required": [
            "probes",
            "recovery",
            "rollback",
            "agentPolicyRef"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "source",
        "processes",
        "dependencies",
        "operations"
      ],
      "additionalProperties": false
    }
  },
  "required": [
    "apiVersion",
    "kind",
    "metadata",
    "spec"
  ],
  "additionalProperties": false,
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Proposed Application manifest",
  "description": "Structural validation only; server validates scopes, references, provider configs, secrets, placement, generation and policy."
}
