The most powerful AI-driven SQL assistant β review queries, analyze schemas, generate SQL from plain English, and connect to live databases with a full agentic AI pipeline featuring self-reflection and RAG-powered intelligence.
π Quick Start Β· β¨ Features Β· ποΈ Architecture Β· π€ AI Pipeline Β· π οΈ Tech Stack
|
Paste any SQL query and get an instant AI-powered deep analysis β performance bottlenecks, security vulnerabilities, readability score, and concrete optimization suggestions with severity tags. |
Upload your DDL or paste a schema and receive a comprehensive evaluation of design choices, normalization gaps, missing indexes, and foreign key recommendations. |
|
Describe what you want in plain English. The AI understands your intent, picks the right dialect (MySQL / PostgreSQL), and returns a clean, optimized query with explanation. |
Connect directly to your MySQL or PostgreSQL instance (read-only, session-based). Explore the live schema, run queries or NL prompts, and get EXPLAIN plan analysis β all in one place. |
|
Upload a schema diagram image and the AI reverse-engineers it into complete SQL DDL β table definitions, constraints, indexes, and relationships included. |
Every analysis is saved. Search, filter by type, date, or database dialect, and revisit any past result with full detail view and re-analysis option. |
| Capability | Detail |
|---|---|
| π Secure Connection | Read-only, session-scoped β never modifies your data |
| π Schema Explorer | Toggle panel with table count, expandable column details |
| π¬ Dual Query Mode | Switch between raw SQL and natural language on the fly |
| ποΈ Voice Input | Speech-to-text for NL mode β just speak your question |
| π€ Smart Context | Agent automatically injects relevant schema context |
| π EXPLAIN Plans | Run and visualize query execution plans instantly |
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β React Frontend (Vite + React 18) β
β Dashboard β Query Review β Schema β NLβSQL β Live DB β History β
ββββββββββββββββββββββββββββ¦ββββββββββββββββββββββββββββββββββββ
β REST API (HTTP/JSON)
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FastAPI Backend β
β /api/review-query /api/review-schema /api/nl-to-query β
β /api/connect-db /api/history /api/schema-build β
βββββββββββββββββ¦βββββββββββββββββββββββ¦ββββββββββββββββββββββββ
β β
βΌ βΌ
ββββββββββββββββββββββββ ββββββββββββββββββββββββββββββββββββ
β AI Agent β β Live DB Connection β
β ββββββββββββββββββ β β βββββββββββββ ββββββββββββββ β
β β Static Analysisβ β β β MySQL β β PostgreSQL β β
β β RAG Retrieval β β β β (PyMySQL) β β(Psycopg2) β β
β β Tool Calling β β β βββββββββββββ ββββββββββββββ β
β β LLM Reasoning β β β Read-Only β Session-Scoped β
β β Self-Reflectionβ β ββββββββββββββββββββββββββββββββββββ
β β Evaluation β β
β βββββββββ¬βββββββββ β
ββββββββββββ¬ββββββββββββ
β
βββββββ©βββββββ
βΌ βΌ
βββββββββββ ββββββββββββ
βChromaDB β β Supabase β
β (RAG) β β(History) β
βββββββββββ ββββββββββββ
Every analysis runs through a fully agentic loop β not a simple one-shot prompt:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β AGENTIC LOOP β
β β
β π₯ Input β
β β β
β βΌ β
β [1] π Static Analysis ββββ Pattern-based issue detection β
β β β
β βΌ β
β [2] π RAG Retrieval βββββββ ChromaDB knowledge search β
β β β
β βΌ β
β [3] π§ Tool Calling ββββββββ Specialized analysis modules β
β β β
β βΌ β
β [4] π§ LLM Reasoning βββββββ Multi-model inference β
β β β
β βΌ β
β [5] πͺ Self-Reflection βββββ Quality check (up to 3x) β
β β β
β βΌ β
β [6] π Evaluation ββββββββββ Score: PerfβSecβReadβComplex β
β β β
β βΌ β
β π€ Final Response β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
The agent automatically cascades through providers β zero downtime if one fails:
| # | Provider | Model | Speed | Notes |
|---|---|---|---|---|
| 1οΈβ£ | Google Gemini | gemini-2.5-pro |
Fast | Primary β best quality |
| 2οΈβ£ | Google Gemini | gemini-2.5-flash |
Faster | Flash fallback |
| 3οΈβ£ | Groq | llama-3.1-8b-instant |
Ultra-fast | Low latency fallback |
| 4οΈβ£ | OpenRouter | gemma-3-4b (free) |
Medium | Free tier fallback |
| 5οΈβ£ | OpenRouter | llama-3.3-70b (free) |
Medium | Final free fallback |
git clone https://github.com/your-username/ai-query-master.git
cd "AI Query Master/backend"
# Create & activate virtual environment
python -m venv venv
venv\Scripts\activate # Windows
# source venv/bin/activate # Linux / macOS
# Install all dependencies
pip install -r requirements.txtCreate backend/.env and fill in your keys:
# ββ AI Providers ββββββββββββββββββββββββββββββββββββββ
GEMINI_API_KEY=your_gemini_key
GROQ_API_KEY=your_groq_key
OPENROUTER_KEY_1=your_openrouter_key
OPENROUTER_KEY_2=your_openrouter_key_optional # optional second key
# ββ Supabase (Auth + History storage) βββββββββββββββββ
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_KEY=your_supabase_anon_keyRun migration.sql in your Supabase SQL Editor to create all required tables.
Drop PDF documents into the RAG knowledge folders to supercharge analysis quality:
RAG_Knowledge/
βββ Mysql/ β MySQL best practices, docs, guides
βββ PostgreSQL/ β PostgreSQL best practices, docs, guides
Terminal 1 β Backend:
cd backend
venv\Scripts\activate
python main.py
# β
API running at http://localhost:8000
# β
Docs available at http://localhost:8000/docsTerminal 2 β Frontend:
cd frontend
npm install
npm run dev
# β
App running at http://localhost:5173Open http://localhost:5173 and start querying! π
| Layer | Technology | Purpose |
|---|---|---|
| Frontend | React 18 + Vite + React Router | SPA with fast HMR dev experience |
| Backend | FastAPI + Python 3.12 | Async REST API with auto-docs |
| AI / LLM | Gemini Β· Groq Β· OpenRouter | Multi-provider fallback inference |
| RAG | ChromaDB Β· LangChain Β· SentenceTransformers | Vector search over knowledge base |
| Auth & Storage | Supabase | Auth, user management, history DB |
| Live Database | PyMySQL Β· Psycopg2 | Read-only live DB connections |
AI Query Master/
β
βββ π backend/
β βββ main.py β FastAPI app entry point
β βββ requirements.txt
β βββ π agent/
β β βββ agent.py β Agentic orchestration loop
β β βββ llm_provider.py β Multi-LLM fallback chain
β β βββ rag_pipeline.py β ChromaDB RAG retrieval
β β βββ tools.py β Specialized analysis tools
β β βββ reflection.py β Self-reflection module
β β βββ evaluator.py β Scoring: Perf/Sec/Read/Complex
β βββ π api/
β β βββ auth.py β Supabase auth endpoints
β β βββ nl_to_query.py β NL β SQL endpoint
β β βββ query_review.py β Query analysis endpoint
β β βββ schema_review.py β Schema analysis endpoint
β β βββ schema_builder.py β Image β DDL endpoint
β β βββ live_db.py β Live DB connection endpoint
β β βββ history.py β Analysis history endpoint
β βββ π db/
β βββ mysql_connector.py β MySQL live connection
β βββ postgres_connector.pyβ PostgreSQL live connection
β βββ supabase_client.py β Supabase client
β
βββ π frontend/
β βββ π src/
β β βββ π pages/ β Full-page route components
β β βββ π components/ β Reusable UI components
β β βββ π context/ β Auth & Theme context
β β βββ api.js β Centralized API client
β βββ package.json
β
βββ π RAG_Knowledge/
β βββ Mysql/ β MySQL knowledge documents
β βββ PostgreSQL/ β PostgreSQL knowledge documents
β
βββ migration.sql β Supabase schema setup
- Live DB connections are strictly read-only and session-scoped β no write operations, no persistent credentials stored
- All API keys are loaded from environment variables β never hardcoded
- Authentication handled by Supabase with JWT tokens
- RAG knowledge base is local β no user query data sent to vector DB providers