{
  "openapi": "3.0.0",
  "info": {
    "title": "Tahirinirina Kevin Portfolio API",
    "description": "Public API for Tahirinirina Kevin (Tahiry) portfolio projects, GitHub repository information, and health status. Administrative operations require authentication.",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://tahiry-portfolio-api.onrender.com/api",
      "description": "Production API"
    }
  ],
  "tags": [
    {
      "name": "GitHub",
      "description": "Portfolio repository data"
    },
    {
      "name": "health",
      "description": "Service health checks"
    }
  ],
  "paths": {
    "/github/repos": {
      "get": {
        "operationId": "getPortfolioRepositories",
        "tags": [
          "GitHub"
        ],
        "summary": "Get portfolio repositories from GitHub",
        "description": "Returns public GitHub repositories selected and mapped for the portfolio. Results may be served from cache.",
        "responses": {
          "200": {
            "description": "Portfolio projects retrieved successfully",
            "headers": {
              "RateLimit-Limit": { "description": "Maximum requests allowed in the current window.", "schema": { "type": "integer", "example": 100 } },
              "RateLimit-Remaining": { "description": "Requests remaining in the current window.", "schema": { "type": "integer", "example": 99 } },
              "RateLimit-Reset": { "description": "Seconds until the current limit window resets.", "schema": { "type": "integer", "example": 60 } },
              "RateLimit-Policy": { "description": "Request quota and window, formatted as limit;w=seconds.", "schema": { "type": "string", "example": "100;w=60" } }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "statusCode",
                    "timestamp"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/MappedProject"
                      }
                    },
                    "statusCode": {
                      "type": "integer"
                    },
                    "timestamp": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "429": {
            "description": "Rate limit exceeded. Retry after the duration in Retry-After.",
            "headers": {
              "Retry-After": { "description": "Seconds to wait before retrying.", "schema": { "type": "integer", "example": 60 } }
            },
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ApiError" }
              }
            }
          }
        }
      }
    },
    "/health": {
      "get": {
        "operationId": "getServiceHealth",
        "tags": [
          "health"
        ],
        "summary": "Check API liveness",
        "description": "Returns a static liveness response without accessing the database or Redis.",
        "servers": [
          {
            "url": "https://tahiry-portfolio-api.onrender.com"
          }
        ],
        "responses": {
          "200": {
            "description": "Service is alive",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                }
              }
            }
          }
        }
      }
    },
    "/v1/github/tech-stack/{owner}/{repo}": {
      "get": {
        "operationId": "getRepositoryTechStack",
        "tags": [
          "GitHub"
        ],
        "summary": "Get a repository technology stack",
        "description": "Returns the deduplicated dependency technology stack for a public GitHub repository.",
        "responses": {
          "200": {
            "description": "Repository technology stack",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RepoTechStack"
                }
              }
            }
          },
          "404": {
            "description": "Repository not found"
          }
        },
        "parameters": [
          {
            "name": "owner",
            "in": "path",
            "required": true,
            "description": "GitHub repository owner",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "repo",
            "in": "path",
            "required": true,
            "description": "GitHub repository name",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/ai-chat/generate": {
      "post": {
        "operationId": "generateAssistantResponse",
        "tags": [
          "AI Chat"
        ],
        "summary": "Generate a streamed assistant response",
        "description": "Streams model output as server-sent events. The message is limited to 2,000 characters and history to 50 messages.",
        "responses": {
          "200": {
            "description": "SSE stream of token events",
            "content": {
              "text/event-stream": {
                "schema": {
                  "type": "string",
                  "description": "SSE events containing JSON token values, terminated by data: [DONE]"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatRequest"
              }
            }
          }
        }
      }
    },
    "/messages": {
      "post": {
        "operationId": "sendContactMessage",
        "tags": [
          "messages"
        ],
        "summary": "Send a contact message",
        "description": "Submits a visitor message to the portfolio owner.",
        "responses": {
          "201": {
            "description": "Message created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SuccessEnvelope"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateMessage"
              }
            }
          }
        }
      },
      "get": {
        "operationId": "listContactMessages",
        "tags": [
          "messages"
        ],
        "summary": "List contact messages",
        "description": "Returns a paginated list of contact messages for authenticated administrators.",
        "responses": {
          "200": {
            "description": "Paginated contact messages",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SuccessEnvelope"
                }
              }
            }
          },
          "401": {
            "description": "Authentication is required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "403": {
            "description": "Administrator privileges are required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          }
        ]
      }
    },
    "/messages/{id}": {
      "get": {
        "operationId": "getContactMessage",
        "tags": [
          "messages"
        ],
        "summary": "Get one contact message",
        "description": "Returns a single message to an authenticated administrator.",
        "responses": {
          "200": {
            "description": "Message details",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SuccessEnvelope"
                }
              }
            }
          },
          "401": {
            "description": "Authentication is required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "403": {
            "description": "Administrator privileges are required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      },
      "delete": {
        "operationId": "deleteContactMessage",
        "tags": [
          "messages"
        ],
        "summary": "Delete a contact message",
        "description": "Deletes a message by its identifier for an authenticated administrator.",
        "responses": {
          "200": {
            "description": "Message deleted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SuccessEnvelope"
                }
              }
            }
          },
          "401": {
            "description": "Authentication is required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "403": {
            "description": "Administrator privileges are required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/messages/{id}/read": {
      "patch": {
        "operationId": "markContactMessageRead",
        "tags": [
          "messages"
        ],
        "summary": "Mark a contact message as read",
        "description": "Marks a message as read for an authenticated administrator.",
        "responses": {
          "200": {
            "description": "Message updated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SuccessEnvelope"
                }
              }
            }
          },
          "401": {
            "description": "Authentication is required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "403": {
            "description": "Administrator privileges are required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/auth/login": {
      "post": {
        "operationId": "loginAdministrator",
        "tags": [
          "authentication"
        ],
        "summary": "Authenticate an administrator",
        "description": "Validates administrator credentials and returns authentication tokens.",
        "responses": {
          "200": {
            "description": "Authentication result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SuccessEnvelope"
                }
              }
            }
          },
          "401": {
            "description": "Credentials are invalid",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LoginRequest"
              }
            }
          }
        }
      }
    },
    "/auth/me": {
      "get": {
        "operationId": "getCurrentAdministrator",
        "tags": [
          "authentication"
        ],
        "summary": "Get the current administrator",
        "description": "Returns the authenticated administrator profile.",
        "responses": {
          "200": {
            "description": "Administrator profile",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SuccessEnvelope"
                }
              }
            }
          },
          "401": {
            "description": "Authentication is required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "403": {
            "description": "Administrator privileges are required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/telemetry/page-view": {
      "post": {
        "operationId": "recordPageView",
        "tags": [
          "telemetry"
        ],
        "summary": "Record a page view",
        "description": "Records an anonymous page view for portfolio analytics.",
        "responses": {
          "201": {
            "description": "Page view recorded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SuccessEnvelope"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        }
      }
    },
    "/telemetry/stats": {
      "get": {
        "operationId": "getTelemetryStats",
        "tags": [
          "telemetry"
        ],
        "summary": "Get dashboard statistics",
        "description": "Returns visitor analytics for authenticated administrators.",
        "responses": {
          "200": {
            "description": "Analytics data",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SuccessEnvelope"
                }
              }
            }
          },
          "401": {
            "description": "Authentication is required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "403": {
            "description": "Administrator privileges are required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": []
      }
    },
    "/telemetry/summary": {
      "get": {
        "operationId": "getTelemetrySummary",
        "tags": [
          "telemetry"
        ],
        "summary": "Get analytics summary",
        "description": "Returns extended analytics trends for authenticated administrators.",
        "responses": {
          "200": {
            "description": "Analytics data",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SuccessEnvelope"
                }
              }
            }
          },
          "401": {
            "description": "Authentication is required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "403": {
            "description": "Administrator privileges are required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": []
      }
    },
    "/telemetry/nodes": {
      "get": {
        "operationId": "getTelemetryNodes",
        "tags": [
          "telemetry"
        ],
        "summary": "List visitor nodes",
        "description": "Returns paginated visitor nodes for authenticated administrators.",
        "responses": {
          "200": {
            "description": "Analytics data",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SuccessEnvelope"
                }
              }
            }
          },
          "401": {
            "description": "Authentication is required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "403": {
            "description": "Administrator privileges are required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 10
            }
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          }
        ]
      }
    },
    "/telemetry/viewers": {
      "get": {
        "operationId": "getTelemetryViewers",
        "tags": [
          "telemetry"
        ],
        "summary": "List visitors",
        "description": "Returns visitor nodes for authenticated administrators.",
        "responses": {
          "200": {
            "description": "Analytics data",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SuccessEnvelope"
                }
              }
            }
          },
          "401": {
            "description": "Authentication is required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "403": {
            "description": "Administrator privileges are required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 10
            }
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          }
        ]
      }
    },
    "/telemetry/alerts": {
      "get": {
        "operationId": "getTelemetryAlerts",
        "tags": [
          "telemetry"
        ],
        "summary": "List system alerts",
        "description": "Returns paginated system alerts for authenticated administrators.",
        "responses": {
          "200": {
            "description": "Analytics data",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SuccessEnvelope"
                }
              }
            }
          },
          "401": {
            "description": "Authentication is required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "403": {
            "description": "Administrator privileges are required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 10
            }
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          }
        ]
      }
    },
    "/telemetry/stats/country": {
      "get": {
        "operationId": "getTelemetryStatsByCountry",
        "tags": [
          "telemetry"
        ],
        "summary": "Get statistics by country",
        "description": "Returns visitor counts grouped by country for authenticated administrators.",
        "responses": {
          "200": {
            "description": "Analytics data",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SuccessEnvelope"
                }
              }
            }
          },
          "401": {
            "description": "Authentication is required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "403": {
            "description": "Administrator privileges are required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": []
      }
    },
    "/telemetry/alerts/{id}/read": {
      "patch": {
        "operationId": "markTelemetryAlertRead",
        "tags": [
          "telemetry"
        ],
        "summary": "Mark an alert as read",
        "description": "Marks the specified alert as read for an authenticated administrator.",
        "responses": {
          "200": {
            "description": "Alert updated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SuccessEnvelope"
                }
              }
            }
          },
          "401": {
            "description": "Authentication is required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "403": {
            "description": "Administrator privileges are required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    }
  },
  "components": {
    "schemas": {
      "MappedProject": {
        "type": "object",
        "required": [
          "id",
          "title",
          "desc",
          "year",
          "technologies",
          "sourceUrl",
          "stars",
          "updatedAt"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "desc": {
            "type": "string"
          },
          "year": {
            "type": "string"
          },
          "technologies": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sourceUrl": {
            "type": "string",
            "format": "uri"
          },
          "liveUrl": {
            "type": "string",
            "format": "uri"
          },
          "stars": {
            "type": "integer",
            "minimum": 0
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "isTeamProject": {
            "type": "boolean"
          },
          "isPrivate": {
            "type": "boolean"
          }
        }
      },
      "Health": {
        "type": "object",
        "required": [
          "status",
          "service",
          "uptime",
          "timestamp"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "ok"
            ]
          },
          "service": {
            "type": "string"
          },
          "uptime": {
            "type": "integer",
            "minimum": 0
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ApiError": {
        "type": "object",
        "required": [
          "code",
          "statusCode",
          "message",
          "resolution"
        ],
        "properties": {
          "code": {
            "type": "string",
            "description": "Stable machine-readable error code"
          },
          "statusCode": {
            "type": "integer",
            "description": "HTTP status code"
          },
          "message": {
            "type": "string",
            "description": "Human-readable explanation"
          },
          "resolution": {
            "type": "string",
            "description": "Suggested next step"
          },
          "path": {
            "type": "string",
            "description": "Requested API path"
          }
        }
      },
      "SuccessEnvelope": {
        "type": "object",
        "required": [
          "data",
          "statusCode",
          "timestamp"
        ],
        "properties": {
          "data": {},
          "statusCode": {
            "type": "integer"
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ChatRequest": {
        "type": "object",
        "required": [
          "message"
        ],
        "properties": {
          "message": {
            "type": "string",
            "maxLength": 2000
          },
          "history": {
            "type": "array",
            "maxItems": 50,
            "items": {
              "type": "object",
              "required": [
                "role",
                "content"
              ],
              "properties": {
                "role": {
                  "type": "string",
                  "enum": [
                    "user",
                    "model",
                    "assistant",
                    "system",
                    "bot"
                  ]
                },
                "content": {
                  "type": "string",
                  "maxLength": 10000
                }
              }
            }
          }
        }
      },
      "CreateMessage": {
        "type": "object",
        "required": [
          "name",
          "email",
          "message"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "message": {
            "type": "string"
          }
        }
      },
      "LoginRequest": {
        "type": "object",
        "required": [
          "email",
          "password"
        ],
        "properties": {
          "email": {
            "type": "string",
            "format": "email"
          },
          "password": {
            "type": "string"
          }
        }
      },
      "RepoTechStack": {
        "type": "object",
        "description": "Deduplicated dependency stack for a repository.",
        "additionalProperties": true
      }
    },
    "responses": {
      "ServiceUnavailable": {
        "description": "The API or upstream service is temporarily unavailable",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        }
      }
    },
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "Required only for protected administrative endpoints."
      }
    }
  },
  "security": [
    {
      "bearer": []
    }
  ]
}
