{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://openspec.tech/schema/v1.1/openspec-schema.json",
  "title": "OpenSpec Format",
  "description": "Open standard for AI agent orchestration specifications. Version 1.1.",
  "allOf": [
    {
      "$ref": "#/definitions/OpenSpec"
    }
  ],
  "definitions": {
    "OpenSpec": {
      "type": "object",
      "properties": {
        "schemaVersion": {
          "type": "string",
          "const": "1.1"
        },
        "id": {
          "type": "string"
        },
        "projectId": {
          "type": "string"
        },
        "title": {
          "type": "string",
          "minLength": 1
        },
        "description": {
          "type": "string"
        },
        "status": {
          "type": "string"
        },
        "goals": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "title": {
                "type": "string",
                "minLength": 1
              },
              "description": {
                "type": "string",
                "minLength": 1
              },
              "type": {
                "type": "string",
                "enum": [
                  "business",
                  "technical",
                  "user",
                  "operational"
                ]
              },
              "successCriteria": {
                "type": "array",
                "items": {
                  "type": "string",
                  "minLength": 1
                },
                "minItems": 1
              },
              "kpi": {
                "type": "string"
              }
            },
            "required": [
              "id",
              "title",
              "description",
              "type",
              "successCriteria"
            ],
            "additionalProperties": false
          },
          "minItems": 3
        },
        "requirements": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "title": {
                "type": "string",
                "minLength": 1
              },
              "description": {
                "type": "string",
                "minLength": 1
              },
              "type": {
                "type": "string",
                "enum": [
                  "functional",
                  "business-rule",
                  "integration"
                ]
              },
              "source": {
                "type": "string"
              },
              "acceptanceCriteria": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "given": {
                      "type": "string"
                    },
                    "when": {
                      "type": "string"
                    },
                    "then": {
                      "type": "string"
                    },
                    "order": {
                      "type": "integer",
                      "minimum": 1
                    }
                  },
                  "required": [
                    "id",
                    "given",
                    "when",
                    "then",
                    "order"
                  ],
                  "additionalProperties": false
                },
                "minItems": 1
              },
              "dependsOn": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "constraints": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "required": [
              "id",
              "title",
              "description",
              "type",
              "acceptanceCriteria"
            ],
            "additionalProperties": false
          },
          "minItems": 3
        },
        "architecture": {
          "type": "string"
        },
        "scope": {
          "type": "object",
          "properties": {
            "inScope": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1
              },
              "minItems": 3
            },
            "outOfScope": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1
              },
              "minItems": 1
            },
            "assumptions": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "externalDependencies": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          "required": [
            "inScope",
            "outOfScope"
          ],
          "additionalProperties": false
        },
        "techStack": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string",
                "minLength": 1
              },
              "version": {
                "type": "string"
              },
              "layer": {
                "type": "string",
                "enum": [
                  "database",
                  "backend",
                  "frontend",
                  "infrastructure",
                  "devops",
                  "observability",
                  "auth",
                  "integration",
                  "testing"
                ]
              },
              "rationale": {
                "type": "string"
              },
              "alternativesConsidered": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "required": [
              "id",
              "name",
              "layer"
            ],
            "additionalProperties": false
          }
        },
        "folderStructures": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "scope": {
                "type": "string",
                "minLength": 1
              },
              "description": {
                "type": "string"
              },
              "content": {
                "type": "string",
                "minLength": 1
              }
            },
            "required": [
              "id",
              "scope",
              "content"
            ],
            "additionalProperties": false
          },
          "minItems": 1
        },
        "acceptanceCriteria": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/OpenSpec/properties/requirements/items/properties/acceptanceCriteria/items"
          }
        },
        "nonFunctionalRequirements": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "description": {
                "type": "string",
                "minLength": 1
              },
              "category": {
                "type": "string",
                "enum": [
                  "performance",
                  "security",
                  "scalability",
                  "reliability",
                  "availability",
                  "usability",
                  "maintainability",
                  "observability",
                  "compliance",
                  "accessibility"
                ]
              },
              "metric": {
                "type": "string",
                "minLength": 1
              },
              "target": {
                "type": "string",
                "minLength": 1
              },
              "measurementMethod": {
                "type": "string"
              }
            },
            "required": [
              "id",
              "description",
              "category",
              "metric",
              "target"
            ],
            "additionalProperties": false
          }
        },
        "sharedPatterns": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string",
                "minLength": 1
              },
              "description": {
                "type": "string",
                "minLength": 1
              },
              "codeStandards": {
                "type": "object",
                "properties": {
                  "errorHandling": {
                    "type": "string"
                  },
                  "naming": {
                    "type": "string"
                  },
                  "language": {
                    "type": "string"
                  }
                },
                "additionalProperties": {
                  "type": "string"
                }
              },
              "commonImports": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "returnTypes": {
                "type": "object",
                "additionalProperties": {
                  "type": "string"
                }
              },
              "additionalImports": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "commonFiles": {
                "type": "object",
                "additionalProperties": {
                  "type": "string"
                }
              }
            },
            "required": [
              "id",
              "name",
              "description"
            ],
            "additionalProperties": false
          }
        },
        "guardrails": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "description": {
                "type": "string",
                "minLength": 1
              },
              "category": {
                "type": "string",
                "enum": [
                  "technical",
                  "business",
                  "regulatory",
                  "ethical",
                  "operational"
                ]
              },
              "rationale": {
                "type": "string",
                "minLength": 1
              },
              "consequence": {
                "type": "string",
                "minLength": 1
              },
              "scope": {
                "type": "string",
                "enum": [
                  "spec",
                  "epic",
                  "ticket"
                ]
              }
            },
            "required": [
              "id",
              "description",
              "category",
              "rationale",
              "consequence"
            ],
            "additionalProperties": false
          }
        },
        "background": {
          "type": "string"
        },
        "epics": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "specificationId": {
                "type": "string"
              },
              "title": {
                "type": "string",
                "minLength": 1
              },
              "description": {
                "type": "string"
              },
              "objective": {
                "type": "string"
              },
              "order": {
                "type": "integer",
                "minimum": 0
              },
              "estimatedMinutes": {
                "type": "integer",
                "minimum": 0
              },
              "architecture": {
                "type": "string"
              },
              "scope": {
                "$ref": "#/definitions/OpenSpec/properties/scope"
              },
              "goals": {
                "type": "array",
                "items": {
                  "$ref": "#/definitions/OpenSpec/properties/goals/items"
                }
              },
              "acceptanceCriteria": {
                "type": "array",
                "items": {
                  "$ref": "#/definitions/OpenSpec/properties/requirements/items/properties/acceptanceCriteria/items"
                }
              },
              "validationCommands": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "apiContracts": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string",
                      "minLength": 1
                    },
                    "type": {
                      "type": "string",
                      "enum": [
                        "rest",
                        "graphql",
                        "rpc",
                        "event",
                        "cli"
                      ]
                    },
                    "description": {
                      "type": "string"
                    },
                    "blueprintReferences": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "blueprintId": {
                            "type": "string"
                          },
                          "context": {
                            "type": "string"
                          },
                          "section": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "blueprintId"
                        ],
                        "additionalProperties": false
                      }
                    }
                  },
                  "required": [
                    "id",
                    "name",
                    "type"
                  ],
                  "additionalProperties": false
                }
              },
              "sharedPatterns": {
                "type": "array",
                "items": {
                  "$ref": "#/definitions/OpenSpec/properties/sharedPatterns/items"
                }
              },
              "fileStructures": {
                "type": "array",
                "items": {
                  "$ref": "#/definitions/OpenSpec/properties/folderStructures/items"
                }
              },
              "requirementsCovered": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "nfrsCovered": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "goalsCovered": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "tickets": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "epicId": {
                      "type": "string"
                    },
                    "ticketNumber": {
                      "type": "integer",
                      "exclusiveMinimum": 0
                    },
                    "title": {
                      "type": "string",
                      "minLength": 1
                    },
                    "description": {
                      "type": "string"
                    },
                    "ticketType": {
                      "type": "string",
                      "enum": [
                        "implementation",
                        "verification"
                      ]
                    },
                    "complexity": {
                      "type": "string",
                      "enum": [
                        "small",
                        "medium",
                        "large",
                        "xlarge"
                      ]
                    },
                    "estimatedMinutes": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "order": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "acceptanceCriteria": {
                      "type": "array",
                      "items": {
                        "$ref": "#/definitions/OpenSpec/properties/requirements/items/properties/acceptanceCriteria/items"
                      }
                    },
                    "implementationSteps": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "text": {
                            "type": "string"
                          },
                          "order": {
                            "type": "integer",
                            "minimum": 1
                          }
                        },
                        "required": [
                          "id",
                          "text",
                          "order"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "filesToBeCreated": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "filesToBeModified": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "filesToBeDeleted": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "filesToBeReferenced": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "testSpecification": {
                      "type": "object",
                      "properties": {
                        "testTypes": {
                          "type": "array",
                          "items": {
                            "type": "string",
                            "enum": [
                              "unit",
                              "integration",
                              "e2e",
                              "typecheck",
                              "lint",
                              "build",
                              "contract",
                              "structural",
                              "layout",
                              "a11y",
                              "performance"
                            ]
                          },
                          "minItems": 1
                        },
                        "qualityGates": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          },
                          "minItems": 1
                        },
                        "testCommands": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        "coverageTarget": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 100
                        }
                      },
                      "required": [
                        "testTypes",
                        "qualityGates",
                        "testCommands"
                      ],
                      "additionalProperties": false
                    },
                    "guardrails": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "codeReferences": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "filePath": {
                            "type": "string"
                          },
                          "symbol": {
                            "type": "string"
                          },
                          "description": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "filePath"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "typeReferences": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "filePath": {
                            "type": "string"
                          },
                          "typeName": {
                            "type": "string"
                          },
                          "description": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "filePath",
                          "typeName"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "codeSnippets": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "language": {
                            "type": "string"
                          },
                          "description": {
                            "type": "string"
                          },
                          "content": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "id",
                          "language",
                          "content"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "typeSnippets": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "language": {
                            "type": "string"
                          },
                          "description": {
                            "type": "string"
                          },
                          "content": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "id",
                          "language",
                          "content"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "blueprintReferences": {
                      "type": "array",
                      "items": {
                        "$ref": "#/definitions/OpenSpec/properties/epics/items/properties/apiContracts/items/properties/blueprintReferences/items"
                      }
                    },
                    "dependencies": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "ticketId": {
                            "type": "string"
                          },
                          "type": {
                            "type": "string",
                            "enum": [
                              "requires",
                              "blocks"
                            ]
                          }
                        },
                        "required": [
                          "ticketId",
                          "type"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "fieldDeclarations": {
                      "type": "object",
                      "additionalProperties": {
                        "type": "object",
                        "properties": {
                          "value": {
                            "type": "string",
                            "const": "N/A"
                          },
                          "reason": {
                            "type": "string",
                            "minLength": 20
                          }
                        },
                        "required": [
                          "value",
                          "reason"
                        ],
                        "additionalProperties": false
                      }
                    }
                  },
                  "required": [
                    "id",
                    "epicId",
                    "title",
                    "ticketType",
                    "complexity",
                    "estimatedMinutes",
                    "acceptanceCriteria",
                    "implementationSteps",
                    "filesToBeCreated",
                    "filesToBeModified",
                    "filesToBeDeleted",
                    "filesToBeReferenced",
                    "guardrails",
                    "codeReferences",
                    "typeReferences",
                    "blueprintReferences",
                    "dependencies"
                  ],
                  "additionalProperties": false
                }
              },
              "fieldDeclarations": {
                "type": "object",
                "additionalProperties": {
                  "$ref": "#/definitions/OpenSpec/properties/epics/items/properties/tickets/items/properties/fieldDeclarations/additionalProperties"
                }
              },
              "category": {
                "type": "string",
                "enum": [
                  "foundation",
                  "functional",
                  "non_functional",
                  "verification"
                ]
              }
            },
            "required": [
              "id",
              "specificationId",
              "title",
              "description",
              "objective",
              "tickets"
            ],
            "additionalProperties": false
          }
        },
        "blueprints": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "title": {
                "type": "string",
                "minLength": 1
              },
              "description": {
                "type": "string"
              },
              "slug": {
                "type": "string"
              },
              "category": {
                "type": "string",
                "enum": [
                  "flowchart",
                  "architecture",
                  "state",
                  "sequence",
                  "erd",
                  "mockup",
                  "adr",
                  "component",
                  "deployment",
                  "api",
                  "algorithm",
                  "protocol",
                  "glossary",
                  "design_system"
                ]
              },
              "format": {
                "type": "string",
                "enum": [
                  "markdown",
                  "mermaid",
                  "ascii",
                  "mixed",
                  "html",
                  "svg",
                  "image"
                ]
              },
              "coverageType": {
                "type": "string",
                "enum": [
                  "ticket",
                  "all"
                ],
                "default": "ticket"
              },
              "content": {
                "type": "string"
              },
              "notes": {
                "type": "string"
              },
              "version": {
                "type": "string"
              },
              "order": {
                "type": "integer",
                "minimum": 0
              },
              "tags": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "required": [
              "id",
              "title",
              "category",
              "content"
            ],
            "additionalProperties": false
          }
        },
        "fieldDeclarations": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/definitions/OpenSpec/properties/epics/items/properties/tickets/items/properties/fieldDeclarations/additionalProperties"
          }
        },
        "epicTargets": {
          "type": "object",
          "properties": {
            "foundation": {
              "type": "integer",
              "minimum": 0
            },
            "functional": {
              "type": "integer",
              "minimum": 0
            },
            "nonFunctional": {
              "type": "integer",
              "minimum": 0
            },
            "verification": {
              "type": "integer",
              "minimum": 0
            }
          },
          "required": [
            "foundation",
            "functional",
            "nonFunctional",
            "verification"
          ],
          "additionalProperties": false
        },
        "estimatedMinutes": {
          "type": "integer",
          "minimum": 0
        }
      },
      "required": [
        "schemaVersion",
        "id",
        "projectId",
        "title",
        "status",
        "goals",
        "requirements",
        "architecture",
        "scope",
        "techStack",
        "folderStructures",
        "acceptanceCriteria",
        "nonFunctionalRequirements",
        "guardrails",
        "epics",
        "blueprints"
      ],
      "additionalProperties": false
    }
  }
}
