# aditya2310-dyp/text-to-sql architecture

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

- Interactive diagram: https://gitdiagram.com/aditya2310-dyp/text-to-sql
- Repository: https://github.com/aditya2310-dyp/text-to-sql

## Overview

This is a Streamlit text-to-SQL assistant that asks for clarification when a question is ambiguous, then generates, validates, executes, and explains a query. Users can also upload tabular files, which are converted to SQLite; inferred relationships enrich the schema for querying across tables. The graph and UI hand off clarification across turns. The SQL-node implementations were not sampled, so their detailed internals are omitted; those stages and upload capabilities are included based on the README.

Main entry points: [`graph.py`](https://github.com/aditya2310-dyp/text-to-sql/blob/main/graph.py) (Workflow orchestration), [`app.py`](https://github.com/aditya2310-dyp/text-to-sql/blob/main/app.py) (Streamlit app), [`chinookdb.sqlite`](https://github.com/aditya2310-dyp/text-to-sql/blob/main/chinookdb.sqlite) (Active SQLite data), [`schema_utils.py`](https://github.com/aditya2310-dyp/text-to-sql/blob/main/schema_utils.py) (Schema extraction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["User interface"]
  node_app["Streamlit app<br/>[app.py]"]
  node_clarification["Clarification state<br/>[app.py]"]
end

subgraph group_data["Data preparation"]
  node_ingest["File ingestion<br/>[ingest.py]"]
  node_inference["Relationship inference"]
  node_database[("Active SQLite data<br/>[chinookdb.sqlite]")]
end

subgraph group_workflow["Query workflow"]
  node_graph["Workflow orchestration<br/>[graph.py]"]
  node_ambiguity["Ambiguity detection<br/>[nodes.py]"]
  node_generation["SQL generation<br/>[nodes.py]"]
  node_validation["SQL validation<br/>[nodes.py]"]
  node_execution["SQL execution<br/>[nodes.py]"]
  node_explanation["Result explanation<br/>[nodes.py]"]
end

subgraph group_support["Shared context"]
  node_schema["Schema extraction<br/>[schema_utils.py]"]
  node_state["Graph state<br/>[state.py]"]
end

node_user(("User"))

node_user -->|"asks question"| node_app
node_app -->|"invokes"| node_graph
node_app -->|"loads schema"| node_schema
node_app -->|"tracks replies"| node_clarification
node_clarification -->|"resubmits context"| node_graph
node_user -->|"uploads files"| node_ingest
node_ingest -->|"creates SQLite"| node_database
node_inference -->|"inspects tables"| node_database
node_inference -->|"enriches schema"| node_generation
node_graph -->|"routes"| node_ambiguity
node_graph -->|"routes"| node_generation
node_graph -->|"routes"| node_validation
node_graph -->|"routes"| node_execution
node_graph -->|"routes"| node_explanation
node_graph -->|"uses state"| node_state
node_schema -->|"supplies schema"| node_ambiguity
node_schema -->|"supplies schema"| node_generation
node_validation -->|"dry-runs query"| node_database
node_execution -->|"runs query"| node_database
node_graph -->|"returns result"| node_app
node_app -->|"shows answer"| node_user

click node_app "https://github.com/aditya2310-dyp/text-to-sql/blob/main/app.py"
click node_clarification "https://github.com/aditya2310-dyp/text-to-sql/blob/main/app.py"
click node_ingest "https://github.com/aditya2310-dyp/text-to-sql/blob/main/ingest.py"
click node_inference "https://github.com/aditya2310-dyp/text-to-sql/blob/main/relationship_inference.py"
click node_database "https://github.com/aditya2310-dyp/text-to-sql/blob/main/chinookdb.sqlite"
click node_schema "https://github.com/aditya2310-dyp/text-to-sql/blob/main/schema_utils.py"
click node_state "https://github.com/aditya2310-dyp/text-to-sql/blob/main/state.py"
click node_graph "https://github.com/aditya2310-dyp/text-to-sql/blob/main/graph.py"
click node_ambiguity "https://github.com/aditya2310-dyp/text-to-sql/blob/main/nodes.py"
click node_generation "https://github.com/aditya2310-dyp/text-to-sql/blob/main/nodes.py"
click node_validation "https://github.com/aditya2310-dyp/text-to-sql/blob/main/nodes.py"
click node_execution "https://github.com/aditya2310-dyp/text-to-sql/blob/main/nodes.py"
click node_explanation "https://github.com/aditya2310-dyp/text-to-sql/blob/main/nodes.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_app,node_clarification,node_user toneBlue
class node_ingest,node_inference,node_database toneAmber
class node_graph,node_ambiguity,node_generation,node_validation,node_execution,node_explanation toneMint
class node_schema,node_state toneRose
```

## Components

### User interface

- [Streamlit app](https://github.com/aditya2310-dyp/text-to-sql/blob/main/app.py): `app.py`
- [Clarification state](https://github.com/aditya2310-dyp/text-to-sql/blob/main/app.py): `app.py`

### Data preparation

- [File ingestion](https://github.com/aditya2310-dyp/text-to-sql/blob/main/ingest.py): `ingest.py`
- [Relationship inference](https://github.com/aditya2310-dyp/text-to-sql/blob/main/relationship_inference.py): `relationship_inference.py`
- [Active SQLite data](https://github.com/aditya2310-dyp/text-to-sql/blob/main/chinookdb.sqlite): `chinookdb.sqlite`

### Query workflow

- [Workflow orchestration](https://github.com/aditya2310-dyp/text-to-sql/blob/main/graph.py): `graph.py`
- [Ambiguity detection](https://github.com/aditya2310-dyp/text-to-sql/blob/main/nodes.py): `nodes.py`
- [SQL generation](https://github.com/aditya2310-dyp/text-to-sql/blob/main/nodes.py): `nodes.py`
- [SQL validation](https://github.com/aditya2310-dyp/text-to-sql/blob/main/nodes.py): `nodes.py`
- [SQL execution](https://github.com/aditya2310-dyp/text-to-sql/blob/main/nodes.py): `nodes.py`
- [Result explanation](https://github.com/aditya2310-dyp/text-to-sql/blob/main/nodes.py): `nodes.py`

### Shared context

- [Schema extraction](https://github.com/aditya2310-dyp/text-to-sql/blob/main/schema_utils.py): `schema_utils.py`
- [Graph state](https://github.com/aditya2310-dyp/text-to-sql/blob/main/state.py): `state.py`

### Other components

- **User**

## Connections

- User → Streamlit app: asks question (evidence: `README.md`)
- Streamlit app → Workflow orchestration: invokes (evidence: `app.py`)
- Streamlit app → Schema extraction: loads schema (evidence: `app.py`)
- Streamlit app → Clarification state: tracks replies (evidence: `app.py`)
- Clarification state → Workflow orchestration: resubmits context (evidence: `app.py`)
- User → File ingestion: uploads files (evidence: `README.md`)
- File ingestion → Active SQLite data: creates SQLite (evidence: `ingest.py`)
- Relationship inference → Active SQLite data: inspects tables (evidence: `relationship_inference.py`)
- Relationship inference → SQL generation: enriches schema (evidence: `README.md`)
- Workflow orchestration → Ambiguity detection: routes (evidence: `graph.py`)
- Workflow orchestration → SQL generation: routes (evidence: `graph.py`)
- Workflow orchestration → SQL validation: routes (evidence: `graph.py`)
- Workflow orchestration → SQL execution: routes (evidence: `graph.py`)
- Workflow orchestration → Result explanation: routes (evidence: `graph.py`)
- Workflow orchestration → Graph state: uses state (evidence: `graph.py`)
- Schema extraction → Ambiguity detection: supplies schema (evidence: `README.md`)
- Schema extraction → SQL generation: supplies schema (evidence: `README.md`)
- SQL validation → Active SQLite data: dry-runs query (evidence: `README.md`)
- SQL execution → Active SQLite data: runs query (evidence: `README.md`)
- Workflow orchestration → Streamlit app: returns result (evidence: `app.py`)
- Streamlit app → User: shows answer (evidence: `app.py`)
