# vanna-ai/vanna architecture

> Architecture diagram of the GitHub repository vanna-ai/vanna, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vanna-ai/vanna
- Repository: https://github.com/vanna-ai/vanna
- Video tour (about a minute): https://gitdiagram.com/vanna-ai/vanna/video

## Overview

#### Purpose and Entry Points
Vanna 2.0 is a Python framework for user-aware natural-language data agents: it turns questions into SQL-backed answers and streams structured UI components. Public package exports begin at `src/vanna/__init__.py`. Runnable examples are available through `src/vanna/examples/__main__.py`; server launching is exposed through `src/vanna/servers/__main__.py`. Applications typically embed Vanna into an existing FastAPI or Flask service.

#### Agent Orchestration
`Agent` is the central request orchestrator, coordinating identity, prompts, LLM calls, tool use, streaming, and recovery. Its configuration controls agent behavior and its default workflow defines the standard execution pipeline.
- `src/vanna/core/agent/agent.py`
- `src/vanna/core/agent/config.py`
- `src/vanna/core/workflow/default.py`

#### Identity, Authorization, and Request Boundaries
An incoming HTTP request is converted into a request context and resolved into a `User`; that identity propagates to tools and supports group-based authorization. Tool abstractions define executable, permission-aware capabilities and their input/result models. This is the primary security boundary between transport authentication and backend actions.
- `src/vanna/core/user/resolver.py`
- `src/vanna/core/user/request_context.py`
- `src/vanna/core/tool/base.py`

#### LLM, Context, and Memory Layer
The core defines provider-neutral LLM contracts, system prompts, enrichers, middleware, and agent memory capabilities. The agent uses these abstractions to assemble context and invoke a selected model; integrations supply concrete OpenAI, Anthropic, Azure OpenAI, Gemini, or local Ollama implementations. Vector/memory backends are independently swappable.
- `src/vanna/core/llm/base.py`
- `src/vanna/core/enricher/base.py`
- `src/vanna/capabilities/agent_memory/base.py`
- `src/vanna/integrations/openai/llm.py`

#### Tools and Data Execution
Tools translate model-directed actions into controlled operations. Built-ins include SQL execution, Python, filesystem, memory, and visualization. SQL runners form the database boundary, allowing engines such as SQLite, PostgreSQL, Snowflake, BigQuery, MySQL, and others; implementations should enforce user-aware filtering/authorization at this layer where required.
- `src/vanna/tools/run_sql.py`
- `src/vanna/capabilities/sql_runner/base.py`
- `src/vanna/integrations/sqlite/sql_runner.py`

#### Streaming API and Presentation Model
Server adapters expose chat handlers and framework routes, delivering streamed rich components rather than only text. Components represent tables, charts, status/progress, cards, and interactions; chart generation is available through Plotly integration. FastAPI and Flask are alternate HTTP runtimes, not required application hosts.
- `src/vanna/servers/base/rich_chat_handler.py`
- `src/vanna/servers/fastapi/routes.py`
- `src/vanna/components/rich/data/dataframe.py`
- `src/vanna/components/rich/data/chart.py`

#### Web Component and External Interfaces
The optional TypeScript web component consumes the backend streaming API and renders `<vanna-chat>` in arbitrary web frameworks. Its API client is the frontend/backend protocol boundary. External infrastructure is selected through integrations: LLM APIs, SQL databases, vector stores (Chroma, Pinecone, Qdrant, Weaviate, Azure Search, etc.), and local persistence/audit/storage implementations.
- `frontends/webcomponent/src/components/vanna-chat.ts`
- `frontends/webcomponent/src/services/api-client.ts`
- `src/vanna/integrations/`
- `src/vanna/integrations/local/audit.py`

#### Operational Extension Points and Compatibility
Lifecycle hooks, audit, observability, validation, storage, and recovery provide production control points around the agent workflow. Registries/component management enable composition. The `legacy` subtree and adapter preserve migration paths from Vanna 0.x, separated from the 2.0 core.
- `src/vanna/core/lifecycle/base.py`
- `src/vanna/core/observability/base.py`
- `src/vanna/core/registry.py`
- `src/vanna/legacy/adapter.py`

Main entry points: [`src/vanna/core/agent/agent.py`](https://github.com/vanna-ai/vanna/blob/main/src/vanna/core/agent/agent.py) (Agent), [`src/vanna/core/workflow/default.py`](https://github.com/vanna-ai/vanna/blob/main/src/vanna/core/workflow/default.py) (Default workflow), [`src/vanna/core/user/resolver.py`](https://github.com/vanna-ai/vanna/blob/main/src/vanna/core/user/resolver.py) (User resolver), [`src/vanna/servers/base/rich_chat_handler.py`](https://github.com/vanna-ai/vanna/blob/main/src/vanna/servers/base/rich_chat_handler.py) (Rich chat handler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Vanna Core"]
  node_package["Package exports<br/>Python package<br/>[__init__.py]"]
  node_agent_config["Agent configuration<br/>[config.py]"]
  node_agent{{"Agent<br/>request orchestrator<br/>[agent.py]"}}
  node_default_workflow["Default workflow<br/>execution pipeline<br/>[default.py]"]
  node_request_context["Request context<br/>request boundary<br/>[request_context.py]"]
  node_user_resolver["User resolver<br/>identity resolver<br/>[resolver.py]"]
  node_llm_contract["LLM contract<br/>provider interface<br/>[base.py]"]
  node_enricher["Context enrichers<br/>context interface<br/>[base.py]"]
  node_agent_memory["Agent memory<br/>memory capability<br/>[base.py]"]
end

subgraph group_execution["Execution &amp; Integrations"]
  node_tool_base{{"Tool abstractions<br/>permission-aware tools<br/>[base.py]"}}
  node_sql_tool["Run SQL tool<br/>built-in tool<br/>[run_sql.py]"]
  node_sql_runner[("SQL runner contract<br/>database boundary<br/>[base.py]")]
  node_sqlite_runner[("SQLite runner<br/>SQL integration<br/>[sql_runner.py]")]
  node_integrations["Integration catalog<br/>backend integrations"]
  node_openai_llm["OpenAI LLM<br/>LLM integration<br/>[llm.py]"]
end

subgraph group_server["Streaming Delivery"]
  node_rich_chat_handler["Rich chat handler<br/>streaming handler"]
  node_fastapi_routes["FastAPI routes<br/>HTTP adapter<br/>[routes.py]"]
  node_rich_components["Rich data components<br/>presentation model<br/>[dataframe.py]"]
  node_chart_component["Chart component<br/>rich component<br/>[chart.py]"]
end

subgraph group_frontend["Optional Web Client"]
  node_web_client["vanna-chat<br/>web component<br/>[vanna-chat.ts]"]
  node_api_client["API client<br/>frontend protocol client<br/>[api-client.ts]"]
end

subgraph group_operations["Operations &amp; Compatibility"]
  node_operations["Lifecycle &amp; observability<br/>operational hooks<br/>[base.py]"]
  node_registry["Registry<br/>[registry.py]"]
  node_legacy_adapter["Legacy adapter<br/>compatibility layer<br/>[adapter.py]"]
end

node_package -->|"exports"| node_agent
node_agent_config -->|"configures"| node_agent
node_agent -->|"runs"| node_default_workflow
node_request_context -->|"resolves identity"| node_user_resolver
node_user_resolver -->|"supplies user"| node_agent
node_default_workflow -->|"builds context"| node_enricher
node_enricher -->|"uses"| node_agent_memory
node_default_workflow -->|"invokes"| node_llm_contract
node_openai_llm -->|"implements"| node_llm_contract
node_integrations -.->|"includes"| node_openai_llm
node_default_workflow -->|"executes tools"| node_tool_base
node_user_resolver -->|"authorizes actions"| node_tool_base
node_sql_tool -->|"implements"| node_tool_base
node_sql_tool -->|"queries through"| node_sql_runner
node_sqlite_runner -->|"implements"| node_sql_runner
node_integrations -.->|"includes"| node_sqlite_runner
node_agent -->|"streams responses"| node_rich_chat_handler
node_fastapi_routes -->|"exposes"| node_rich_chat_handler
node_rich_chat_handler -->|"emits"| node_rich_components
node_chart_component -->|"extends"| node_rich_components
node_web_client -->|"uses"| node_api_client
node_api_client -->|"streams with"| node_fastapi_routes
node_operations -.->|"hooks around"| node_agent
node_registry -.->|"composes"| node_agent
node_legacy_adapter -.->|"migrates to"| node_agent

click node_package "https://github.com/vanna-ai/vanna/blob/main/src/vanna/__init__.py"
click node_agent_config "https://github.com/vanna-ai/vanna/blob/main/src/vanna/core/agent/config.py"
click node_agent "https://github.com/vanna-ai/vanna/blob/main/src/vanna/core/agent/agent.py"
click node_default_workflow "https://github.com/vanna-ai/vanna/blob/main/src/vanna/core/workflow/default.py"
click node_request_context "https://github.com/vanna-ai/vanna/blob/main/src/vanna/core/user/request_context.py"
click node_user_resolver "https://github.com/vanna-ai/vanna/blob/main/src/vanna/core/user/resolver.py"
click node_llm_contract "https://github.com/vanna-ai/vanna/blob/main/src/vanna/core/llm/base.py"
click node_enricher "https://github.com/vanna-ai/vanna/blob/main/src/vanna/core/enricher/base.py"
click node_agent_memory "https://github.com/vanna-ai/vanna/blob/main/src/vanna/capabilities/agent_memory/base.py"
click node_tool_base "https://github.com/vanna-ai/vanna/blob/main/src/vanna/core/tool/base.py"
click node_sql_tool "https://github.com/vanna-ai/vanna/blob/main/src/vanna/tools/run_sql.py"
click node_sql_runner "https://github.com/vanna-ai/vanna/blob/main/src/vanna/capabilities/sql_runner/base.py"
click node_sqlite_runner "https://github.com/vanna-ai/vanna/blob/main/src/vanna/integrations/sqlite/sql_runner.py"
click node_openai_llm "https://github.com/vanna-ai/vanna/blob/main/src/vanna/integrations/openai/llm.py"
click node_rich_chat_handler "https://github.com/vanna-ai/vanna/blob/main/src/vanna/servers/base/rich_chat_handler.py"
click node_fastapi_routes "https://github.com/vanna-ai/vanna/blob/main/src/vanna/servers/fastapi/routes.py"
click node_rich_components "https://github.com/vanna-ai/vanna/blob/main/src/vanna/components/rich/data/dataframe.py"
click node_chart_component "https://github.com/vanna-ai/vanna/blob/main/src/vanna/components/rich/data/chart.py"
click node_web_client "https://github.com/vanna-ai/vanna/blob/main/frontends/webcomponent/src/components/vanna-chat.ts"
click node_api_client "https://github.com/vanna-ai/vanna/blob/main/frontends/webcomponent/src/services/api-client.ts"
click node_operations "https://github.com/vanna-ai/vanna/blob/main/src/vanna/core/lifecycle/base.py"
click node_registry "https://github.com/vanna-ai/vanna/blob/main/src/vanna/core/registry.py"
click node_legacy_adapter "https://github.com/vanna-ai/vanna/blob/main/src/vanna/legacy/adapter.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_package,node_agent_config,node_agent,node_default_workflow,node_request_context,node_user_resolver,node_llm_contract,node_enricher,node_agent_memory toneBlue
class node_tool_base,node_sql_tool,node_sql_runner,node_sqlite_runner,node_integrations,node_openai_llm toneAmber
class node_rich_chat_handler,node_fastapi_routes,node_rich_components,node_chart_component toneMint
class node_web_client,node_api_client toneRose
class node_operations,node_registry,node_legacy_adapter toneIndigo
```

## Components

### Vanna Core

Framework contracts and agent workflow.

- [Package exports](https://github.com/vanna-ai/vanna/blob/main/src/vanna/__init__.py): Python package · `src/vanna/__init__.py`
- [Agent configuration](https://github.com/vanna-ai/vanna/blob/main/src/vanna/core/agent/config.py): agent config · `src/vanna/core/agent/config.py`
- [Agent](https://github.com/vanna-ai/vanna/blob/main/src/vanna/core/agent/agent.py): request orchestrator · Coordinates identity, context, model calls, tools, streaming, and recovery. · `src/vanna/core/agent/agent.py`
- [Default workflow](https://github.com/vanna-ai/vanna/blob/main/src/vanna/core/workflow/default.py): execution pipeline · `src/vanna/core/workflow/default.py`
- [Request context](https://github.com/vanna-ai/vanna/blob/main/src/vanna/core/user/request_context.py): request boundary · `src/vanna/core/user/request_context.py`
- [User resolver](https://github.com/vanna-ai/vanna/blob/main/src/vanna/core/user/resolver.py): identity resolver · `src/vanna/core/user/resolver.py`
- [LLM contract](https://github.com/vanna-ai/vanna/blob/main/src/vanna/core/llm/base.py): provider interface · `src/vanna/core/llm/base.py`
- [Context enrichers](https://github.com/vanna-ai/vanna/blob/main/src/vanna/core/enricher/base.py): context interface · `src/vanna/core/enricher/base.py`
- [Agent memory](https://github.com/vanna-ai/vanna/blob/main/src/vanna/capabilities/agent_memory/base.py): memory capability · Swappable memory and vector backends. · `src/vanna/capabilities/agent_memory/base.py`

### Execution & Integrations

Controlled tool execution and pluggable backends.

- [Tool abstractions](https://github.com/vanna-ai/vanna/blob/main/src/vanna/core/tool/base.py): permission-aware tools · Defines executable capabilities and input/result models. · `src/vanna/core/tool/base.py`
- [Run SQL tool](https://github.com/vanna-ai/vanna/blob/main/src/vanna/tools/run_sql.py): built-in tool · `src/vanna/tools/run_sql.py`
- [SQL runner contract](https://github.com/vanna-ai/vanna/blob/main/src/vanna/capabilities/sql_runner/base.py): database boundary · Backend implementations enforce user-aware data access where needed. · `src/vanna/capabilities/sql_runner/base.py`
- [SQLite runner](https://github.com/vanna-ai/vanna/blob/main/src/vanna/integrations/sqlite/sql_runner.py): SQL integration · `src/vanna/integrations/sqlite/sql_runner.py`
- **Integration catalog**: backend integrations · Supplies LLM, SQL, vector, storage, and other concrete providers.
- [OpenAI LLM](https://github.com/vanna-ai/vanna/blob/main/src/vanna/integrations/openai/llm.py): LLM integration · `src/vanna/integrations/openai/llm.py`

### Streaming Delivery

HTTP adapters and rich response model.

- [Rich chat handler](https://github.com/vanna-ai/vanna/blob/main/src/vanna/servers/base/rich_chat_handler.py): streaming handler · Streams structured chat components. · `src/vanna/servers/base/rich_chat_handler.py`
- [FastAPI routes](https://github.com/vanna-ai/vanna/blob/main/src/vanna/servers/fastapi/routes.py): HTTP adapter · Alternate server runtime for embedding or standalone delivery. · `src/vanna/servers/fastapi/routes.py`
- [Rich data components](https://github.com/vanna-ai/vanna/blob/main/src/vanna/components/rich/data/dataframe.py): presentation model · Tables, charts, status, cards, and interactions. · `src/vanna/components/rich/data/dataframe.py`
- [Chart component](https://github.com/vanna-ai/vanna/blob/main/src/vanna/components/rich/data/chart.py): rich component · `src/vanna/components/rich/data/chart.py`

### Optional Web Client

- [vanna-chat](https://github.com/vanna-ai/vanna/blob/main/frontends/webcomponent/src/components/vanna-chat.ts): web component · Optional embeddable TypeScript chat UI. · `frontends/webcomponent/src/components/vanna-chat.ts`
- [API client](https://github.com/vanna-ai/vanna/blob/main/frontends/webcomponent/src/services/api-client.ts): frontend protocol client · Frontend/backend streaming protocol boundary. · `frontends/webcomponent/src/services/api-client.ts`

### Operations & Compatibility

Production extension points and migration support.

- [Lifecycle & observability](https://github.com/vanna-ai/vanna/blob/main/src/vanna/core/lifecycle/base.py): operational hooks · Production lifecycle, audit, validation, and recovery controls. · `src/vanna/core/lifecycle/base.py`
- [Registry](https://github.com/vanna-ai/vanna/blob/main/src/vanna/core/registry.py): composition registry · `src/vanna/core/registry.py`
- [Legacy adapter](https://github.com/vanna-ai/vanna/blob/main/src/vanna/legacy/adapter.py): compatibility layer · Separates Vanna 0.x migration paths from the 2.0 core. · `src/vanna/legacy/adapter.py`

## Connections

- Package exports → Agent: exports
- Agent configuration → Agent: configures
- Agent → Default workflow: runs
- Request context → User resolver: resolves identity
- User resolver → Agent: supplies user
- Default workflow → Context enrichers: builds context
- Context enrichers → Agent memory: uses
- Default workflow → LLM contract: invokes
- OpenAI LLM → LLM contract: implements
- Integration catalog → OpenAI LLM: includes
- Default workflow → Tool abstractions: executes tools
- User resolver → Tool abstractions: authorizes actions
- Run SQL tool → Tool abstractions: implements
- Run SQL tool → SQL runner contract: queries through
- SQLite runner → SQL runner contract: implements
- Integration catalog → SQLite runner: includes
- Agent → Rich chat handler: streams responses
- FastAPI routes → Rich chat handler: exposes
- Rich chat handler → Rich data components: emits
- Chart component → Rich data components: extends
- vanna-chat → API client: uses
- API client → FastAPI routes: streams with
- Lifecycle & observability → Agent: hooks around
- Registry → Agent: composes
- Legacy adapter → Agent: migrates to
