# nasirsaikh/vanna-ai architecture

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

- Interactive diagram: https://gitdiagram.com/nasirsaikh/vanna-ai
- Repository: https://github.com/nasirsaikh/vanna-ai

## Overview

Takaful AI Analytics is a Django platform for secure, agent-scoped natural-language analytics, with interactive queries and dashboards plus email intake and scheduled jobs. The central workflow resolves an agent and effective permissions, prepares prompts and retrieved knowledge, generates and validates SQL, executes bounded reads, and returns protected results. Agent configuration, training, schema discovery, and audit state support that workflow; mailbox and scheduler paths extend it. Several entry-point and subsystem implementations were not sampled, so those links are included only where documented or indexed.

Main entry points: [`orchestrator/services.py`](https://github.com/nasirsaikh/vanna-ai/blob/main/orchestrator/services.py) (Query orchestration), [`automation_center/email_service.py`](https://github.com/nasirsaikh/vanna-ai/blob/main/automation_center/email_service.py) (Email processing), [`automation_center/tasks.py`](https://github.com/nasirsaikh/vanna-ai/blob/main/automation_center/tasks.py) (Scheduled jobs), [`chat/views.py`](https://github.com/nasirsaikh/vanna-ai/blob/main/chat/views.py) (Interactive requests)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_query["Analytics workflow"]
  node_interactive["Interactive requests<br/>[views.py]"]
  node_orchestrator["Query orchestration<br/>[services.py]"]
  node_validator["SQL validation<br/>[validator.py]"]
  node_execution["Bounded execution<br/>[query_execution.py]"]
  node_response["Response security"]
end

subgraph group_agent["Agent and knowledge"]
  node_access["Agent access<br/>[agent_access.py]"]
  node_context["Policy context<br/>[agent_context.py]"]
  node_prompt["Prompt building<br/>[prompt_builder.py]"]
  node_providers["AI providers<br/>[llm_providers.py]"]
  node_training["Training service"]
  node_vector["Agent vector index<br/>[agent_vector.py]"]
  node_schema["Schema and policies<br/>[schema_service.py]"]
  node_audit[("Agent and audit records<br/>[models.py]")]
end

subgraph group_operations["Email and scheduling"]
  node_mailbox["Microsoft Graph<br/>[graph_client.py]"]
  node_email["Email processing<br/>[email_service.py]"]
  node_schedule["Scheduled jobs<br/>[tasks.py]"]
  node_job_records[("Job and email records<br/>[models.py]")]
end

subgraph group_presentation["Results and UI"]
  node_charts["Chart selection<br/>[services.py]"]
  node_browser["Analytics UI<br/>[console.js]"]
end

node_user(("Analyst"))

node_user -->|"asks question"| node_interactive
node_interactive -.->|"submits request"| node_orchestrator
node_orchestrator -->|"resolves agent"| node_access
node_orchestrator -->|"builds context"| node_context
node_context -.->|"reads policies"| node_audit
node_orchestrator -->|"builds prompt"| node_prompt
node_orchestrator -->|"requests generation"| node_providers
node_orchestrator -->|"retrieves knowledge"| node_vector
node_training -->|"updates index"| node_vector
node_orchestrator -.->|"loads schema"| node_schema
node_orchestrator -->|"validates SQL"| node_validator
node_orchestrator -->|"executes query"| node_execution
node_execution -.->|"records query"| node_audit
node_orchestrator -->|"secures result"| node_response
node_response -.->|"provides result"| node_charts
node_charts -.->|"renders charts"| node_browser
node_schedule -->|"processes mail"| node_email
node_email -->|"reads and replies"| node_mailbox
node_email -->|"submits analytics"| node_orchestrator
node_schedule -->|"runs analytics"| node_orchestrator
node_schedule -.->|"updates run state"| node_job_records
node_email -.->|"stores requests"| node_job_records

click node_interactive "https://github.com/nasirsaikh/vanna-ai/blob/main/chat/views.py"
click node_orchestrator "https://github.com/nasirsaikh/vanna-ai/blob/main/orchestrator/services.py"
click node_access "https://github.com/nasirsaikh/vanna-ai/blob/main/orchestrator/agent_access.py"
click node_context "https://github.com/nasirsaikh/vanna-ai/blob/main/orchestrator/agent_context.py"
click node_prompt "https://github.com/nasirsaikh/vanna-ai/blob/main/orchestrator/prompt_builder.py"
click node_providers "https://github.com/nasirsaikh/vanna-ai/blob/main/orchestrator/llm_providers.py"
click node_training "https://github.com/nasirsaikh/vanna-ai/blob/main/orchestrator/training_service.py"
click node_vector "https://github.com/nasirsaikh/vanna-ai/blob/main/orchestrator/agent_vector.py"
click node_schema "https://github.com/nasirsaikh/vanna-ai/blob/main/orchestrator/schema_service.py"
click node_validator "https://github.com/nasirsaikh/vanna-ai/blob/main/orchestrator/validator.py"
click node_execution "https://github.com/nasirsaikh/vanna-ai/blob/main/orchestrator/query_execution.py"
click node_audit "https://github.com/nasirsaikh/vanna-ai/blob/main/orchestrator/models.py"
click node_response "https://github.com/nasirsaikh/vanna-ai/blob/main/orchestrator/response_security.py"
click node_charts "https://github.com/nasirsaikh/vanna-ai/blob/main/analytics/services.py"
click node_browser "https://github.com/nasirsaikh/vanna-ai/blob/main/static/js/console.js"
click node_mailbox "https://github.com/nasirsaikh/vanna-ai/blob/main/automation_center/graph_client.py"
click node_email "https://github.com/nasirsaikh/vanna-ai/blob/main/automation_center/email_service.py"
click node_schedule "https://github.com/nasirsaikh/vanna-ai/blob/main/automation_center/tasks.py"
click node_job_records "https://github.com/nasirsaikh/vanna-ai/blob/main/automation_center/models.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_interactive,node_orchestrator,node_validator,node_execution,node_response toneBlue
class node_access,node_context,node_prompt,node_providers,node_training,node_vector,node_schema,node_audit toneAmber
class node_mailbox,node_email,node_schedule,node_job_records toneMint
class node_charts,node_browser toneRose
class node_user toneIndigo
```

## Components

### Analytics workflow

- [Interactive requests](https://github.com/nasirsaikh/vanna-ai/blob/main/chat/views.py): `chat/views.py`
- [Query orchestration](https://github.com/nasirsaikh/vanna-ai/blob/main/orchestrator/services.py): `orchestrator/services.py`
- [SQL validation](https://github.com/nasirsaikh/vanna-ai/blob/main/orchestrator/validator.py): `orchestrator/validator.py`
- [Bounded execution](https://github.com/nasirsaikh/vanna-ai/blob/main/orchestrator/query_execution.py): `orchestrator/query_execution.py`
- [Response security](https://github.com/nasirsaikh/vanna-ai/blob/main/orchestrator/response_security.py): `orchestrator/response_security.py`

### Agent and knowledge

- [Agent access](https://github.com/nasirsaikh/vanna-ai/blob/main/orchestrator/agent_access.py): `orchestrator/agent_access.py`
- [Policy context](https://github.com/nasirsaikh/vanna-ai/blob/main/orchestrator/agent_context.py): `orchestrator/agent_context.py`
- [Prompt building](https://github.com/nasirsaikh/vanna-ai/blob/main/orchestrator/prompt_builder.py): `orchestrator/prompt_builder.py`
- [AI providers](https://github.com/nasirsaikh/vanna-ai/blob/main/orchestrator/llm_providers.py): `orchestrator/llm_providers.py`
- [Training service](https://github.com/nasirsaikh/vanna-ai/blob/main/orchestrator/training_service.py): `orchestrator/training_service.py`
- [Agent vector index](https://github.com/nasirsaikh/vanna-ai/blob/main/orchestrator/agent_vector.py): `orchestrator/agent_vector.py`
- [Schema and policies](https://github.com/nasirsaikh/vanna-ai/blob/main/orchestrator/schema_service.py): `orchestrator/schema_service.py`
- [Agent and audit records](https://github.com/nasirsaikh/vanna-ai/blob/main/orchestrator/models.py): `orchestrator/models.py`

### Email and scheduling

- [Microsoft Graph](https://github.com/nasirsaikh/vanna-ai/blob/main/automation_center/graph_client.py): `automation_center/graph_client.py`
- [Email processing](https://github.com/nasirsaikh/vanna-ai/blob/main/automation_center/email_service.py): `automation_center/email_service.py`
- [Scheduled jobs](https://github.com/nasirsaikh/vanna-ai/blob/main/automation_center/tasks.py): `automation_center/tasks.py`
- [Job and email records](https://github.com/nasirsaikh/vanna-ai/blob/main/automation_center/models.py): `automation_center/models.py`

### Results and UI

- [Chart selection](https://github.com/nasirsaikh/vanna-ai/blob/main/analytics/services.py): `analytics/services.py`
- [Analytics UI](https://github.com/nasirsaikh/vanna-ai/blob/main/static/js/console.js): `static/js/console.js`

### Other components

- **Analyst**

## Connections

- Analyst → Interactive requests: asks question
- Interactive requests → Query orchestration: submits request
- Query orchestration → Agent access: resolves agent (evidence: `orchestrator/services.py`)
- Query orchestration → Policy context: builds context (evidence: `orchestrator/services.py`)
- Policy context → Agent and audit records: reads policies
- Query orchestration → Prompt building: builds prompt (evidence: `orchestrator/services.py`)
- Query orchestration → AI providers: requests generation (evidence: `orchestrator/services.py`)
- Query orchestration → Agent vector index: retrieves knowledge (evidence: `orchestrator/services.py`)
- Training service → Agent vector index: updates index (evidence: `orchestrator/training_service.py`)
- Query orchestration → Schema and policies: loads schema
- Query orchestration → SQL validation: validates SQL (evidence: `orchestrator/services.py`)
- Query orchestration → Bounded execution: executes query (evidence: `orchestrator/services.py`)
- Bounded execution → Agent and audit records: records query
- Query orchestration → Response security: secures result (evidence: `orchestrator/services.py`)
- Response security → Chart selection: provides result
- Chart selection → Analytics UI: renders charts
- Scheduled jobs → Email processing: processes mail (evidence: `automation_center/tasks.py`)
- Email processing → Microsoft Graph: reads and replies (evidence: `automation_center/email_service.py`)
- Email processing → Query orchestration: submits analytics (evidence: `automation_center/email_service.py`)
- Scheduled jobs → Query orchestration: runs analytics
- Scheduled jobs → Job and email records: updates run state (evidence: `automation_center/tasks.py`)
- Email processing → Job and email records: stores requests (evidence: `automation_center/email_service.py`)
