# jimmyu2foru18/project-1-unnesting-queries architecture

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

- Interactive diagram: https://gitdiagram.com/jimmyu2foru18/project-1-unnesting-queries
- Repository: https://github.com/jimmyu2foru18/project-1-unnesting-queries
- Video tour (about a minute): https://gitdiagram.com/jimmyu2foru18/project-1-unnesting-queries/video

## Overview

This repository demonstrates SQL-query unnesting with LLMs and compares nested versus unnested query runtimes. The main workflow builds a prompt, calls a selected LLM provider, and extracts SQL; separate scripts benchmark sample TPC-H data or an IMDb database. Prompt templates and cross-database SQL snippets are additional capabilities. The graph follows the sampled entry points and documented behavior; the IMDb setup SQL is not present in the tree.

Main entry points: [`imdb_unnesting_script.py`](https://github.com/jimmyu2foru18/project-1-unnesting-queries/blob/main/imdb_unnesting_script.py) (IMDb Benchmark), [`main.py`](https://github.com/jimmyu2foru18/project-1-unnesting-queries/blob/main/main.py) (LLM Demo), [`times.py`](https://github.com/jimmyu2foru18/project-1-unnesting-queries/blob/main/times.py) (Sample Benchmark), [`llm.py`](https://github.com/jimmyu2foru18/project-1-unnesting-queries/blob/main/llm.py) (LLM Client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_generation["Unnesting"]
  node_main["LLM Demo<br/>[main.py]"]
  node_prompt_builder["Demo Prompt<br/>[main.py]"]
  node_llm["LLM Client<br/>[llm.py]"]
end

subgraph group_benchmark["Query Benchmarking"]
  node_times["Sample Benchmark<br/>[times.py]"]
  node_sample_data["Sample Data Setup<br/>[times.py]"]
  node_query_timer["Query Timer<br/>[times.py]"]
  node_imdb_script["IMDb Benchmark"]
  node_nested_query_file["Nested Query Input<br/>[Nested_Queries.sql]"]
end

subgraph group_support["Prompt and SQL Support"]
  node_prompt_templates["Prompt Templates<br/>[prompt.py]"]
  node_database_consistency["SQL Dialect Helper"]
end

subgraph group_integrations["External Services"]
  node_duckdb[("DuckDB")]
  node_llm_providers{{"LLM Providers"}}
end

node_user(("User"))

node_user -->|"runs"| node_main
node_main -->|"builds prompt"| node_prompt_builder
node_main -->|"calls"| node_llm
node_llm -->|"sends requests"| node_llm_providers
node_main -->|"gets SQL snippet"| node_database_consistency
node_user -->|"runs"| node_times
node_times -->|"requests rewrite"| node_llm
node_times -->|"sets up"| node_sample_data
node_times -->|"times queries"| node_query_timer
node_sample_data -->|"creates tables"| node_duckdb
node_query_timer -->|"executes queries"| node_duckdb
node_user -->|"runs"| node_imdb_script
node_imdb_script -->|"reads query"| node_nested_query_file
node_imdb_script -->|"requests rewrite"| node_llm
node_imdb_script -->|"executes SQL"| node_duckdb
node_imdb_script -.->|"imports helper"| node_database_consistency

click node_main "https://github.com/jimmyu2foru18/project-1-unnesting-queries/blob/main/main.py"
click node_prompt_builder "https://github.com/jimmyu2foru18/project-1-unnesting-queries/blob/main/main.py"
click node_llm "https://github.com/jimmyu2foru18/project-1-unnesting-queries/blob/main/llm.py"
click node_prompt_templates "https://github.com/jimmyu2foru18/project-1-unnesting-queries/blob/main/prompt.py"
click node_database_consistency "https://github.com/jimmyu2foru18/project-1-unnesting-queries/blob/main/database_consistency.py"
click node_times "https://github.com/jimmyu2foru18/project-1-unnesting-queries/blob/main/times.py"
click node_sample_data "https://github.com/jimmyu2foru18/project-1-unnesting-queries/blob/main/times.py"
click node_query_timer "https://github.com/jimmyu2foru18/project-1-unnesting-queries/blob/main/times.py"
click node_imdb_script "https://github.com/jimmyu2foru18/project-1-unnesting-queries/blob/main/imdb_unnesting_script.py"
click node_nested_query_file "https://github.com/jimmyu2foru18/project-1-unnesting-queries/blob/main/Nested_Queries.sql"

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_main,node_prompt_builder,node_llm,node_user toneBlue
class node_times,node_sample_data,node_query_timer,node_imdb_script,node_nested_query_file toneAmber
class node_prompt_templates,node_database_consistency toneMint
class node_duckdb,node_llm_providers toneRose
```

## Components

### Unnesting

- [LLM Demo](https://github.com/jimmyu2foru18/project-1-unnesting-queries/blob/main/main.py): `main.py`
- [Demo Prompt](https://github.com/jimmyu2foru18/project-1-unnesting-queries/blob/main/main.py): `main.py`
- [LLM Client](https://github.com/jimmyu2foru18/project-1-unnesting-queries/blob/main/llm.py): `llm.py`

### Query Benchmarking

- [Sample Benchmark](https://github.com/jimmyu2foru18/project-1-unnesting-queries/blob/main/times.py): `times.py`
- [Sample Data Setup](https://github.com/jimmyu2foru18/project-1-unnesting-queries/blob/main/times.py): `times.py`
- [Query Timer](https://github.com/jimmyu2foru18/project-1-unnesting-queries/blob/main/times.py): `times.py`
- [IMDb Benchmark](https://github.com/jimmyu2foru18/project-1-unnesting-queries/blob/main/imdb_unnesting_script.py): `imdb_unnesting_script.py`
- [Nested Query Input](https://github.com/jimmyu2foru18/project-1-unnesting-queries/blob/main/Nested_Queries.sql): `Nested_Queries.sql`

### Prompt and SQL Support

- [Prompt Templates](https://github.com/jimmyu2foru18/project-1-unnesting-queries/blob/main/prompt.py): `prompt.py`
- [SQL Dialect Helper](https://github.com/jimmyu2foru18/project-1-unnesting-queries/blob/main/database_consistency.py): `database_consistency.py`

### External Services

- **DuckDB**
- **LLM Providers**

### Other components

- **User**

## Connections

- User → LLM Demo: runs (evidence: `README.md`)
- LLM Demo → Demo Prompt: builds prompt (evidence: `main.py`)
- LLM Demo → LLM Client: calls (evidence: `main.py`)
- LLM Client → LLM Providers: sends requests (evidence: `llm.py`)
- LLM Demo → SQL Dialect Helper: gets SQL snippet (evidence: `main.py`)
- User → Sample Benchmark: runs (evidence: `README.md`)
- Sample Benchmark → LLM Client: requests rewrite (evidence: `times.py`)
- Sample Benchmark → Sample Data Setup: sets up (evidence: `times.py`)
- Sample Benchmark → Query Timer: times queries (evidence: `times.py`)
- Sample Data Setup → DuckDB: creates tables (evidence: `times.py`)
- Query Timer → DuckDB: executes queries (evidence: `times.py`)
- User → IMDb Benchmark: runs (evidence: `README.md`)
- IMDb Benchmark → Nested Query Input: reads query (evidence: `imdb_unnesting_script.py`)
- IMDb Benchmark → LLM Client: requests rewrite (evidence: `imdb_unnesting_script.py`)
- IMDb Benchmark → DuckDB: executes SQL (evidence: `imdb_unnesting_script.py`)
- IMDb Benchmark → SQL Dialect Helper: imports helper (evidence: `imdb_unnesting_script.py`)
