Ask database questions in plain English and receive instant, dialect-aware, validated SQL with live interactive query results, visual ER diagrams, and query history.
| ๐ Authentication & Security | ๐ Hot-Swappable Data Sources |
|---|---|
![]() |
![]() |
| โ๏ธ Paper Terminal Query Interface |
|---|
![]() |
SQLscribe is an enterprise-grade, full-stack Text-to-SQL query assistant designed to democratize database access. By coupling a fast FastAPI backend with a high-performance React 18 interface, SQLscribe allows non-technical stakeholders and developers alike to query complex databases in plain English without writing a single line of SQL manually.
Under the hood, SQLscribe leverages the Groq API (Llama 3.3 70B) for dialect-aware SQL generation, paired with real-time database schema introspection and AST-based SQL guardrails (sqlglot) to guarantee that every generated query is syntactically sound, schema-valid, and execution-safe.
In modern data-driven organizations:
- High Barrier to Entry: Business analysts, product managers, and decision-makers often lack deep SQL expertise (joins, window functions, CTEs), creating reliance on overloaded engineering teams.
- Schema Hallucination in Naive LLMs: Standard text-to-SQL prompts frequently hallucinate non-existent table and column names or produce syntax incompatible with specific database engines (e.g. SQLite vs. PostgreSQL vs. MySQL).
- Security & Injection Risks: Unchecked LLM SQL generation can lead to catastrophic data loss via destructive operations (
DROP TABLE, un-indexedUPDATE/DELETE) or SQL injection vulnerabilities (SELECT ...; DROP DATABASE;).
SQLscribe introduces a Human-in-the-Loop, Guardrailed AI Architecture:
- Live Schema Introspection: Fetches exact table structures, column definitions, and data types directly from the active database before prompting the LLM.
- Dialect-Specific Prompting: Dynamically instructs the LLM to format SQL for SQLite, PostgreSQL, or MySQL.
- Abstract Syntax Tree (AST) Validation Engine: Intercepts every generated query with
sqlglotto enforce single-statement constraints, block SQL comment injection, verify table references against allowed schemas, and confirm read-only safety. - Self-Correcting LLM Retry Loop: If a query fails validation, the validator's error message is automatically fed back to Llama 3.3 for immediate self-correction.
- Hot-Swappable Data Sources:
- Seeded Demo Database: Instant setup with an e-commerce RetailDB schema (
customers,products,orders,order_items). - SQLite File Upload: Upload any custom
.db/.sqlitefile for automatic schema parsing. - Local SQLite Path: Connect directly to any local SQLite file path.
- Live PostgreSQL Server: Connect directly to remote or local PostgreSQL instances.
- Live MySQL Server: Connect directly to remote or local MySQL instances.
- Seeded Demo Database: Instant setup with an e-commerce RetailDB schema (
- Groq Llama 3.3 70B Engine: Sub-second natural language translation tuned specifically for SQL generation.
- SQL Guard Safety System: AST-based validation preventing multi-statement execution, comments, unknown table references, and unwanted mutations.
- Paper Terminal Interface: Minimalist warm paper backdrop (
#FAF7F1) paired with a high-contrast dark terminal window (#2B2B2B) for crisp SQL code visibility. - Interactive Results Grid: Automatic column deduplication, row-capping (500 max rows protection), and instant CSV data export.
- Live ER Diagram Generator: Interactive, dynamically computed entity-relationship visualizer built from live schema introspection.
- Execution History & Favorites: Persisted query history per database, favorite query bookmarking, and one-click query re-run.
- Token Authentication: Built-in signup, login, and bearer-token session protection powered by bcrypt password hashing.
The following diagram illustrates SQLscribe's multi-tiered system architecture, data flow, and component interactions:
flowchart TD
subgraph Client ["Client Tier (React 18 + Tailwind)"]
UI["Paper Terminal Web App"]
end
subgraph Hosting ["FastAPI Backend Service"]
API["FastAPI App (Uvicorn Engine)"]
AuthModule["Auth Module (Bcrypt + Sessions)"]
SourceModule["Source Introspector & Driver"]
GuardModule["SQL Guard (sqlglot AST Validator)"]
HistoryModule["History Store Manager"]
end
subgraph AILayer ["AI Generation Layer"]
GroqAPI["Groq API (Llama 3.3 70B)"]
end
subgraph DataLayer ["Active Data Source (Connected DB)"]
DemoDB["Seeded Demo RetailDB (SQLite)"]
UploadDB["Uploaded SQLite (.db / .sqlite)"]
PostgresDB["Live PostgreSQL Server"]
MySQLDB["Live MySQL Server"]
end
subgraph InternalStorage ["System Persistence"]
AuthDB[("Auth DB (auth.db)")]
HistDB[("History DB (history.db)")]
end
UI -->|"HTTP / REST API"| API
API --> AuthModule
AuthModule --> AuthDB
API -->|"1. Introspect Schema"| SourceModule
SourceModule --> DataLayer
API -->|"2. Question + Live Schema"| GroqAPI
GroqAPI -->|"3. Generated Raw SQL"| API
API -->|"4. Validate AST & Security"| GuardModule
GuardModule -->|"5. Validated Safe SQL"| API
API -->|"6. Execute Safe Query"| DataLayer
DataLayer -->|"7. Result Sets & Metadata"| API
API -->|"8. Log Execution History"| HistoryModule
HistoryModule --> HistDB
API -->|"9. JSON Response"| UI
- App / Client Tier (React 18): Single-page application designed with the Paper Terminal aesthetic. Handles data source selection, prompt submission, syntax-highlighted SQL rendering, interactive table views with CSV export, dynamic ER diagram visualization, and user sessions.
- API Layer (FastAPI): Asynchronous Python REST service serving as the core orchestrator. Manages connection pooling, endpoint routing, session authentication, and database metadata extraction.
- AI Layer (Groq API): Powered by
llama-3.3-70b-versatile. Formulates dialect-aware SQL prompts by appending live table/column schema context, enforcing single statement responses without markdown noise. - Parsing & Guardrail Layer (
sqlglot+sql_guard.py): Intercepts LLM outputs before execution. Parses raw text into Abstract Syntax Trees (AST), verifies referenced tables against the live schema, strips comment tokens, blocks multi-statement injection, and enforces read-only execution modes. - Data Tier (Hot-Swappable Connectors): Database abstraction layer providing zero-config SQLite seeding, uploaded
.dbfile parsing, and connection management for live PostgreSQL (psycopg2) and MySQL (pymysql) instances. - Persistence Store: Independent SQLite database instances handling user authentication tokens (
auth.db) and user query execution logs (history.db) isolated from active user data sources.
SQLscribe enforces strict multi-layered AI safety mechanisms before any generated query hits a database:
- AST Parsing (
sqlglot): Converts LLM-generated string outputs into structured Abstract Syntax Trees to verify syntax correctness across dialect targets (sqlite,postgres,mysql). - Multi-Statement Injection Prevention: Rejects any query containing semicolon
;execution separators to block nested or piggybacked SQL attacks. - SQL Comment Stripping: Rejects
--,/*, and*/comment syntax to prevent comment-based logic bypasses. - Schema Boundary Enforcement: Extracted table names from the AST are validated against
allowed_tablesretrieved from live schema introspection. Any query referencing unknown or unmapped tables is blocked immediately. - Read-Only Enforcer: Detects query types (
exp.Select) and rejects unauthorized DDL/DML statements unless write permissions are explicitly enabled. - Automatic LLM Self-Correction: When AST validation fails, SQLscribe passes the validation error back to Llama 3.3 for a second attempt, allowing the LLM to self-correct its query syntax or table names automatically.
- Memory Protection & Deduplication: Enforces a strict 500-row return limit (
MAX_ROWS) and automatically deduplicates repeating result column names (name,name_2) to prevent data loss or frontend memory crashes.
| Domain | Technology / Library | Description |
|---|---|---|
| Frontend Framework | React 18, Vite | High-performance SPA frontend |
| Styling & UI | Tailwind CSS, Framer Motion | Paper Terminal custom palette & smooth UI transitions |
| Icons & Visuals | Lucide React | Clean, scalable vector iconography |
| Backend Framework | FastAPI, Uvicorn | Async Python ASGI web framework |
| LLM Provider | Groq API (llama-3.3-70b-versatile) |
Ultra-low latency natural language to SQL translation |
| SQL Parser & Validator | sqlglot |
AST construction, SQL dialect translation, & guardrails |
| Database Connectors | SQLite (sqlite3), PostgreSQL (psycopg2-binary), MySQL (pymysql) |
Native multi-engine database support |
| Authentication | Passlib, Bcrypt, PyJWT | Secure user signup, password hashing, and session management |
Ensure you have the following installed on your machine:
- Python 3.10+
- Node.js 18+ & npm
- Groq API Key: Obtain a free key from Groq Console
# Navigate to backend directory
cd backend
# Create a virtual environment
python -m venv venv
# Activate virtual environment
# On Linux/macOS:
source venv/bin/activate
# On Windows (PowerShell):
.\venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Create environment file
cp .env.example .envOpen .env and set your Groq API key:
GROQ_API_KEY=your_groq_api_key_here
SQLSCRIBE_MODEL=llama-3.3-70b-versatileStart the backend server:
uvicorn app.main:app --reload --port 8000Verify backend health:
curl http://127.0.0.1:8000/api/health
# Response: {"status":"ok"}In a separate terminal window:
# Navigate to frontend directory
cd frontend
# Install Node dependencies
npm install
# Start Vite development server
npm run devOpen your browser and visit: http://localhost:5173
- Sign Up / Log In: Create an account on the initial authentication screen.
- Select Data Source:
- Load Demo Database: Seeds an instant e-commerce database with zero setup.
- Upload SQLite Database: Select any
.dbor.sqlitefile from your computer. - Connect PostgreSQL / MySQL: Input database host, port, database name, user, and password.
- Ask Questions: Type natural language prompts like:
- "Show top 5 products by total sales revenue."
- "List all customers who placed more than 3 orders."
- "Calculate average order value by product category."
- Inspect & Export:
- View the generated SQL in the dark Paper Terminal panel.
- Browse query results in the table grid and export to CSV.
- Click the Schema tab to explore tables or view the dynamically generated ER Diagram.
- Click the History tab to re-run or favorite previous queries.
sqlscribe/
โโโ backend/
โ โโโ app/
โ โ โโโ main.py # FastAPI endpoints (Auth, Sources, Schema, Query, History)
โ โ โโโ auth.py # User authentication, password hashing & session management
โ โ โโโ sources.py # Active data source manager (Demo, SQLite, Postgres, MySQL)
โ โ โโโ database.py # Seed schema definition & demo RetailDB seeder
โ โ โโโ history.py # Query execution logger & favorites persistence
โ โ โโโ llm.py # Groq API client & dialect-aware prompt generation
โ โ โโโ sql_guard.py # sqlglot AST parsing, SQL validation & security guardrails
โ โโโ data/ # System databases (auth.db, history.db, demo database)
โ โโโ requirements.txt # Python backend dependencies
โ โโโ .env.example # Environment template for Groq API key
โ
โโโ docs/
โ โโโ auth-screen.png # User authentication & security screen
โ โโโ datasource-picker.png # Data source selection screen
โ โโโ paper-terminal-preview.png # Main Paper Terminal query screen
โ
โโโ frontend/
โโโ src/
โ โโโ components/
โ โ โโโ DataSourceLanding.jsx # Initial data source selection view
โ โ โโโ Sidebar.jsx # Sidebar navigation & live schema explorer
โ โ โโโ QueryPanel.jsx # Question input & terminal-style SQL panel
โ โ โโโ ConnectionStatus.jsx # Live backend connection indicator
โ โ โโโ DatabaseSelector.jsx # Active database display & switcher modal
โ โ โโโ ResultsPanel.jsx # Interactive data table & CSV exporter
โ โ โโโ QueryHistory.jsx # Recent query history drawer
โ โ โโโ HistoryView.jsx # Full execution history view with search
โ โ โโโ SchemaView.jsx # Detailed schema viewer tab
โ โ โโโ ERDiagram.jsx # Live entity-relationship visualizer
โ โโโ lib/
โ โ โโโ api.js # Frontend API client & fetch wrappers
โ โ โโโ highlightSql.js # SQL keyword syntax highlighter
โ โโโ App.jsx # Main application state & tab router
โ โโโ index.css # Base styles & Paper Terminal custom palette
โโโ tailwind.config.js # Tailwind configuration & color tokens
โโโ package.json # Frontend dependencies & scripts
- Per-User Database Connections: Isolate active database sessions per user session token rather than process-wide global state.
- Controlled Write Operations: Interactive confirmation dialogs for safe
INSERT/UPDATEqueries with enforcedWHEREclause checks. - Automated Chart Generation: Built-in charting (Bar charts, Line graphs, Pie charts) powered by Recharts/Chart.js for numeric query results.
- AI Response Insights: Generative text summaries explaining the data insights alongside raw query table output.
- EXPLAIN ANALYZE Integration: Visual query execution plan and performance optimization recommendations.
Meet the collaborators behind SQLscribe:
- ๐ฉโ๐ป Priyanshi Choudhary โ @Priyanshi0907
- ๐ฉโ๐ป Khushi Sharma โ @khushisharma050405
- ๐จโ๐ป Kunal Chauhan โ @Kunal-Chauhan-1858
Distributed under the MIT License. See LICENSE for more information.


