{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Project Metadata Schema",
  "description": "Workflow initialization metadata for project-level context",
  "type": "object",
  "required": [
    "project_name",
    "initialized_at",
    "overview",
    "features",
    "statistics",
    "_metadata"
  ],
  "properties": {
    "project_name": {
      "type": "string",
      "description": "Project name extracted from git repo or directory"
    },
    "initialized_at": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 timestamp of initialization"
    },
    "overview": {
      "type": "object",
      "required": [
        "description",
        "technology_stack",
        "architecture",
        "key_components"
      ],
      "properties": {
        "description": {
          "type": "string",
          "description": "Brief project description (e.g., 'TypeScript web application with React frontend')"
        },
        "technology_stack": {
          "type": "object",
          "required": ["languages", "frameworks", "build_tools", "test_frameworks"],
          "properties": {
            "languages": {
              "type": "array",
              "items": {
                "type": "object",
                "required": ["name", "file_count", "primary"],
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Language name (e.g., TypeScript, Python)"
                  },
                  "file_count": {
                    "type": "integer",
                    "description": "Number of source files in this language"
                  },
                  "primary": {
                    "type": "boolean",
                    "description": "True if this is the primary language"
                  }
                }
              }
            },
            "frameworks": {
              "type": "array",
              "items": {"type": "string"},
              "description": "Detected frameworks (React, Express, Django, etc.)"
            },
            "build_tools": {
              "type": "array",
              "items": {"type": "string"},
              "description": "Build tools and package managers (npm, cargo, maven, etc.)"
            },
            "test_frameworks": {
              "type": "array",
              "items": {"type": "string"},
              "description": "Testing frameworks (jest, pytest, go test, etc.)"
            }
          }
        },
        "architecture": {
          "type": "object",
          "required": ["style", "layers", "patterns"],
          "properties": {
            "style": {
              "type": "string",
              "description": "Architecture style (MVC, microservices, layered, etc.)"
            },
            "layers": {
              "type": "array",
              "items": {"type": "string"},
              "description": "Architectural layers (presentation, business-logic, data-access)"
            },
            "patterns": {
              "type": "array",
              "items": {"type": "string"},
              "description": "Design patterns (Repository, Factory, Singleton, etc.)"
            }
          }
        },
        "key_components": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["name", "path", "description", "importance"],
            "properties": {
              "name": {
                "type": "string",
                "description": "Component name"
              },
              "path": {
                "type": "string",
                "description": "Relative path to component directory"
              },
              "description": {
                "type": "string",
                "description": "Brief description of component functionality"
              },
              "importance": {
                "type": "string",
                "enum": ["high", "medium", "low"],
                "description": "Component importance level"
              }
            }
          },
          "description": "5-10 core modules/components"
        }
      }
    },
    "features": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["session_id", "title", "completed_at", "tags"],
        "properties": {
          "session_id": {
            "type": "string",
            "description": "WFS session identifier"
          },
          "title": {
            "type": "string",
            "description": "Feature title/description"
          },
          "completed_at": {
            "type": "string",
            "format": "date-time",
            "description": "ISO 8601 timestamp of completion"
          },
          "tags": {
            "type": "array",
            "items": {"type": "string"},
            "description": "Feature tags for categorization"
          }
        }
      },
      "description": "Completed workflow features (populated by /workflow:session:complete)"
    },
    "development_index": {
      "type": "object",
      "description": "Categorized development history (lite-plan/lite-execute)",
      "properties": {
        "feature": { "type": "array", "items": { "$ref": "#/$defs/devIndexEntry" } },
        "enhancement": { "type": "array", "items": { "$ref": "#/$defs/devIndexEntry" } },
        "bugfix": { "type": "array", "items": { "$ref": "#/$defs/devIndexEntry" } },
        "refactor": { "type": "array", "items": { "$ref": "#/$defs/devIndexEntry" } },
        "docs": { "type": "array", "items": { "$ref": "#/$defs/devIndexEntry" } }
      }
    },
    "statistics": {
      "type": "object",
      "required": ["total_features", "total_sessions", "last_updated"],
      "properties": {
        "total_features": {
          "type": "integer",
          "description": "Count of completed features"
        },
        "total_sessions": {
          "type": "integer",
          "description": "Count of workflow sessions"
        },
        "last_updated": {
          "type": "string",
          "format": "date-time",
          "description": "ISO 8601 timestamp of last update"
        }
      }
    },
    "_metadata": {
      "type": "object",
      "required": ["initialized_by", "analysis_timestamp", "analysis_mode"],
      "properties": {
        "initialized_by": {
          "type": "string",
          "description": "Agent or tool that performed initialization"
        },
        "analysis_timestamp": {
          "type": "string",
          "format": "date-time",
          "description": "ISO 8601 timestamp of analysis"
        },
        "analysis_mode": {
          "type": "string",
          "enum": ["deep-scan", "quick-scan", "bash-fallback"],
          "description": "Analysis mode used"
        }
      }
    }
  },
  "$defs": {
    "devIndexEntry": {
      "type": "object",
      "required": ["title", "sub_feature", "date", "description", "status"],
      "properties": {
        "title": { "type": "string", "maxLength": 60 },
        "sub_feature": { "type": "string", "description": "Module/component area" },
        "date": { "type": "string", "format": "date" },
        "description": { "type": "string", "maxLength": 100 },
        "status": { "type": "string", "enum": ["completed", "partial"] },
        "session_id": { "type": "string", "description": "lite-plan session ID" }
      }
    }
  }
}
