{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://decantr.ai/schemas/scan-report.v2.json",
  "title": "Decantr Brownfield Scan Report V2",
  "type": "object",
  "required": [
    "$schema",
    "schemaVersion",
    "generatedAt",
    "input",
    "source",
    "confidence",
    "applicability",
    "project",
    "routes",
    "components",
    "styling",
    "staticHosting",
    "assistant",
    "pagesProbe",
    "discovery",
    "findings",
    "recommendedCommands",
    "privacy"
  ],
  "properties": {
    "$schema": {
      "const": "https://decantr.ai/schemas/scan-report.v2.json"
    },
    "schemaVersion": {
      "const": "scan-report.v2"
    },
    "generatedAt": {
      "type": "string",
      "format": "date-time"
    },
    "input": {
      "type": "object",
      "required": ["kind", "value"],
      "properties": {
        "kind": {
          "type": "string",
          "enum": ["local", "github-repo", "github-pages"]
        },
        "value": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "source": {
      "type": "object"
    },
    "confidence": {
      "$ref": "#/$defs/confidence"
    },
    "applicability": {
      "type": "object",
      "required": ["status", "label", "reasons"],
      "properties": {
        "status": {
          "type": "string",
          "enum": ["strong_fit", "partial_fit", "not_applicable", "unknown"]
        },
        "label": {
          "type": "string",
          "minLength": 1
        },
        "reasons": {
          "$ref": "#/$defs/stringArray"
        }
      },
      "additionalProperties": false
    },
    "project": {
      "type": "object",
      "required": [
        "framework",
        "frameworkVersion",
        "packageManager",
        "primaryLanguage",
        "hasTypeScript",
        "hasTailwind",
        "hasDecantr",
        "packageName",
        "evidence",
        "workspaceScope",
        "projectPath"
      ],
      "properties": {
        "framework": {
          "type": "string"
        },
        "frameworkVersion": {
          "type": ["string", "null"]
        },
        "packageManager": {
          "type": "string"
        },
        "primaryLanguage": {
          "type": "string"
        },
        "hasTypeScript": {
          "type": "boolean"
        },
        "hasTailwind": {
          "type": "boolean"
        },
        "hasDecantr": {
          "type": "boolean"
        },
        "packageName": {
          "type": ["string", "null"]
        },
        "evidence": {
          "$ref": "#/$defs/stringArray"
        },
        "workspaceScope": {
          "type": "string",
          "enum": ["single-app", "workspace-app"]
        },
        "projectPath": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "routes": {
      "type": "object",
      "required": [
        "strategy",
        "count",
        "items",
        "routeSignalCount",
        "taskableRouteCount",
        "excludedSourceCount",
        "confidence",
        "authority",
        "completeness",
        "authorityFiles",
        "evidence",
        "signals"
      ],
      "properties": {
        "strategy": {
          "type": "string"
        },
        "count": {
          "type": "integer",
          "minimum": 0
        },
        "items": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/route"
          }
        },
        "routeSignalCount": {
          "type": "integer",
          "minimum": 0
        },
        "taskableRouteCount": {
          "type": "integer",
          "minimum": 0
        },
        "excludedSourceCount": {
          "type": "integer",
          "minimum": 0
        },
        "confidence": {
          "$ref": "#/$defs/confidenceLevel"
        },
        "authority": {
          "type": "string",
          "enum": ["proven", "inferred", "unresolved"]
        },
        "completeness": {
          "type": "string",
          "enum": ["complete", "partial", "unknown"]
        },
        "authorityFiles": {
          "$ref": "#/$defs/stringArray"
        },
        "evidence": {
          "$ref": "#/$defs/stringArray"
        },
        "signals": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/routeSignal"
          }
        }
      },
      "additionalProperties": false
    },
    "components": {
      "type": "object",
      "required": [
        "pageCount",
        "componentCount",
        "directories",
        "confidence",
        "evidence",
        "items",
        "limitations"
      ],
      "properties": {
        "pageCount": {
          "type": "integer",
          "minimum": 0
        },
        "componentCount": {
          "type": "integer",
          "minimum": 0
        },
        "directories": {
          "$ref": "#/$defs/stringArray"
        },
        "confidence": {
          "$ref": "#/$defs/confidenceLevel"
        },
        "evidence": {
          "$ref": "#/$defs/stringArray"
        },
        "items": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/component"
          }
        },
        "limitations": {
          "$ref": "#/$defs/stringArray"
        }
      },
      "additionalProperties": false
    },
    "styling": {
      "type": "object"
    },
    "staticHosting": {
      "type": "object"
    },
    "assistant": {
      "type": "object",
      "required": ["ruleFiles"],
      "properties": {
        "ruleFiles": {
          "$ref": "#/$defs/stringArray"
        }
      },
      "additionalProperties": false
    },
    "graphPreview": {
      "type": "object"
    },
    "pagesProbe": {
      "anyOf": [{ "type": "object" }, { "type": "null" }]
    },
    "discovery": {
      "type": "object",
      "required": [
        "schemaVersion",
        "workspace",
        "projectEvidence",
        "routeSignalCount",
        "taskableRouteCount",
        "routeExcludedSourceCount",
        "routeConfidence",
        "routeAuthority",
        "routeCompleteness",
        "routeAuthorityFiles",
        "routeEvidence",
        "componentConfidence",
        "componentEvidence",
        "uiSurfaces",
        "limitations"
      ],
      "properties": {
        "schemaVersion": {
          "const": "discovery.v1"
        },
        "workspace": {
          "type": "object",
          "required": ["projectPath", "scope"],
          "properties": {
            "projectPath": {
              "type": "string"
            },
            "scope": {
              "type": "string",
              "enum": ["single-app", "workspace-app"]
            }
          },
          "additionalProperties": false
        },
        "projectEvidence": {
          "$ref": "#/$defs/stringArray"
        },
        "routeSignalCount": {
          "type": "integer",
          "minimum": 0
        },
        "taskableRouteCount": {
          "type": "integer",
          "minimum": 0
        },
        "routeExcludedSourceCount": {
          "type": "integer",
          "minimum": 0
        },
        "routeConfidence": {
          "$ref": "#/$defs/confidenceLevel"
        },
        "routeAuthority": {
          "type": "string",
          "enum": ["proven", "inferred", "unresolved"]
        },
        "routeCompleteness": {
          "type": "string",
          "enum": ["complete", "partial", "unknown"]
        },
        "routeAuthorityFiles": {
          "$ref": "#/$defs/stringArray"
        },
        "routeEvidence": {
          "$ref": "#/$defs/stringArray"
        },
        "componentConfidence": {
          "$ref": "#/$defs/confidenceLevel"
        },
        "componentEvidence": {
          "$ref": "#/$defs/stringArray"
        },
        "uiSurfaces": {
          "$ref": "#/$defs/uiSurfaces"
        },
        "limitations": {
          "$ref": "#/$defs/stringArray"
        }
      },
      "additionalProperties": false
    },
    "findings": {
      "type": "array",
      "items": {
        "type": "object"
      }
    },
    "recommendedCommands": {
      "$ref": "#/$defs/stringArray"
    },
    "privacy": {
      "type": "object"
    }
  },
  "additionalProperties": false,
  "$defs": {
    "uiAxis": {
      "type": "object",
      "required": ["status", "confidence", "evidence", "limitations", "blocksReady"],
      "properties": {
        "status": {
          "type": "string",
          "enum": ["proven", "partial", "unresolved", "not_applicable", "unsupported"]
        },
        "confidence": {
          "$ref": "#/$defs/confidenceLevel"
        },
        "evidence": {
          "$ref": "#/$defs/stringArray"
        },
        "limitations": {
          "$ref": "#/$defs/stringArray"
        },
        "blocksReady": {
          "type": "boolean"
        }
      },
      "additionalProperties": false
    },
    "uiSurfaces": {
      "type": "object",
      "required": ["schemaVersion", "status", "primaryMode", "counts", "axes", "evidenceAdapters", "reasons"],
      "properties": {
        "schemaVersion": {
          "const": "ui-surfaces.v1"
        },
        "status": {
          "type": "string",
          "enum": ["ready", "limited", "blocked", "unsupported"]
        },
        "primaryMode": {
          "type": "string",
          "enum": ["application", "design-system", "component-library", "unknown"]
        },
        "counts": {
          "type": "object",
          "required": ["file", "route", "layout", "component", "story", "overlay", "flow", "package", "runtime-state"],
          "properties": {
            "file": { "type": "integer", "minimum": 0 },
            "route": { "type": "integer", "minimum": 0 },
            "layout": { "type": "integer", "minimum": 0 },
            "component": { "type": "integer", "minimum": 0 },
            "story": { "type": "integer", "minimum": 0 },
            "overlay": { "type": "integer", "minimum": 0 },
            "flow": { "type": "integer", "minimum": 0 },
            "package": { "type": "integer", "minimum": 0 },
            "runtime-state": { "type": "integer", "minimum": 0 }
          },
          "additionalProperties": false
        },
        "axes": {
          "type": "object",
          "required": ["selectedApp", "surfaceAuthority", "topologyCompleteness", "taskability", "componentInventory", "stylingAuthority", "runtimeEvidence"],
          "properties": {
            "selectedApp": { "$ref": "#/$defs/uiAxis" },
            "surfaceAuthority": { "$ref": "#/$defs/uiAxis" },
            "topologyCompleteness": { "$ref": "#/$defs/uiAxis" },
            "taskability": { "$ref": "#/$defs/uiAxis" },
            "componentInventory": { "$ref": "#/$defs/uiAxis" },
            "stylingAuthority": { "$ref": "#/$defs/uiAxis" },
            "runtimeEvidence": { "$ref": "#/$defs/uiAxis" }
          },
          "additionalProperties": false
        },
        "evidenceAdapters": {
          "$ref": "#/$defs/uiEvidenceAdapters"
        },
        "reasons": {
          "$ref": "#/$defs/stringArray"
        }
      },
      "additionalProperties": false
    },
    "uiEvidenceFile": {
      "type": "object",
      "required": ["file", "role", "scope"],
      "properties": {
        "file": {
          "type": "string"
        },
        "role": {
          "type": "string",
          "enum": ["configuration", "source", "artifact"]
        },
        "scope": {
          "type": "string",
          "enum": ["production", "package", "story", "example", "test", "fixture", "generated", "build-output", "supporting", "runtime-evidence"]
        }
      },
      "additionalProperties": false
    },
    "uiEvidenceAdapter": {
      "type": "object",
      "required": ["kind", "status", "confidence", "files", "evidence", "limitations"],
      "properties": {
        "kind": {
          "type": "string",
          "enum": ["storybook", "figma-code-connect", "design-tokens", "project-tests", "runtime", "visual", "accessibility"]
        },
        "status": {
          "type": "string",
          "enum": ["absent", "configured", "available"]
        },
        "confidence": {
          "$ref": "#/$defs/confidenceLevel"
        },
        "files": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/uiEvidenceFile"
          }
        },
        "evidence": {
          "$ref": "#/$defs/stringArray"
        },
        "limitations": {
          "$ref": "#/$defs/stringArray"
        }
      },
      "additionalProperties": false
    },
    "uiEvidenceAdapters": {
      "type": "object",
      "required": ["storybook", "figmaCodeConnect", "designTokens", "projectTests", "runtime", "visual", "accessibility"],
      "properties": {
        "storybook": {
          "$ref": "#/$defs/uiEvidenceAdapter"
        },
        "figmaCodeConnect": {
          "$ref": "#/$defs/uiEvidenceAdapter"
        },
        "designTokens": {
          "$ref": "#/$defs/uiEvidenceAdapter"
        },
        "projectTests": {
          "$ref": "#/$defs/uiEvidenceAdapter"
        },
        "runtime": {
          "$ref": "#/$defs/uiEvidenceAdapter"
        },
        "visual": {
          "$ref": "#/$defs/uiEvidenceAdapter"
        },
        "accessibility": {
          "$ref": "#/$defs/uiEvidenceAdapter"
        }
      },
      "additionalProperties": false
    },
    "confidenceLevel": {
      "type": "string",
      "enum": ["high", "medium", "low"]
    },
    "confidence": {
      "type": "object",
      "required": ["level", "score", "reasons"],
      "properties": {
        "level": {
          "$ref": "#/$defs/confidenceLevel"
        },
        "score": {
          "type": "integer",
          "minimum": 0,
          "maximum": 100
        },
        "reasons": {
          "$ref": "#/$defs/stringArray"
        }
      },
      "additionalProperties": false
    },
    "route": {
      "type": "object",
      "required": ["path", "file", "hasLayout"],
      "properties": {
        "path": {
          "type": "string"
        },
        "file": {
          "type": "string"
        },
        "hasLayout": {
          "type": "boolean"
        }
      },
      "additionalProperties": false
    },
    "routeSignal": {
      "type": "object",
      "required": ["path", "file", "kind", "confidence", "taskable", "evidence"],
      "properties": {
        "path": {
          "type": "string"
        },
        "file": {
          "type": "string"
        },
        "kind": {
          "type": "string"
        },
        "confidence": {
          "$ref": "#/$defs/confidenceLevel"
        },
        "taskable": {
          "type": "boolean"
        },
        "evidence": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "component": {
      "type": "object",
      "required": ["name", "file", "kind", "confidence"],
      "properties": {
        "name": {
          "type": "string"
        },
        "file": {
          "type": "string"
        },
        "kind": {
          "type": "string"
        },
        "confidence": {
          "$ref": "#/$defs/confidenceLevel"
        }
      },
      "additionalProperties": false
    },
    "stringArray": {
      "type": "array",
      "items": {
        "type": "string"
      }
    }
  }
}
