{
  "openapi": "3.1.0",
  "info": {
    "title": "Zuhaib Rashid Portfolio & Developer API",
    "description": "Production-ready, agent-friendly REST API for interacting with Zuhaib Rashid's developer portfolio, live GitHub statistics, and developer services.",
    "version": "1.0.0",
    "contact": {
      "name": "Zuhaib Rashid",
      "email": "zuhaibrashid01@gmail.com",
      "url": "https://www.zuhaibrashid.com/contact"
    }
  },
  "servers": [
    {
      "url": "https://www.zuhaibrashid.com",
      "description": "Production Live Server"
    },
    {
      "url": "http://localhost:3000",
      "description": "Local Development Server"
    }
  ],
  "paths": {
    "/api/v1/github": {
      "get": {
        "operationId": "getGithubStatsV1",
        "summary": "Get Aggregated GitHub Statistics (v1)",
        "description": "Fetches real-time aggregated star and fork metrics across all public repositories for Zuhaib-dev with built-in cursor pagination, caching, and rate limiting.",
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "description": "Cursor pagination token for navigating to subsequent pages",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "page",
            "in": "query",
            "required": false,
            "description": "Page number for paginating through repositories",
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Number of items per page (maximum 100)",
            "schema": {
              "type": "integer",
              "default": 100,
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "Unique idempotency token for safe, deterministic retries",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response with aggregated stats and pagination metadata",
            "headers": {
              "RateLimit-Limit": {
                "description": "IETF standard max requests allowed",
                "schema": { "type": "integer", "example": 60 }
              },
              "RateLimit-Remaining": {
                "description": "IETF standard remaining requests",
                "schema": { "type": "integer", "example": 59 }
              },
              "RateLimit-Reset": {
                "description": "IETF standard window reset in seconds",
                "schema": { "type": "integer", "example": 3600 }
              },
              "X-RateLimit-Limit": {
                "description": "Maximum allowed requests per minute",
                "schema": { "type": "integer", "example": 60 }
              },
              "X-RateLimit-Remaining": {
                "description": "Remaining requests in current window",
                "schema": { "type": "integer", "example": 59 }
              },
              "X-RateLimit-Reset": {
                "description": "Unix timestamp when the rate limit window resets",
                "schema": { "type": "integer", "example": 1700000000 }
              },
              "X-API-Version": {
                "description": "API Version",
                "schema": { "type": "string", "example": "v1" }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GitHubStatsResponse"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/github": {
      "get": {
        "operationId": "getGithubStats",
        "summary": "Get Aggregated GitHub Statistics (Legacy / Alias)",
        "description": "Direct alias to v1 endpoint. Returns stars and forks count.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "Unique idempotency token for safe, deterministic retries",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GitHubStatsResponse"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "PaginationMetadata": {
        "type": "object",
        "required": ["page", "limit", "hasNextPage"],
        "properties": {
          "page": {
            "type": "integer",
            "description": "Current page number",
            "example": 1
          },
          "limit": {
            "type": "integer",
            "description": "Items per page",
            "example": 100
          },
          "totalFetched": {
            "type": "integer",
            "description": "Total repositories fetched in this page",
            "example": 25
          },
          "hasNextPage": {
            "type": "boolean",
            "description": "Whether more pages are available",
            "example": false
          }
        }
      },
      "GitHubStatsResponse": {
        "type": "object",
        "required": ["stars", "forks", "reposCount", "version"],
        "properties": {
          "stars": {
            "type": "integer",
            "description": "Total stars across all public repositories",
            "example": 42
          },
          "forks": {
            "type": "integer",
            "description": "Total forks across all public repositories",
            "example": 12
          },
          "reposCount": {
            "type": "integer",
            "description": "Number of public repositories analyzed",
            "example": 30
          },
          "version": {
            "type": "string",
            "description": "API schema version",
            "example": "v1"
          },
          "pagination": {
            "$ref": "#/components/schemas/PaginationMetadata"
          }
        }
      },
      "ErrorDetail": {
        "type": "object",
        "required": ["code", "message", "status"],
        "properties": {
          "code": {
            "type": "string",
            "description": "Machine-readable error code",
            "example": "RESOURCE_NOT_FOUND"
          },
          "message": {
            "type": "string",
            "description": "Human-readable error description",
            "example": "The requested API endpoint was not found"
          },
          "status": {
            "type": "integer",
            "description": "HTTP status code",
            "example": 404
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": ["error", "status"],
        "properties": {
          "error": {
            "$ref": "#/components/schemas/ErrorDetail"
          },
          "status": {
            "type": "integer",
            "description": "HTTP status code",
            "example": 404
          }
        }
      }
    }
  }
}
