# kashish1530/data-analytics-agent architecture

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

- Interactive diagram: https://gitdiagram.com/kashish1530/data-analytics-agent
- Repository: https://github.com/kashish1530/data-analytics-agent

## Overview

This is a Streamlit text-to-SQL analytics app: a user asks a business question, the app may clarify ambiguity, the engine builds SQL using database schema context and a Groq model, and the agent validates and executes the query against SQLite before the UI displays results. The agent also provides schema-inspection, distinct-value, and calculation tools, plus a bounded repair loop used by its question-answering flow. The README documents these capabilities; the sampled app path calls generation and query execution directly. Unshown evaluation and data-generation scripts are omitted.

Main entry points: [`agent.py`](https://github.com/kashish1530/data-analytics-agent/blob/main/agent.py) (Database agent), [`app.py`](https://github.com/kashish1530/data-analytics-agent/blob/main/app.py) (Streamlit canvas), [`engine.py`](https://github.com/kashish1530/data-analytics-agent/blob/main/engine.py) (SQL generation and cache), [`Chinook_Sqlite.sqlite`](https://github.com/kashish1530/data-analytics-agent/blob/main/Chinook_Sqlite.sqlite) (Chinook SQLite)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interaction["User interaction"]
  node_ui["Streamlit canvas<br/>[app.py]"]
  node_clarify["Ambiguity check<br/>[engine.py]"]
  node_results["Results and charts<br/>[app.py]"]
end

subgraph group_agent["Agent tools"]
  node_agent["Database agent<br/>[agent.py]"]
  node_repair["Repair loop<br/>[agent.py]"]
  node_inspect["Schema inspector<br/>[agent.py]"]
  node_distinct["Distinct-value lookup<br/>[agent.py]"]
  node_calculate["Calculator<br/>[agent.py]"]
end

subgraph group_sql["SQL engine"]
  node_validate["AST safety check<br/>[engine.py]"]
  node_execute["Read-only executor<br/>[engine.py]"]
  node_schema["Schema context<br/>[engine.py]"]
  node_generator["SQL generation and cache<br/>[engine.py]"]
end

subgraph group_data["Data and model"]
  node_sqlite[("Chinook SQLite")]
  node_groq["Groq API"]
end

node_user(("Analyst"))

node_user -->|"asks question"| node_ui
node_ui -->|"checks ambiguity"| node_clarify
node_ui -->|"requests SQL"| node_generator
node_ui -->|"runs query"| node_agent
node_agent -->|"validates SQL"| node_validate
node_agent -->|"executes SQL"| node_execute
node_execute -->|"reads rows"| node_sqlite
node_generator -->|"gets schema"| node_schema
node_schema -->|"reads metadata"| node_sqlite
node_generator -->|"requests completion"| node_groq
node_repair -->|"regenerates SQL"| node_generator
node_repair -->|"runs query tool"| node_agent
node_agent -->|"provides tool"| node_inspect
node_agent -->|"provides tool"| node_distinct
node_agent -->|"provides tool"| node_calculate
node_ui -->|"renders output"| node_results

click node_ui "https://github.com/kashish1530/data-analytics-agent/blob/main/app.py"
click node_clarify "https://github.com/kashish1530/data-analytics-agent/blob/main/engine.py"
click node_results "https://github.com/kashish1530/data-analytics-agent/blob/main/app.py"
click node_agent "https://github.com/kashish1530/data-analytics-agent/blob/main/agent.py"
click node_repair "https://github.com/kashish1530/data-analytics-agent/blob/main/agent.py"
click node_inspect "https://github.com/kashish1530/data-analytics-agent/blob/main/agent.py"
click node_distinct "https://github.com/kashish1530/data-analytics-agent/blob/main/agent.py"
click node_calculate "https://github.com/kashish1530/data-analytics-agent/blob/main/agent.py"
click node_validate "https://github.com/kashish1530/data-analytics-agent/blob/main/engine.py"
click node_execute "https://github.com/kashish1530/data-analytics-agent/blob/main/engine.py"
click node_schema "https://github.com/kashish1530/data-analytics-agent/blob/main/engine.py"
click node_generator "https://github.com/kashish1530/data-analytics-agent/blob/main/engine.py"
click node_sqlite "https://github.com/kashish1530/data-analytics-agent/blob/main/Chinook_Sqlite.sqlite"

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_ui,node_clarify,node_results toneBlue
class node_agent,node_repair,node_inspect,node_distinct,node_calculate toneAmber
class node_validate,node_execute,node_schema,node_generator toneMint
class node_sqlite,node_groq toneRose
class node_user toneIndigo
```

## Components

### User interaction

- [Streamlit canvas](https://github.com/kashish1530/data-analytics-agent/blob/main/app.py): `app.py`
- [Ambiguity check](https://github.com/kashish1530/data-analytics-agent/blob/main/engine.py): `engine.py`
- [Results and charts](https://github.com/kashish1530/data-analytics-agent/blob/main/app.py): `app.py`

### Agent tools

- [Database agent](https://github.com/kashish1530/data-analytics-agent/blob/main/agent.py): `agent.py`
- [Repair loop](https://github.com/kashish1530/data-analytics-agent/blob/main/agent.py): `agent.py`
- [Schema inspector](https://github.com/kashish1530/data-analytics-agent/blob/main/agent.py): `agent.py`
- [Distinct-value lookup](https://github.com/kashish1530/data-analytics-agent/blob/main/agent.py): `agent.py`
- [Calculator](https://github.com/kashish1530/data-analytics-agent/blob/main/agent.py): `agent.py`

### SQL engine

- [AST safety check](https://github.com/kashish1530/data-analytics-agent/blob/main/engine.py): `engine.py`
- [Read-only executor](https://github.com/kashish1530/data-analytics-agent/blob/main/engine.py): `engine.py`
- [Schema context](https://github.com/kashish1530/data-analytics-agent/blob/main/engine.py): `engine.py`
- [SQL generation and cache](https://github.com/kashish1530/data-analytics-agent/blob/main/engine.py): `engine.py`

### Data and model

- [Chinook SQLite](https://github.com/kashish1530/data-analytics-agent/blob/main/Chinook_Sqlite.sqlite): `Chinook_Sqlite.sqlite`
- **Groq API**

### Other components

- **Analyst**

## Connections

- Analyst → Streamlit canvas: asks question (evidence: `app.py`)
- Streamlit canvas → Ambiguity check: checks ambiguity (evidence: `app.py`)
- Streamlit canvas → SQL generation and cache: requests SQL (evidence: `app.py`)
- Streamlit canvas → Database agent: runs query (evidence: `app.py`)
- Database agent → AST safety check: validates SQL (evidence: `agent.py`)
- Database agent → Read-only executor: executes SQL (evidence: `agent.py`)
- Read-only executor → Chinook SQLite: reads rows (evidence: `engine.py`)
- SQL generation and cache → Schema context: gets schema (evidence: `engine.py`)
- Schema context → Chinook SQLite: reads metadata (evidence: `engine.py`)
- SQL generation and cache → Groq API: requests completion (evidence: `engine.py`)
- Repair loop → SQL generation and cache: regenerates SQL (evidence: `agent.py`)
- Repair loop → Database agent: runs query tool (evidence: `agent.py`)
- Database agent → Schema inspector: provides tool (evidence: `agent.py`)
- Database agent → Distinct-value lookup: provides tool (evidence: `agent.py`)
- Database agent → Calculator: provides tool (evidence: `agent.py`)
- Streamlit canvas → Results and charts: renders output (evidence: `app.py`)
