# definitive-io/duckdb-text2sql architecture

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

- Interactive diagram: https://gitdiagram.com/definitive-io/duckdb-text2sql
- Repository: https://github.com/definitive-io/duckdb-text2sql

## Overview

DuckDB Query Generator is a Streamlit question-to-SQL app: a user asks about CSV-backed data, Groq generates DuckDB SQL, the app parses and executes it, and Groq summarizes results. The workflow and customization, correction, and summarization stages are visible in app.py; the base prompt and CSV inputs are documented. The excerpts do not establish the prompt’s exact contents or explicit file-reading behavior inside DuckDB, so those data links are documented rather than inferred from implementation.

Main entry points: [`app.py`](https://github.com/definitive-io/duckdb-text2sql/blob/main/app.py) (Streamlit workflow), [`data/employees.csv`](https://github.com/definitive-io/duckdb-text2sql/blob/main/data/employees.csv) (Employee CSV), [`data/purchases.csv`](https://github.com/definitive-io/duckdb-text2sql/blob/main/data/purchases.csv) (Purchase CSV), [`prompts/base_prompt.txt`](https://github.com/definitive-io/duckdb-text2sql/blob/main/prompts/base_prompt.txt) (Base prompt)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["App workflow"]
  node_app["Streamlit workflow<br/>[app.py]"]
  node_custom["Model and context options<br/>[app.py]"]
  node_summary["Result summarization<br/>[app.py]"]
end

subgraph group_generation["AI generation"]
  node_prompt["Base prompt<br/>[base_prompt.txt]"]
  node_groq["Groq API"]
  node_response["Response parsing<br/>[app.py]"]
  node_reflection["SQL correction<br/>[app.py]"]
end

subgraph group_query["Query execution"]
  node_sql["Generated SQL<br/>[app.py]"]
  node_executor["DuckDB executor<br/>[app.py]"]
  node_duckdb[("In-memory DuckDB<br/>[app.py]")]
  node_results["Query results<br/>[app.py]"]
end

subgraph group_inputs["Data and prompts"]
  node_employees["Employee CSV<br/>[employees.csv]"]
  node_purchases["Purchase CSV<br/>[purchases.csv]"]
end

node_user(("Question asker"))

node_user -->|"asks question"| node_app
node_app -->|"configures"| node_custom
node_app -->|"loads"| node_prompt
node_app -->|"requests SQL"| node_groq
node_app -->|"parses reply"| node_response
node_response -->|"extracts SQL"| node_sql
node_app -->|"executes query"| node_executor
node_executor -->|"runs SQL"| node_duckdb
node_app -->|"requests correction"| node_reflection
node_reflection -->|"sends correction"| node_groq
node_executor -->|"returns rows"| node_results
node_app -->|"summarizes results"| node_summary
node_summary -->|"requests summary"| node_groq
node_summary -->|"uses rows"| node_results
node_app -->|"displays answer"| node_user
node_employees -.->|"queried as data"| node_duckdb
node_purchases -.->|"queried as data"| node_duckdb

click node_app "https://github.com/definitive-io/duckdb-text2sql/blob/main/app.py"
click node_custom "https://github.com/definitive-io/duckdb-text2sql/blob/main/app.py"
click node_prompt "https://github.com/definitive-io/duckdb-text2sql/blob/main/prompts/base_prompt.txt"
click node_response "https://github.com/definitive-io/duckdb-text2sql/blob/main/app.py"
click node_reflection "https://github.com/definitive-io/duckdb-text2sql/blob/main/app.py"
click node_sql "https://github.com/definitive-io/duckdb-text2sql/blob/main/app.py"
click node_executor "https://github.com/definitive-io/duckdb-text2sql/blob/main/app.py"
click node_duckdb "https://github.com/definitive-io/duckdb-text2sql/blob/main/app.py"
click node_employees "https://github.com/definitive-io/duckdb-text2sql/blob/main/data/employees.csv"
click node_purchases "https://github.com/definitive-io/duckdb-text2sql/blob/main/data/purchases.csv"
click node_summary "https://github.com/definitive-io/duckdb-text2sql/blob/main/app.py"
click node_results "https://github.com/definitive-io/duckdb-text2sql/blob/main/app.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_custom,node_summary toneBlue
class node_prompt,node_groq,node_response,node_reflection toneAmber
class node_sql,node_executor,node_duckdb,node_results toneMint
class node_employees,node_purchases toneRose
class node_user toneIndigo
```

## Components

### App workflow

- [Streamlit workflow](https://github.com/definitive-io/duckdb-text2sql/blob/main/app.py): `app.py`
- [Model and context options](https://github.com/definitive-io/duckdb-text2sql/blob/main/app.py): `app.py`
- [Result summarization](https://github.com/definitive-io/duckdb-text2sql/blob/main/app.py): `app.py`

### AI generation

- [Base prompt](https://github.com/definitive-io/duckdb-text2sql/blob/main/prompts/base_prompt.txt): `prompts/base_prompt.txt`
- **Groq API**
- [Response parsing](https://github.com/definitive-io/duckdb-text2sql/blob/main/app.py): `app.py`
- [SQL correction](https://github.com/definitive-io/duckdb-text2sql/blob/main/app.py): `app.py`

### Query execution

- [Generated SQL](https://github.com/definitive-io/duckdb-text2sql/blob/main/app.py): `app.py`
- [DuckDB executor](https://github.com/definitive-io/duckdb-text2sql/blob/main/app.py): `app.py`
- [In-memory DuckDB](https://github.com/definitive-io/duckdb-text2sql/blob/main/app.py): `app.py`
- [Query results](https://github.com/definitive-io/duckdb-text2sql/blob/main/app.py): `app.py`

### Data and prompts

- [Employee CSV](https://github.com/definitive-io/duckdb-text2sql/blob/main/data/employees.csv): `data/employees.csv`
- [Purchase CSV](https://github.com/definitive-io/duckdb-text2sql/blob/main/data/purchases.csv): `data/purchases.csv`

### Other components

- **Question asker**

## Connections

- Question asker → Streamlit workflow: asks question (evidence: `app.py`)
- Streamlit workflow → Model and context options: configures (evidence: `app.py`)
- Streamlit workflow → Base prompt: loads (evidence: `app.py`)
- Streamlit workflow → Groq API: requests SQL (evidence: `app.py`)
- Streamlit workflow → Response parsing: parses reply (evidence: `app.py`)
- Response parsing → Generated SQL: extracts SQL (evidence: `app.py`)
- Streamlit workflow → DuckDB executor: executes query (evidence: `app.py`)
- DuckDB executor → In-memory DuckDB: runs SQL (evidence: `app.py`)
- Streamlit workflow → SQL correction: requests correction (evidence: `app.py`)
- SQL correction → Groq API: sends correction (evidence: `app.py`)
- DuckDB executor → Query results: returns rows (evidence: `app.py`)
- Streamlit workflow → Result summarization: summarizes results (evidence: `app.py`)
- Result summarization → Groq API: requests summary (evidence: `app.py`)
- Result summarization → Query results: uses rows (evidence: `app.py`)
- Streamlit workflow → Question asker: displays answer (evidence: `app.py`)
- Employee CSV → In-memory DuckDB: queried as data (evidence: `README.md`)
- Purchase CSV → In-memory DuckDB: queried as data (evidence: `README.md`)
