# lohitkolluri/nlp2sql architecture

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

- Interactive diagram: https://gitdiagram.com/lohitkolluri/nlp2sql
- Repository: https://github.com/lohitkolluri/nlp2sql

## Overview

NLP2SQL is a Streamlit application that turns natural-language questions into SQL, runs queries against SQLite or PostgreSQL, and presents analysis and visualizations. The README documents validation, decision logs, multimodal input, query history, and exports; these are included as product capabilities, though their implementation details are not all visible in the excerpts. The main app excerpt is partial, so some workflow links rely on the README rather than inspected call sites.

Main entry points: [`app/NLP2SQL.py`](https://github.com/lohitkolluri/nlp2sql/blob/v2/app/NLP2SQL.py) (SQL generation), [`src/database/DB_Config.py`](https://github.com/lohitkolluri/nlp2sql/blob/v2/src/database/DB_Config.py) (Query execution), [`src/api/LLM_Config.py`](https://github.com/lohitkolluri/nlp2sql/blob/v2/src/api/LLM_Config.py) (Provider routing), [`src/prompts/Base_Prompt.py`](https://github.com/lohitkolluri/nlp2sql/blob/v2/src/prompts/Base_Prompt.py) (SQL prompt)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_app["Streamlit application<br/>[NLP2SQL.py]"]
  node_input["Text and image input<br/>[NLP2SQL.py]"]
  node_history["Query history and export<br/>[NLP2SQL.py]"]
end

subgraph group_generation["Query generation"]
  node_prompt["SQL prompt<br/>[Base_Prompt.py]"]
  node_generation_flow["SQL generation<br/>[NLP2SQL.py]"]
  node_llm["Provider routing<br/>[LLM_Config.py]"]
  node_validation["SQL validation<br/>[NLP2SQL.py]"]
end

subgraph group_data["Database access"]
  node_schema["Schema discovery<br/>[DB_Config.py]"]
  node_execution["Query execution<br/>[DB_Config.py]"]
end

subgraph group_results["Results and analysis"]
  node_results_view["Result display<br/>[NLP2SQL.py]"]
  node_statistics["Summary statistics<br/>[NLP2SQL.py]"]
  node_visualization["Charts and analysis<br/>[NLP2SQL.py]"]
  node_decision_log["Decision log<br/>[NLP2SQL.py]"]
end

node_user(("User"))
node_azure{{"Azure OpenAI"}}
node_gemini{{"Gemini"}}
node_database[("Selected database")]

node_user -->|"uses"| node_app
node_app -->|"offers"| node_input
node_input -->|"submits question"| node_generation_flow
node_generation_flow -->|"builds prompt"| node_prompt
node_prompt -->|"retrieves schema"| node_schema
node_generation_flow -->|"requests completion"| node_llm
node_llm -->|"routes requests"| node_azure
node_llm -->|"routes requests"| node_gemini
node_generation_flow -->|"validates SQL"| node_validation
node_validation -.->|"permits query"| node_execution
node_app -->|"runs query"| node_execution
node_execution -->|"queries"| node_database
node_execution -->|"returns rows"| node_results_view
node_results_view -->|"summarizes"| node_statistics
node_results_view -->|"renders charts"| node_visualization
node_generation_flow -->|"produces reasoning"| node_decision_log
node_app -->|"manages queries"| node_history

click node_app "https://github.com/lohitkolluri/nlp2sql/blob/v2/app/NLP2SQL.py"
click node_input "https://github.com/lohitkolluri/nlp2sql/blob/v2/app/NLP2SQL.py"
click node_history "https://github.com/lohitkolluri/nlp2sql/blob/v2/app/NLP2SQL.py"
click node_prompt "https://github.com/lohitkolluri/nlp2sql/blob/v2/src/prompts/Base_Prompt.py"
click node_schema "https://github.com/lohitkolluri/nlp2sql/blob/v2/src/database/DB_Config.py"
click node_generation_flow "https://github.com/lohitkolluri/nlp2sql/blob/v2/app/NLP2SQL.py"
click node_llm "https://github.com/lohitkolluri/nlp2sql/blob/v2/src/api/LLM_Config.py"
click node_validation "https://github.com/lohitkolluri/nlp2sql/blob/v2/app/NLP2SQL.py"
click node_execution "https://github.com/lohitkolluri/nlp2sql/blob/v2/src/database/DB_Config.py"
click node_results_view "https://github.com/lohitkolluri/nlp2sql/blob/v2/app/NLP2SQL.py"
click node_statistics "https://github.com/lohitkolluri/nlp2sql/blob/v2/app/NLP2SQL.py"
click node_visualization "https://github.com/lohitkolluri/nlp2sql/blob/v2/app/NLP2SQL.py"
click node_decision_log "https://github.com/lohitkolluri/nlp2sql/blob/v2/app/NLP2SQL.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_input,node_history,node_user toneBlue
class node_prompt,node_generation_flow,node_llm,node_validation,node_database toneAmber
class node_schema,node_execution toneMint
class node_results_view,node_statistics,node_visualization,node_decision_log toneRose
class node_azure,node_gemini toneIndigo
```

## Components

### User interface

- [Streamlit application](https://github.com/lohitkolluri/nlp2sql/blob/v2/app/NLP2SQL.py): `app/NLP2SQL.py`
- [Text and image input](https://github.com/lohitkolluri/nlp2sql/blob/v2/app/NLP2SQL.py): `app/NLP2SQL.py`
- [Query history and export](https://github.com/lohitkolluri/nlp2sql/blob/v2/app/NLP2SQL.py): `app/NLP2SQL.py`

### Query generation

- [SQL prompt](https://github.com/lohitkolluri/nlp2sql/blob/v2/src/prompts/Base_Prompt.py): `src/prompts/Base_Prompt.py`
- [SQL generation](https://github.com/lohitkolluri/nlp2sql/blob/v2/app/NLP2SQL.py): `app/NLP2SQL.py`
- [Provider routing](https://github.com/lohitkolluri/nlp2sql/blob/v2/src/api/LLM_Config.py): `src/api/LLM_Config.py`
- [SQL validation](https://github.com/lohitkolluri/nlp2sql/blob/v2/app/NLP2SQL.py): `app/NLP2SQL.py`

### Database access

- [Schema discovery](https://github.com/lohitkolluri/nlp2sql/blob/v2/src/database/DB_Config.py): `src/database/DB_Config.py`
- [Query execution](https://github.com/lohitkolluri/nlp2sql/blob/v2/src/database/DB_Config.py): `src/database/DB_Config.py`

### Results and analysis

- [Result display](https://github.com/lohitkolluri/nlp2sql/blob/v2/app/NLP2SQL.py): `app/NLP2SQL.py`
- [Summary statistics](https://github.com/lohitkolluri/nlp2sql/blob/v2/app/NLP2SQL.py): `app/NLP2SQL.py`
- [Charts and analysis](https://github.com/lohitkolluri/nlp2sql/blob/v2/app/NLP2SQL.py): `app/NLP2SQL.py`
- [Decision log](https://github.com/lohitkolluri/nlp2sql/blob/v2/app/NLP2SQL.py): `app/NLP2SQL.py`

### Other components

- **User**
- **Azure OpenAI**
- **Gemini**
- **Selected database**

## Connections

- User → Streamlit application: uses (evidence: `README.md`)
- Streamlit application → Text and image input: offers (evidence: `README.md`)
- Text and image input → SQL generation: submits question (evidence: `README.md`)
- SQL generation → SQL prompt: builds prompt (evidence: `src/prompts/Base_Prompt.py`)
- SQL prompt → Schema discovery: retrieves schema (evidence: `src/prompts/Base_Prompt.py`)
- SQL generation → Provider routing: requests completion (evidence: `app/NLP2SQL.py`)
- Provider routing → Azure OpenAI: routes requests (evidence: `src/api/LLM_Config.py`)
- Provider routing → Gemini: routes requests (evidence: `src/api/LLM_Config.py`)
- SQL generation → SQL validation: validates SQL (evidence: `app/NLP2SQL.py`)
- SQL validation → Query execution: permits query (evidence: `app/NLP2SQL.py`)
- Streamlit application → Query execution: runs query (evidence: `README.md`)
- Query execution → Selected database: queries (evidence: `src/database/DB_Config.py`)
- Query execution → Result display: returns rows (evidence: `README.md`)
- Result display → Summary statistics: summarizes (evidence: `README.md`)
- Result display → Charts and analysis: renders charts (evidence: `README.md`)
- SQL generation → Decision log: produces reasoning (evidence: `README.md`)
- Streamlit application → Query history and export: manages queries (evidence: `README.md`)
