{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://standards.rootblocks.com/schemas/components/component.v1.schema.json",
  "title": "RootBlocks Component v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "componentId",
    "version",
    "owner",
    "taxonomy",
    "category",
    "provider",
    "capabilities",
    "inputs",
    "outputs",
    "secrets",
    "source",
    "buildPack",
    "distribution",
    "evidence"
  ],
  "properties": {
    "schemaVersion": {
      "const": "rootblocks.component/v1"
    },
    "componentId": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9.-]{2,127}$"
    },
    "displayName": {
      "type": "string",
      "minLength": 1,
      "maxLength": 160
    },
    "version": {
      "$ref": "#/$defs/semver"
    },
    "owner": {
      "type": "object",
      "additionalProperties": false,
      "required": ["type", "id"],
      "properties": {
        "type": {
          "enum": ["rootblocks", "organization", "project", "personal"]
        },
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9.-]{1,127}$"
        },
        "visibility": {
          "enum": ["public", "organization-private", "project-local", "personal-private"]
        }
      }
    },
    "category": {
      "enum": [
        "validation",
        "business-rule",
        "messaging",
        "http",
        "data",
        "auth",
        "storage",
        "observability",
        "documents",
        "ai",
        "infra",
        "cicd",
        "custom"
      ]
    },
    "taxonomy": {
      "$ref": "#/$defs/taxonomy"
    },
    "provider": {
      "enum": [
        "rootblocks",
        "azure",
        "aws",
        "gcp",
        "kubernetes",
        "github",
        "azure-devops",
        "custom"
      ]
    },
    "capabilities": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "enum": [
          "design",
          "validate",
          "compile",
          "run",
          "debug",
          "trace",
          "evidence",
          "requires-secret",
          "network",
          "stateful",
          "idempotent",
          "destructive"
        ]
      }
    },
    "inputs": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/port"
      }
    },
    "outputs": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/port"
      }
    },
    "secrets": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/secretRequirement"
      }
    },
    "runtime": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "adapter": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9.-]{2,127}$"
        },
        "supportedRunners": {
          "type": "array",
          "items": {
            "enum": ["builderx-api", "builderx-console", "builderx-worker", "external-adapter"]
          },
          "uniqueItems": true
        }
      }
    },
    "source": {
      "$ref": "#/$defs/componentSource"
    },
    "buildPack": {
      "$ref": "#/$defs/buildPackRef"
    },
    "distribution": {
      "$ref": "#/$defs/componentDistribution"
    },
    "evidence": {
      "type": "object",
      "additionalProperties": false,
      "required": ["required", "events"],
      "properties": {
        "required": {
          "type": "boolean"
        },
        "events": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "enum": ["configured", "validated", "executed", "failed", "redacted"]
          }
        }
      }
    },
    "compatibility": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "minimumStandardVersion": {
          "$ref": "#/$defs/semver"
        },
        "minimumBuilderXVersion": {
          "$ref": "#/$defs/semver"
        },
        "minimumRootBlocksConsoleVersion": {
          "$ref": "#/$defs/semver"
        },
        "minimumDarkFactoryVersion": {
          "$ref": "#/$defs/semver"
        }
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "source": {
            "properties": {
              "mode": {
                "const": "builderx-compiler"
              }
            },
            "required": ["mode"]
          }
        },
        "required": ["source"]
      },
      "then": {
        "properties": {
          "distribution": {
            "properties": {
              "artifacts": {
                "contains": {
                  "properties": {
                    "kind": {
                      "const": "builderx-buildpack"
                    }
                  },
                  "required": ["kind"]
                }
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "source": {
            "properties": {
              "mode": {
                "const": "agent-generated"
              }
            },
            "required": ["mode"]
          }
        },
        "required": ["source"]
      },
      "then": {
        "properties": {
          "distribution": {
            "properties": {
              "artifacts": {
                "contains": {
                  "properties": {
                    "kind": {
                      "enum": ["nuget", "npm", "pypi", "maven", "gradle", "cargo", "go-module", "composer", "gem", "docker-oci", "custom"]
                    }
                  },
                  "required": ["kind"]
                }
              }
            }
          }
        }
      }
    }
  ],
  "$defs": {
    "componentSource": {
      "type": "object",
      "additionalProperties": false,
      "required": ["producer", "mode"],
      "properties": {
        "producer": {
          "enum": ["rootblocks", "rootblocks-console", "darkfactory", "builderx", "human", "external"]
        },
        "mode": {
          "enum": ["builderx-compiler", "agent-generated", "manual-governed", "imported"]
        },
        "generatorRef": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9_.:/@-]{1,160}$"
        },
        "sourceMapRef": {
          "type": "string",
          "pattern": "^(builderx|docs|src|tests|components)/.+$"
        }
      }
    },
    "buildPackRef": {
      "type": "object",
      "additionalProperties": false,
      "required": ["buildPackId", "version", "path", "categoryPath", "exposedWorkflowIds"],
      "properties": {
        "buildPackId": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9.-]{2,127}$"
        },
        "version": {
          "$ref": "#/$defs/semver"
        },
        "path": {
          "type": "string",
          "pattern": "^(builderx|components)/.+\\.buildpack\\.(yaml|yml|json)$"
        },
        "categoryPath": {
          "type": "array",
          "minItems": 2,
          "items": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9.-]{1,127}$"
          }
        },
        "exposedWorkflowIds": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9.-]{2,127}$"
          },
          "uniqueItems": true
        }
      }
    },
    "componentDistribution": {
      "type": "object",
      "additionalProperties": false,
      "required": ["sync", "artifacts"],
      "properties": {
        "sync": {
          "$ref": "#/$defs/componentSync"
        },
        "artifacts": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/packageArtifact"
          }
        }
      }
    },
    "componentSync": {
      "type": "object",
      "additionalProperties": false,
      "required": ["required", "tool", "targetScope"],
      "properties": {
        "required": {
          "type": "boolean",
          "const": true
        },
        "tool": {
          "const": "rbstd"
        },
        "targetScope": {
          "enum": ["global", "organization", "project", "personal"]
        },
        "importCommand": {
          "type": "string",
          "pattern": "^rbstd components import .+$"
        },
        "syncCommand": {
          "type": "string",
          "pattern": "^rbstd components sync .+$"
        }
      }
    },
    "packageArtifact": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "language", "packageName", "version", "sourcePath"],
      "properties": {
        "kind": {
          "enum": [
            "builderx-buildpack",
            "nuget",
            "npm",
            "pypi",
            "maven",
            "gradle",
            "cargo",
            "go-module",
            "composer",
            "gem",
            "docker-oci",
            "custom"
          ]
        },
        "language": {
          "enum": ["csharp", "typescript", "javascript", "python", "java", "kotlin", "go", "rust", "php", "ruby", "custom"]
        },
        "packageName": {
          "type": "string",
          "pattern": "^[a-zA-Z0-9@][a-zA-Z0-9_.:/@-]{1,160}$"
        },
        "version": {
          "$ref": "#/$defs/semver"
        },
        "sourcePath": {
          "type": "string",
          "pattern": "^(src|components|builderx|packages)/.+$"
        },
        "artifactRef": {
          "type": "string",
          "pattern": "^(dist|artifacts|packages|builderx)/.+$"
        },
        "registry": {
          "type": "string",
          "maxLength": 240
        }
      }
    },
    "taxonomy": {
      "type": "object",
      "additionalProperties": false,
      "required": ["superCategory", "category", "subcategory", "usableIn"],
      "properties": {
        "superCategory": {
          "enum": ["cross-functional", "project-type", "domain-specific", "integration", "custom"]
        },
        "projectCategory": {
          "enum": [
            "any",
            "application",
            "component-pack",
            "library",
            "worker",
            "service",
            "infrastructure-project",
            "workflow-project",
            "test-project",
            "cicd-project",
            "data-project",
            "ai-project",
            "custom"
          ]
        },
        "category": {
          "enum": [
            "validation",
            "business-rule",
            "messaging",
            "http",
            "data",
            "auth",
            "storage",
            "observability",
            "documents",
            "ai",
            "infra",
            "workflow",
            "test",
            "cicd",
            "integration",
            "ui",
            "security",
            "custom"
          ]
        },
        "subcategory": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9.-]{1,127}$"
        },
        "integrationTarget": {
          "type": "object",
          "additionalProperties": false,
          "required": ["kind", "id"],
          "properties": {
            "kind": {
              "enum": ["none", "cloud-provider", "saas", "social-platform", "payment-provider", "identity-provider", "database", "message-broker", "observability-provider", "custom"]
            },
            "id": {
              "type": "string",
              "pattern": "^[a-z0-9][a-z0-9.-]{1,127}$"
            }
          }
        },
        "usableIn": {
          "type": "array",
          "minItems": 1,
          "items": {
            "enum": ["application", "infrastructure", "workflow", "test", "cicd", "component-pack", "documentation", "all"]
          },
          "uniqueItems": true
        },
        "designerPalette": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "group": {
              "type": "string",
              "pattern": "^[a-z0-9][a-z0-9.-]{1,127}$"
            },
            "order": {
              "type": "integer",
              "minimum": 0
            },
            "tags": {
              "type": "array",
              "items": {
                "type": "string",
                "pattern": "^[a-z0-9][a-z0-9.-]{1,127}$"
              },
              "uniqueItems": true
            }
          }
        }
      }
    },
    "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.-]+)?$"
    },
    "port": {
      "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", "object", "array", "secret-ref", "any"]
        },
        "required": {
          "type": "boolean"
        },
        "description": {
          "type": "string",
          "maxLength": 500
        }
      }
    },
    "secretRequirement": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "provider", "scope", "required"],
      "properties": {
        "name": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9.-]{1,127}$"
        },
        "provider": {
          "enum": ["azure-key-vault", "aws-secrets-manager", "gcp-secret-manager", "hashicorp-vault", "environment", "custom"]
        },
        "scope": {
          "enum": ["organization", "project", "environment", "personal"]
        },
        "required": {
          "type": "boolean"
        }
      }
    }
  }
}
