How 10div10/sql-copilot works
SQL Copilot turns a user’s question into validated, read-only SQL and a plain-language answer. Users first upload a CSV or connect a database; the API creates a session and indexes its schema. For queries, it supplies either the full schema or retrieved table context to SQL generation, validates the result, executes it, optionally retries after an execution error, and explains the returned rows. The graph reflects the README and sampled backend source; frontend implementation details were not sampled, so its documented API relationship is cited to the README.
Main entry points: main.py FastAPI endpoints · db.py Engine setup · schema_store.py Schema indexing · index.html Browser UI
Components 17
User interface
- Browser UI
frontend/index.html - FastAPI endpoints
backend/main.py
Data sessions
- CSV loader
backend/db.py - Engine setup
backend/db.py - Session database
Query pipeline
- Schema context
backend/main.py - SQL validation
backend/sql_guard.py - Query execution
backend/main.py
Schema and language
- Schema indexing
backend/schema_store.py - Chroma schema index
backend/schema_store.py - Table retrieval
backend/schema_store.py - SQL generation
backend/llm.py - SQL correction
backend/llm.py - Result explanation
backend/llm.py
Other components
- User
- Groq LLM
- Connected database
Connections 25
- User → Browser UI: asks or uploads
README.md - Browser UI → FastAPI endpoints: calls API
README.md - FastAPI endpoints → Browser UI: returns results
README.md - FastAPI endpoints → CSV loader: loads CSV
backend/main.py - FastAPI endpoints → Engine setup: creates engine
backend/main.py - CSV loader → Session database: writes dataset
backend/db.py - Engine setup → Session database: opens session DB
backend/db.py - Engine setup → Connected database: connects
backend/db.py - FastAPI endpoints → Schema indexing: builds schema index
backend/main.py - Schema indexing → Session database: introspects and samples
backend/schema_store.py - Schema indexing → Chroma schema index: stores table docs
backend/schema_store.py - FastAPI endpoints → Table retrieval: retrieves tables
backend/main.py - Table retrieval → Chroma schema index: queries index
backend/schema_store.py - FastAPI endpoints → Schema context: builds context
backend/main.py - Table retrieval → Schema context: supplies relevant docs
backend/main.py - Schema context → SQL generation: provides schema
backend/main.py - FastAPI endpoints → SQL generation: requests SQL
backend/main.py - SQL generation → Groq LLM: generates SQL
backend/llm.py - FastAPI endpoints → SQL validation: validates SQL
backend/main.py - FastAPI endpoints → Query execution: executes safe SQL
backend/main.py - Query execution → Session database: reads rows
backend/main.py - Query execution → SQL correction: requests retry SQL
backend/main.py - SQL correction → Groq LLM: corrects SQL
backend/llm.py - FastAPI endpoints → Result explanation: requests answer
backend/main.py - Result explanation → Groq LLM: explains results
backend/llm.py