{
  "openapi": "3.0.3",
  "info": {
    "title": "Zdravo AI API",
    "version": "2.0.0",
    "description": "Universal AI Memory Layer API. Store, search, and manage memories across AI platforms.",
    "contact": {
      "name": "Zdravo AI",
      "email": "api@zdravo.ai",
      "url": "https://zdravo.ai"
    },
    "license": {
      "name": "Proprietary",
      "url": "https://zdravo.ai/terms"
    }
  },
  "servers": [
    {
      "url": "https://zdravo.ai",
      "description": "Production"
    },
    {
      "url": "https://staging.zdravo.ai",
      "description": "Staging"
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    },
    {
      "BearerAuth": []
    }
  ],
  "paths": {
    "/api/v1/memories": {
      "get": {
        "summary": "List memories",
        "description": "Retrieve paginated list of memories for the authenticated user.",
        "tags": [
          "Memories"
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "maximum": 100
            }
          },
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "semantic",
                "episodic",
                "procedural",
                "working",
                "emotional"
              ]
            }
          },
          {
            "name": "pinned",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Memory"
                      }
                    },
                    "pagination": {
                      "$ref": "#/components/schemas/Pagination"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          }
        }
      },
      "post": {
        "summary": "Create memory",
        "description": "Create a new memory with content, tags, and metadata.",
        "tags": [
          "Memories"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateMemoryRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Memory"
                }
              }
            }
          },
          "400": {
            "description": "Validation error"
          },
          "401": {
            "description": "Unauthorized"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/api/v1/memories/{id}": {
      "get": {
        "summary": "Get memory",
        "description": "Retrieve a single memory by ID.",
        "tags": [
          "Memories"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Memory"
                }
              }
            }
          },
          "404": {
            "description": "Not found"
          }
        }
      },
      "delete": {
        "summary": "Delete memory",
        "description": "Soft-delete a memory.",
        "tags": [
          "Memories"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/api/v1/memories/search": {
      "post": {
        "summary": "Hybrid search",
        "description": "Search memories using vector similarity, keyword matching, and graph topology.",
        "tags": [
          "Search"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "query"
                ],
                "properties": {
                  "query": {
                    "type": "string"
                  },
                  "limit": {
                    "type": "integer",
                    "default": 20
                  },
                  "rerank": {
                    "type": "boolean",
                    "default": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "results": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/SearchResult"
                      }
                    },
                    "total": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/memories/export": {
      "get": {
        "summary": "Export memories",
        "description": "Download all memories in JSON or Markdown format.",
        "tags": [
          "Export"
        ],
        "parameters": [
          {
            "name": "format",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "json",
                "markdown"
              ],
              "default": "json"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "File download",
            "content": {
              "application/json": {},
              "text/markdown": {}
            }
          }
        }
      }
    },
    "/api/v1/teams": {
      "get": {
        "summary": "List teams",
        "description": "Get all teams the user belongs to.",
        "tags": [
          "Teams"
        ],
        "responses": {
          "200": {
            "description": "Success"
          }
        }
      },
      "post": {
        "summary": "Create team",
        "description": "Create a new organization.",
        "tags": [
          "Teams"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created"
          }
        }
      }
    },
    "/api/v1/teams/{id}/members": {
      "get": {
        "summary": "List team members",
        "description": "Get all members of a team.",
        "tags": [
          "Teams"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          }
        }
      },
      "post": {
        "summary": "Invite member",
        "description": "Invite a user to the team.",
        "tags": [
          "Teams"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "role": {
                    "type": "string",
                    "enum": [
                      "admin",
                      "member",
                      "viewer"
                    ],
                    "default": "member"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Invited"
          }
        }
      }
    },
    "/api/health": {
      "get": {
        "summary": "Health check",
        "description": "System health status for all components.",
        "tags": [
          "System"
        ],
        "responses": {
          "200": {
            "description": "Healthy",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthStatus"
                }
              }
            }
          },
          "503": {
            "description": "Unhealthy"
          }
        }
      }
    },
    "/api/sse/updates": {
      "get": {
        "summary": "Real-time updates",
        "description": "Server-Sent Events stream for real-time team notifications.",
        "tags": [
          "Realtime"
        ],
        "responses": {
          "200": {
            "description": "Event stream",
            "content": {
              "text/event-stream": {}
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "API key from settings page"
      },
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "Supabase session token"
      }
    },
    "schemas": {
      "Memory": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "title": {
            "type": "string"
          },
          "content": {
            "type": "string"
          },
          "memory_type": {
            "type": "string",
            "enum": [
              "semantic",
              "episodic",
              "procedural",
              "working",
              "emotional"
            ]
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "confidence_score": {
            "type": "number",
            "minimum": 0,
            "maximum": 100
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CreateMemoryRequest": {
        "type": "object",
        "required": [
          "content"
        ],
        "properties": {
          "content": {
            "type": "string",
            "minLength": 10
          },
          "title": {
            "type": "string"
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "metadata": {
            "type": "object"
          }
        }
      },
      "SearchResult": {
        "type": "object",
        "properties": {
          "memory": {
            "$ref": "#/components/schemas/Memory"
          },
          "scores": {
            "type": "object",
            "properties": {
              "vector": {
                "type": "number"
              },
              "keyword": {
                "type": "number"
              },
              "hybrid": {
                "type": "number"
              }
            }
          },
          "highlights": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "Pagination": {
        "type": "object",
        "properties": {
          "page": {
            "type": "integer"
          },
          "limit": {
            "type": "integer"
          },
          "total": {
            "type": "integer"
          },
          "totalPages": {
            "type": "integer"
          }
        }
      },
      "HealthStatus": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "healthy",
              "degraded",
              "unhealthy"
            ]
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          },
          "uptime": {
            "type": "integer"
          },
          "checks": {
            "type": "object"
          }
        }
      }
    }
  }
}