How eisoptrophobicc/data-intel works
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: query_parser.py Parser · query_executor.py Executor · app.py App Entry · template_engine.py Template Engine
Components 23
Frontend
Next.js user interface and API routes
- Dashboard · Main conversational BI interface
frontend/app/page.js - DIDashboard · Primary frontend dashboard component
frontend/components/DIDashboard.jsx - Login · Frontend login route
frontend/app/api/login/route.js - Register · Frontend register route
frontend/app/api/register/route.js - Claude API · Frontend model access route
frontend/app/api/claude/route.js
Backend Core
Query understanding, SQL generation, validation, and execution
- App Entry · Backend service entrypoint
backend/app.py - Parser · Interprets user questions
backend/query_parser.py - Template Engine · Maps intent to query patterns
backend/template_engine.py - Follow-up · Handles ambiguity and clarification
backend/followup_engine.py - SQL Generator · Produces candidate SQL
backend/sql_generator.py - SQL Validator · Checks SQL safety and schema fit
backend/sql_validator.py - Executor · Runs validated SQL on SQLite
backend/query_executor.py - Insight Engine · Turns results into narrative insights
backend/insight_engine.py - Chart Selector · Chooses chart or visualization form
backend/chart_selector.py
Data and Memory
SQLite ingestion inputs and persistent adaptive memory
- DB Setup · Loads CSV data into SQLite
backend/setup_db.py - Schema Loader · Discovers tables and columns
backend/schema_loader.py - Schema Memory · Persisted schema metadata
backend/schema_memory.json - Question Cache · Stored prior query history
backend/question_cache.json - Bad Cache · Persisted failed patterns
backend/bad_cache.json - Template Memory · Reusable query templates
backend/template_memory.json - Sample CSV · Example source dataset
backend/YouTube Content Creation.csv
Access Layer
Authentication and request access boundaries
- Auth · Backend authentication boundary
backend/auth.py
Other components
- Model Service · External generative model provider
Connections 24
- 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