# priyanshmathur-28/export-sql-generator architecture

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

- Interactive diagram: https://gitdiagram.com/priyanshmathur-28/export-sql-generator
- Repository: https://github.com/priyanshmathur-28/export-sql-generator

## Overview

Export SQL Generator turns carrier/vendor specification workbooks into T-SQL. The main workflow reads and classifies workbook sheets, makes schema context searchable, generates population and supplementary-data SQL through specialist agents, then assembles and writes the final query. The graph preserves the documented formatting, multi-record, and audit capabilities. Some capabilities are documented rather than visible in the excerpts; those relationships cite the README, and unsampled implementation details are not inferred.

Main entry points: [`agents/main_orchestrator.py`](https://github.com/priyanshmathur-28/export-sql-generator/blob/main/agents/main_orchestrator.py) (Workflow orchestrator), [`tools/rag_query.py`](https://github.com/priyanshmathur-28/export-sql-generator/blob/main/tools/rag_query.py) (Schema retrieval), [`agents/epopagent.py`](https://github.com/priyanshmathur-28/export-sql-generator/blob/main/agents/epopagent.py) (Population SQL), [`tools/vector_db.py`](https://github.com/priyanshmathur-28/export-sql-generator/blob/main/tools/vector_db.py) (Schema indexing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Workbook ingestion"]
  node_orchestrator["Workflow orchestrator"]
  node_reader["Workbook reader<br/>[excel_reader.py]"]
  node_classifier["Sheet classification"]
end

subgraph group_schema["Schema retrieval"]
  node_schema_indexer["Schema indexing<br/>[vector_db.py]"]
  node_vector_store[("Schema vector index")]
  node_retrieval["Schema retrieval<br/>[rag_query.py]"]
end

subgraph group_agents["SQL synthesis"]
  node_population["Population SQL<br/>[epopagent.py]"]
  node_entity_mapping["Entity mapping<br/>[epopagent.py]"]
  node_attributes["Attribute pivots<br/>[Attragent.py]"]
  node_coverage["Coverage details<br/>[coveragent.py]"]
  node_record_format["Header/detail records<br/>[Detailagent.py]"]
  node_trailer["Trailer summaries<br/>[traileragent.py]"]
  node_assembly["SQL assembly"]
end

subgraph group_runtime["Runtime support"]
  node_launcher["Application entry<br/>[main.py]"]
  node_audit["Audit logging<br/>[log.py]"]
end

node_engineer(("Engineer"))
node_openai["OpenAI services"]
node_pinecone[("Pinecone")]

node_engineer -->|"starts run"| node_launcher
node_launcher -->|"invokes"| node_orchestrator
node_orchestrator -->|"reads workbook"| node_reader
node_orchestrator -->|"classifies sheets"| node_classifier
node_reader -.->|"provides sheet data"| node_classifier
node_orchestrator -->|"indexes schema"| node_schema_indexer
node_schema_indexer -->|"upserts embeddings"| node_vector_store
node_schema_indexer -->|"creates embeddings"| node_openai
node_schema_indexer -->|"writes vectors"| node_pinecone
node_retrieval -->|"embeds query"| node_openai
node_retrieval -->|"queries index"| node_pinecone
node_population -->|"retrieves schema"| node_retrieval
node_population -.->|"generates mapping phase"| node_entity_mapping
node_population -->|"dispatches pivots"| node_attributes
node_population -->|"dispatches coverage phase"| node_coverage
node_entity_mapping -.->|"retrieves schema"| node_retrieval
node_coverage -->|"retrieves schema"| node_retrieval
node_record_format -->|"retrieves schema"| node_retrieval
node_trailer -->|"retrieves schema"| node_retrieval
node_orchestrator -->|"runs synthesis"| node_population
node_orchestrator -->|"runs record generation"| node_record_format
node_orchestrator -->|"runs trailer generation"| node_trailer
node_orchestrator -->|"assembles SQL"| node_assembly
node_assembly -->|"delivers T-SQL"| node_engineer
node_orchestrator -.->|"records run activity"| node_audit

click node_launcher "https://github.com/priyanshmathur-28/export-sql-generator/blob/main/main.py"
click node_orchestrator "https://github.com/priyanshmathur-28/export-sql-generator/blob/main/agents/main_orchestrator.py"
click node_reader "https://github.com/priyanshmathur-28/export-sql-generator/blob/main/tools/excel_reader.py"
click node_classifier "https://github.com/priyanshmathur-28/export-sql-generator/blob/main/agents/main_orchestrator.py"
click node_schema_indexer "https://github.com/priyanshmathur-28/export-sql-generator/blob/main/tools/vector_db.py"
click node_retrieval "https://github.com/priyanshmathur-28/export-sql-generator/blob/main/tools/rag_query.py"
click node_population "https://github.com/priyanshmathur-28/export-sql-generator/blob/main/agents/epopagent.py"
click node_entity_mapping "https://github.com/priyanshmathur-28/export-sql-generator/blob/main/agents/epopagent.py"
click node_attributes "https://github.com/priyanshmathur-28/export-sql-generator/blob/main/agents/Attragent.py"
click node_coverage "https://github.com/priyanshmathur-28/export-sql-generator/blob/main/agents/coveragent.py"
click node_record_format "https://github.com/priyanshmathur-28/export-sql-generator/blob/main/agents/Detailagent.py"
click node_trailer "https://github.com/priyanshmathur-28/export-sql-generator/blob/main/agents/traileragent.py"
click node_assembly "https://github.com/priyanshmathur-28/export-sql-generator/blob/main/agents/main_orchestrator.py"
click node_audit "https://github.com/priyanshmathur-28/export-sql-generator/blob/main/utils/log.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_orchestrator,node_reader,node_classifier toneBlue
class node_schema_indexer,node_vector_store,node_retrieval,node_pinecone toneAmber
class node_population,node_entity_mapping,node_attributes,node_coverage,node_record_format,node_trailer,node_assembly toneMint
class node_launcher,node_audit toneRose
class node_engineer,node_openai toneIndigo
```

## Components

### Workbook ingestion

- [Workflow orchestrator](https://github.com/priyanshmathur-28/export-sql-generator/blob/main/agents/main_orchestrator.py): `agents/main_orchestrator.py`
- [Workbook reader](https://github.com/priyanshmathur-28/export-sql-generator/blob/main/tools/excel_reader.py): `tools/excel_reader.py`
- [Sheet classification](https://github.com/priyanshmathur-28/export-sql-generator/blob/main/agents/main_orchestrator.py): `agents/main_orchestrator.py`

### Schema retrieval

- [Schema indexing](https://github.com/priyanshmathur-28/export-sql-generator/blob/main/tools/vector_db.py): `tools/vector_db.py`
- **Schema vector index**
- [Schema retrieval](https://github.com/priyanshmathur-28/export-sql-generator/blob/main/tools/rag_query.py): `tools/rag_query.py`

### SQL synthesis

- [Population SQL](https://github.com/priyanshmathur-28/export-sql-generator/blob/main/agents/epopagent.py): `agents/epopagent.py`
- [Entity mapping](https://github.com/priyanshmathur-28/export-sql-generator/blob/main/agents/epopagent.py): `agents/epopagent.py`
- [Attribute pivots](https://github.com/priyanshmathur-28/export-sql-generator/blob/main/agents/Attragent.py): `agents/Attragent.py`
- [Coverage details](https://github.com/priyanshmathur-28/export-sql-generator/blob/main/agents/coveragent.py): `agents/coveragent.py`
- [Header/detail records](https://github.com/priyanshmathur-28/export-sql-generator/blob/main/agents/Detailagent.py): `agents/Detailagent.py`
- [Trailer summaries](https://github.com/priyanshmathur-28/export-sql-generator/blob/main/agents/traileragent.py): `agents/traileragent.py`
- [SQL assembly](https://github.com/priyanshmathur-28/export-sql-generator/blob/main/agents/main_orchestrator.py): `agents/main_orchestrator.py`

### Runtime support

- [Application entry](https://github.com/priyanshmathur-28/export-sql-generator/blob/main/main.py): `main.py`
- [Audit logging](https://github.com/priyanshmathur-28/export-sql-generator/blob/main/utils/log.py): `utils/log.py`

### Other components

- **Engineer**
- **OpenAI services**
- **Pinecone**

## Connections

- Engineer → Application entry: starts run (evidence: `README.md`)
- Application entry → Workflow orchestrator: invokes (evidence: `main.py`)
- Workflow orchestrator → Workbook reader: reads workbook (evidence: `agents/main_orchestrator.py`)
- Workflow orchestrator → Sheet classification: classifies sheets (evidence: `agents/main_orchestrator.py`)
- Workbook reader → Sheet classification: provides sheet data (evidence: `README.md`)
- Workflow orchestrator → Schema indexing: indexes schema (evidence: `agents/main_orchestrator.py`)
- Schema indexing → Schema vector index: upserts embeddings (evidence: `tools/vector_db.py`)
- Schema indexing → OpenAI services: creates embeddings (evidence: `tools/vector_db.py`)
- Schema indexing → Pinecone: writes vectors (evidence: `tools/vector_db.py`)
- Schema retrieval → OpenAI services: embeds query (evidence: `tools/rag_query.py`)
- Schema retrieval → Pinecone: queries index (evidence: `tools/rag_query.py`)
- Population SQL → Schema retrieval: retrieves schema (evidence: `agents/epopagent.py`)
- Population SQL → Entity mapping: generates mapping phase (evidence: `agents/epopagent.py`)
- Population SQL → Attribute pivots: dispatches pivots (evidence: `agents/epopagent.py`)
- Population SQL → Coverage details: dispatches coverage phase (evidence: `agents/epopagent.py`)
- Entity mapping → Schema retrieval: retrieves schema (evidence: `agents/epopagent.py`)
- Coverage details → Schema retrieval: retrieves schema (evidence: `agents/coveragent.py`)
- Header/detail records → Schema retrieval: retrieves schema (evidence: `agents/Detailagent.py`)
- Trailer summaries → Schema retrieval: retrieves schema (evidence: `agents/traileragent.py`)
- Workflow orchestrator → Population SQL: runs synthesis (evidence: `agents/main_orchestrator.py`)
- Workflow orchestrator → Header/detail records: runs record generation (evidence: `agents/main_orchestrator.py`)
- Workflow orchestrator → Trailer summaries: runs trailer generation (evidence: `agents/main_orchestrator.py`)
- Workflow orchestrator → SQL assembly: assembles SQL (evidence: `README.md`)
- SQL assembly → Engineer: delivers T-SQL (evidence: `README.md`)
- Workflow orchestrator → Audit logging: records run activity
