{
  "openapi": "3.1.0",
  "info": {
    "title": "Enegra Kanba API",
    "version": "0.2.0",
    "description": "HTTP API specification for Enegra Kanba (enegra-kanba), powered by Cloudflare Workers, Cloudflare D1 (SQLite), Cloudflare R2 storage, Cloudflare Turnstile bot protection, Better Auth, Resend transactional email, and Stripe billing."
  },
  "servers": [
    {
      "url": "https://enegra-kanba.enegra.workers.dev",
      "description": "Production Cloudflare Workers Deployment"
    }
  ],
  "paths": {
    "/api/health": {
      "get": {
        "operationId": "getHealth",
        "summary": "Service health check and runtime version metadata",
        "responses": {
          "200": {
            "description": "Service is healthy",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status",
                    "service",
                    "version",
                    "commit",
                    "commitShort",
                    "buildTime",
                    "timestamp"
                  ],
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "ok"
                    },
                    "service": {
                      "type": "string",
                      "example": "enegra-kanba"
                    },
                    "version": {
                      "type": "string",
                      "example": "0.2.0"
                    },
                    "commit": {
                      "type": "string"
                    },
                    "commitShort": {
                      "type": "string"
                    },
                    "buildTime": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "timestamp": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/version.json": {
      "get": {
        "operationId": "getVersionMetadata",
        "summary": "Build-time version and Git commit metadata",
        "responses": {
          "200": {
            "description": "Static build metadata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "version",
                    "commit",
                    "commitShort",
                    "buildTime",
                    "buildTimestamp",
                    "service"
                  ],
                  "properties": {
                    "version": {
                      "type": "string",
                      "example": "0.2.0"
                    },
                    "commit": {
                      "type": "string"
                    },
                    "commitShort": {
                      "type": "string"
                    },
                    "buildTime": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "buildTimestamp": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "service": {
                      "type": "string",
                      "example": "enegra-kanba"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/auth/{path}": {
      "get": {
        "operationId": "betterAuthGet",
        "summary": "Better Auth session, OAuth callback, and OIDC discovery endpoints",
        "parameters": [
          {
            "name": "path",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Authentication response"
          }
        }
      },
      "post": {
        "operationId": "betterAuthPost",
        "summary": "Better Auth sign-in, sign-up, password reset, 2FA, and sign-out endpoints",
        "parameters": [
          {
            "name": "path",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Authentication action completed"
          },
          "403": {
            "description": "Blocked by Cloudflare Turnstile bot protection"
          }
        }
      }
    },
    "/api/db": {
      "post": {
        "operationId": "executeDatabaseQuery",
        "summary": "Execute an authenticated query or mutation against Cloudflare D1",
        "responses": {
          "200": {
            "description": "Query result"
          },
          "401": {
            "description": "Authentication required for mutations"
          }
        }
      }
    },
    "/api/invitations": {
      "post": {
        "operationId": "sendProjectInvitation",
        "summary": "Invite an existing or new user to a project and send a Resend transactional email",
        "responses": {
          "200": {
            "description": "Member added or invitation sent"
          },
          "401": {
            "description": "Authentication required"
          },
          "429": {
            "description": "Rate limit exceeded"
          }
        }
      }
    },
    "/api/upload/avatar": {
      "post": {
        "operationId": "uploadUserAvatar",
        "summary": "Upload a user profile avatar to Cloudflare R2 (or local storage in dev)",
        "responses": {
          "200": {
            "description": "Uploaded avatar URL"
          },
          "400": {
            "description": "Invalid image type or size"
          },
          "401": {
            "description": "Authentication required"
          }
        }
      }
    },
    "/api/fetch-meta": {
      "get": {
        "operationId": "fetchUrlMeta",
        "summary": "Fetch OpenGraph metadata for a given URL with SSRF protection and rate limiting",
        "parameters": [
          {
            "name": "url",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uri"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Resolved URL metadata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "title": {
                      "type": "string"
                    },
                    "description": {
                      "type": "string"
                    },
                    "icon": {
                      "type": "string"
                    },
                    "ogImage": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Missing or private url parameter"
          },
          "429": {
            "description": "Rate limit exceeded"
          },
          "500": {
            "description": "Upstream metadata lookup error"
          }
        }
      }
    },
    "/api/stripe/checkout": {
      "post": {
        "operationId": "createStripeCheckout",
        "summary": "Create a Stripe Checkout session for an authenticated user",
        "responses": {
          "200": {
            "description": "Created checkout session"
          },
          "400": {
            "description": "Invalid parameters"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/stripe/webhook": {
      "post": {
        "operationId": "handleStripeWebhook",
        "summary": "Process signed Stripe webhook events",
        "responses": {
          "200": {
            "description": "Webhook processed"
          },
          "400": {
            "description": "Invalid signature"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    }
  }
}
