{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://gitlink.org.cn/schemas/research-knowledge-graph.json",
  "title": "Research Knowledge Graph",
  "description": "Schema for the research knowledge graph generated from GitLink repository analysis",
  "type": "object",
  "required": ["metadata", "nodes", "edges"],
  "properties": {
    "metadata": {
      "type": "object",
      "required": ["generated_at", "search_keywords"],
      "properties": {
        "generated_at": { "type": "string", "format": "date-time" },
        "search_keywords": {
          "type": "array",
          "items": { "type": "string" },
          "minItems": 1
        },
        "total_repos_scanned": { "type": "integer", "minimum": 0 },
        "total_contributors_found": { "type": "integer", "minimum": 0 },
        "total_edges_inferred": { "type": "integer", "minimum": 0 },
        "api_version": { "type": "string" }
      }
    },
    "nodes": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["id", "type", "label"],
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique node identifier, e.g. 'repo:owner/repo-name' or 'topic:NLP'",
            "pattern": "^[a-z_]+:.+$"
          },
          "type": {
            "type": "string",
            "description": "Node type",
            "enum": ["repo", "contributor", "topic", "paper", "organization", "release"]
          },
          "label": {
            "type": "string",
            "description": "Human-readable display name"
          },
          "description": {
            "type": "string",
            "description": "Optional description for tooltip"
          },
          "properties": {
            "type": "object",
            "description": "Type-specific attributes"
          }
        }
      }
    },
    "edges": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["source", "target", "type"],
        "properties": {
          "source": {
            "type": "string",
            "description": "Source node ID"
          },
          "target": {
            "type": "string",
            "description": "Target node ID"
          },
          "type": {
            "type": "string",
            "description": "Relationship type",
            "enum": [
              "depends_on",
              "cites",
              "contributes_to",
              "forks_from",
              "has_topic",
              "collaborates_with",
              "releases",
              "references_paper",
              "implements_method",
              "related_to"
            ]
          },
          "weight": {
            "type": "number",
            "minimum": 0,
            "maximum": 1,
            "default": 0.5,
            "description": "Edge weight / confidence"
          },
          "evidence": {
            "type": "string",
            "description": "How this edge was inferred"
          }
        }
      }
    }
  }
}
