# eisoptrophobicc/data-intel architecture

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

- Interactive diagram: https://gitdiagram.com/eisoptrophobicc/data-intel
- Repository: https://github.com/eisoptrophobicc/data-intel

## Overview

1. This repo is a two-tier conversational BI system: a Python backend does dataset ingestion, intent-to-SQL translation, query execution, and result shaping; a Next.js frontend provides the user-facing UI and lightweight API routes.

2. The backend is the architectural core. `backend/app.py` is the likely service entrypoint, while `run_query.py` and the `test_sql*.py` files indicate a CLI/test harness for exercising the query pipeline without the frontend.

3. Data ingestion is CSV-driven and dataset-agnostic. `setup_db.py` and `download_data.py` suggest CSV files are cleaned and loaded into an internal SQLite database, with `backend/YouTube Content Creation.csv` serving as an example dataset. This is the first major boundary: raw tabular data becomes a queryable local database.

4. Schema discovery is explicit rather than hard-coded. `schema_loader.py` and `build_schema_memory.py` derive table/column metadata and persist it into `schema_memory.json`. This lets the system adapt to different datasets without predefined schemas.

5. The natural-language understanding layer is split across several modules: `query_parser.py` interprets the user request, `template_engine.py` and `chart_selector.py` appear to map the intent into analytical patterns or presentation choices, and `followup_engine.py` handles ambiguous queries or clarification logic. `insight_engine.py` likely transforms raw query results into narrative analytics.

6. SQL generation and safety are separate concerns. `sql_generator.py` creates candidate SQL, and `sql_validator.py` checks that the query is structurally safe and compatible with the loaded schema before execution. This boundary protects the database from malformed or unsupported queries.

7. `query_executor.py` is the execution boundary between generated SQL and returned analytics. It runs the validated SQL against the internal database and returns result sets for downstream formatting, charting, or insight generation.

8. LLM integration is abstracted behind `genai_client.py` and `adapter.py`. The repo is designed to delegate intent interpretation and generation to an external model provider while keeping the rest of the system model-agnostic. The frontend also has an `/api/claude` route, which suggests a separate integration path for Claude-style model access.

9. The system maintains persistent “memory” to improve repeated usage and reduce bad outputs. `question_cache.json`, `bad_cache.json`, and `template_memory.json` indicate stored history for prior queries, failed patterns, and reusable query templates. These files are part of the adaptive behavior, not just logging.

10. The frontend is a Next.js app (`frontend/app`, `frontend/components/DIDashboard.jsx`) with login/register routes and a main dashboard page. Its role is to collect user input, display results, and likely proxy requests to the backend or model API routes.

11. Authentication is separated from the analytics pipeline. `backend/auth.py` plus the frontend `login` and `register` routes indicate a user-access layer that sits alongside, but not inside, the SQL/query engine.

12. For an architecture diagram, the main flow is: user uploads or selects a dataset in the UI → backend ingests CSV into SQLite and builds schema memory → user asks a natural-language question → LLM-assisted parsing and template selection produce SQL → SQL is validated → query is executed → results/insights/charts are returned to the frontend. The main external dependency is the generative model service; the main internal datastore is the dynamically created SQLite database plus JSON-based memory caches.

Main entry points: [`backend/query_parser.py`](https://github.com/eisoptrophobicc/data-intel/blob/main/backend/query_parser.py) (Parser), [`backend/query_executor.py`](https://github.com/eisoptrophobicc/data-intel/blob/main/backend/query_executor.py) (Executor), [`backend/app.py`](https://github.com/eisoptrophobicc/data-intel/blob/main/backend/app.py) (App Entry), [`backend/template_engine.py`](https://github.com/eisoptrophobicc/data-intel/blob/main/backend/template_engine.py) (Template Engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_fe_dashboard["Dashboard<br/>ui<br/>[page.js]"]
  node_fe_dashboard_comp["DIDashboard<br/>ui component<br/>[DIDashboard.jsx]"]
  node_fe_login["Login<br/>route<br/>[route.js]"]
  node_fe_register["Register<br/>route<br/>[route.js]"]
  node_fe_claude["Claude API<br/>route<br/>[route.js]"]
end

subgraph group_backend_core["Backend Core"]
  node_be_app["App Entry<br/>[app.py]"]
  node_be_parser["Parser<br/>nlp<br/>[query_parser.py]"]
  node_be_template["Template Engine<br/>planner<br/>[template_engine.py]"]
  node_be_followup["Follow-up<br/>dialog<br/>[followup_engine.py]"]
  node_be_sqlgen["SQL Generator<br/>[sql_generator.py]"]
  node_be_validator["SQL Validator<br/>guard<br/>[sql_validator.py]"]
  node_be_exec["Executor<br/>runtime<br/>[query_executor.py]"]
  node_be_insight["Insight Engine<br/>analytics<br/>[insight_engine.py]"]
  node_be_chart["Chart Selector<br/>presentation<br/>[chart_selector.py]"]
end

subgraph group_backend_data["Data and Memory"]
  node_be_setup[("DB Setup<br/>ingest<br/>[setup_db.py]")]
  node_be_schema_load["Schema Loader<br/>[schema_loader.py]"]
  node_be_schema_mem["Schema Memory<br/>[schema_memory.json]"]
  node_be_qcache["Question Cache<br/>memory"]
  node_be_badc["Bad Cache<br/>memory<br/>[bad_cache.json]"]
  node_be_tmplmem["Template Memory"]
  node_be_data_csv["Sample CSV<br/>dataset"]
end

subgraph group_auth["Access Layer"]
  node_be_auth["Auth<br/>[auth.py]"]
end

node_llm{{"Model Service<br/>external model"}}

node_fe_dashboard -->|"renders"| node_fe_dashboard_comp
node_fe_dashboard -->|"queries"| node_be_app
node_fe_login -->|"authenticates"| node_be_auth
node_fe_register -->|"registers"| node_be_auth
node_fe_claude -->|"proxies"| node_llm
node_be_app -->|"parses"| node_be_parser
node_be_parser -->|"selects pattern"| node_be_template
node_be_parser -->|"clarifies"| node_be_followup
node_be_template -->|"guides"| node_be_sqlgen
node_be_followup -->|"asks"| node_llm
node_be_sqlgen -->|"generates with"| node_llm
node_be_sqlgen -->|"checks"| node_be_validator
node_be_validator -->|"permits"| node_be_exec
node_be_exec -->|"returns results"| node_be_insight
node_be_exec -->|"feeds charts"| node_be_chart
node_be_exec -->|"reads schema"| node_be_schema_mem
node_be_setup -->|"loads"| node_be_data_csv
node_be_setup -->|"discovers"| node_be_schema_load
node_be_schema_load -->|"persists"| node_be_schema_mem
node_be_parser -->|"consults"| node_be_qcache
node_be_parser -->|"avoids"| node_be_badc
node_be_template -->|"reuses"| node_be_tmplmem
node_be_app -->|"orchestrates"| node_be_exec
node_be_app -->|"protects"| node_be_auth

click node_fe_dashboard "https://github.com/eisoptrophobicc/data-intel/blob/main/frontend/app/page.js"
click node_fe_dashboard_comp "https://github.com/eisoptrophobicc/data-intel/blob/main/frontend/components/DIDashboard.jsx"
click node_fe_login "https://github.com/eisoptrophobicc/data-intel/blob/main/frontend/app/api/login/route.js"
click node_fe_register "https://github.com/eisoptrophobicc/data-intel/blob/main/frontend/app/api/register/route.js"
click node_fe_claude "https://github.com/eisoptrophobicc/data-intel/blob/main/frontend/app/api/claude/route.js"
click node_be_app "https://github.com/eisoptrophobicc/data-intel/blob/main/backend/app.py"
click node_be_parser "https://github.com/eisoptrophobicc/data-intel/blob/main/backend/query_parser.py"
click node_be_template "https://github.com/eisoptrophobicc/data-intel/blob/main/backend/template_engine.py"
click node_be_followup "https://github.com/eisoptrophobicc/data-intel/blob/main/backend/followup_engine.py"
click node_be_sqlgen "https://github.com/eisoptrophobicc/data-intel/blob/main/backend/sql_generator.py"
click node_be_validator "https://github.com/eisoptrophobicc/data-intel/blob/main/backend/sql_validator.py"
click node_be_exec "https://github.com/eisoptrophobicc/data-intel/blob/main/backend/query_executor.py"
click node_be_insight "https://github.com/eisoptrophobicc/data-intel/blob/main/backend/insight_engine.py"
click node_be_chart "https://github.com/eisoptrophobicc/data-intel/blob/main/backend/chart_selector.py"
click node_be_auth "https://github.com/eisoptrophobicc/data-intel/blob/main/backend/auth.py"
click node_be_setup "https://github.com/eisoptrophobicc/data-intel/blob/main/backend/setup_db.py"
click node_be_schema_load "https://github.com/eisoptrophobicc/data-intel/blob/main/backend/schema_loader.py"
click node_be_schema_mem "https://github.com/eisoptrophobicc/data-intel/blob/main/backend/schema_memory.json"
click node_be_qcache "https://github.com/eisoptrophobicc/data-intel/blob/main/backend/question_cache.json"
click node_be_badc "https://github.com/eisoptrophobicc/data-intel/blob/main/backend/bad_cache.json"
click node_be_tmplmem "https://github.com/eisoptrophobicc/data-intel/blob/main/backend/template_memory.json"
click node_be_data_csv "https://github.com/eisoptrophobicc/data-intel/blob/main/backend/YouTube Content Creation.csv"

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_fe_dashboard,node_fe_dashboard_comp,node_fe_login,node_fe_register,node_fe_claude toneBlue
class node_be_app,node_be_parser,node_be_template,node_be_followup,node_be_sqlgen,node_be_validator,node_be_exec,node_be_insight,node_be_chart toneAmber
class node_be_setup,node_be_schema_load,node_be_schema_mem,node_be_qcache,node_be_badc,node_be_tmplmem,node_be_data_csv toneMint
class node_be_auth toneRose
class node_llm toneNeutral
```

## Components

### Frontend

Next.js user interface and API routes

- [Dashboard](https://github.com/eisoptrophobicc/data-intel/blob/main/frontend/app/page.js): ui · Main conversational BI interface · `frontend/app/page.js`
- [DIDashboard](https://github.com/eisoptrophobicc/data-intel/blob/main/frontend/components/DIDashboard.jsx): ui component · Primary frontend dashboard component · `frontend/components/DIDashboard.jsx`
- [Login](https://github.com/eisoptrophobicc/data-intel/blob/main/frontend/app/api/login/route.js): route · Frontend login route · `frontend/app/api/login/route.js`
- [Register](https://github.com/eisoptrophobicc/data-intel/blob/main/frontend/app/api/register/route.js): route · Frontend register route · `frontend/app/api/register/route.js`
- [Claude API](https://github.com/eisoptrophobicc/data-intel/blob/main/frontend/app/api/claude/route.js): route · Frontend model access route · `frontend/app/api/claude/route.js`

### Backend Core

Query understanding, SQL generation, validation, and execution

- [App Entry](https://github.com/eisoptrophobicc/data-intel/blob/main/backend/app.py): service · Backend service entrypoint · `backend/app.py`
- [Parser](https://github.com/eisoptrophobicc/data-intel/blob/main/backend/query_parser.py): nlp · Interprets user questions · `backend/query_parser.py`
- [Template Engine](https://github.com/eisoptrophobicc/data-intel/blob/main/backend/template_engine.py): planner · Maps intent to query patterns · `backend/template_engine.py`
- [Follow-up](https://github.com/eisoptrophobicc/data-intel/blob/main/backend/followup_engine.py): dialog · Handles ambiguity and clarification · `backend/followup_engine.py`
- [SQL Generator](https://github.com/eisoptrophobicc/data-intel/blob/main/backend/sql_generator.py): generator · Produces candidate SQL · `backend/sql_generator.py`
- [SQL Validator](https://github.com/eisoptrophobicc/data-intel/blob/main/backend/sql_validator.py): guard · Checks SQL safety and schema fit · `backend/sql_validator.py`
- [Executor](https://github.com/eisoptrophobicc/data-intel/blob/main/backend/query_executor.py): runtime · Runs validated SQL on SQLite · `backend/query_executor.py`
- [Insight Engine](https://github.com/eisoptrophobicc/data-intel/blob/main/backend/insight_engine.py): analytics · Turns results into narrative insights · `backend/insight_engine.py`
- [Chart Selector](https://github.com/eisoptrophobicc/data-intel/blob/main/backend/chart_selector.py): presentation · Chooses chart or visualization form · `backend/chart_selector.py`

### Data and Memory

SQLite ingestion inputs and persistent adaptive memory

- [DB Setup](https://github.com/eisoptrophobicc/data-intel/blob/main/backend/setup_db.py): ingest · Loads CSV data into SQLite · `backend/setup_db.py`
- [Schema Loader](https://github.com/eisoptrophobicc/data-intel/blob/main/backend/schema_loader.py): schema · Discovers tables and columns · `backend/schema_loader.py`
- [Schema Memory](https://github.com/eisoptrophobicc/data-intel/blob/main/backend/schema_memory.json): memory · Persisted schema metadata · `backend/schema_memory.json`
- [Question Cache](https://github.com/eisoptrophobicc/data-intel/blob/main/backend/question_cache.json): memory · Stored prior query history · `backend/question_cache.json`
- [Bad Cache](https://github.com/eisoptrophobicc/data-intel/blob/main/backend/bad_cache.json): memory · Persisted failed patterns · `backend/bad_cache.json`
- [Template Memory](https://github.com/eisoptrophobicc/data-intel/blob/main/backend/template_memory.json): memory · Reusable query templates · `backend/template_memory.json`
- [Sample CSV](https://github.com/eisoptrophobicc/data-intel/blob/HEAD/backend/YouTube%20Content%20Creation.csv): dataset · Example source dataset · `backend/YouTube Content Creation.csv`

### Access Layer

Authentication and request access boundaries

- [Auth](https://github.com/eisoptrophobicc/data-intel/blob/main/backend/auth.py): auth · Backend authentication boundary · `backend/auth.py`

### Other components

- **Model Service**: external model · External generative model provider

## Connections

- Dashboard → DIDashboard: renders · Dashboard uses the main UI component
- Dashboard → App Entry: queries · User questions are sent to backend service
- Login → Auth: authenticates · Login flow connects to backend auth
- Register → Auth: registers · Registration flow connects to backend auth
- Claude API → Model Service: proxies · Frontend route exposes model access
- App Entry → Parser: parses · Service begins with intent parsing
- Parser → Template Engine: selects pattern · Parsed intent feeds template matching
- Parser → Follow-up: clarifies · Ambiguous requests trigger follow-up logic
- Template Engine → SQL Generator: guides · Template choice informs SQL generation
- Follow-up → Model Service: asks · Clarification can consult the model
- SQL Generator → Model Service: generates with · SQL generation is model-assisted
- SQL Generator → SQL Validator: checks · Generated SQL is validated before execution
- SQL Validator → Executor: permits · Only valid queries proceed to execution
- Executor → Insight Engine: returns results · Result sets feed insight shaping
- Executor → Chart Selector: feeds charts · Execution output informs visualization choice
- Executor → Schema Memory: reads schema · Execution depends on discovered schema metadata
- DB Setup → Sample CSV: loads · CSV is ingested into SQLite
- DB Setup → Schema Loader: discovers · Setup phase builds schema from loaded data
- Schema Loader → Schema Memory: persists · Discovered schema is stored as memory
- Parser → Question Cache: consults · Known questions help parsing behavior
- Parser → Bad Cache: avoids · Failed patterns reduce bad outputs
- Template Engine → Template Memory: reuses · Template memory stores reusable patterns
- App Entry → Executor: orchestrates · Backend service coordinates the execution pipeline
- App Entry → Auth: protects · Access control sits alongside query handling
