An intelligent platform for generating and executing database queries through AI, powered by LLMs and natural language processing.
Query-Bot is a full-stack application that bridges the gap between natural language and database queries. Users can describe what data they need in plain English, and the AI system intelligently generates the corresponding SQL queries, executes them, and returns resultsβall with a user-friendly interface.
Perfect for:
- Data analysts without SQL expertise
- Rapid data exploration and reporting
- Learning SQL through AI-assisted examples
- Organizations reducing query-writing overhead
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Frontend (Next.js/React) β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β Auth UI β β Query Builderβ β Schema Mgmt β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
ββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β HTTP/REST
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Backend API (Express.js/TypeScript) β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β Auth Routes β β Query Routes β β Schema Routesβ β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β β
β ββββββββββββββββββββββββββββΌβββββββββββββββββββββββ β
β β LLM Service (Query Generation) β β
β β - Claude/OpenAI Integration β β
β β - Query validation & optimization β β
β ββββββββββββββββββββββββββββ¬βββββββββββββββββββββββ β
β β β
β ββββββββββββββββββββββββββββΌβββββββββββββββββββββββ β
β β Driver API (Python Executor) β β
β β - Query execution β β
β β - Result processing β β
β ββββββββββββββββββββββββββββ¬βββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β Database Protocol
βΌ
βββββββββββββββββββ
β PostgreSQL/SQL β
β Database β
βββββββββββββββββββ
| Layer | Technology | Responsibility |
|---|---|---|
| Frontend | Next.js 14, React, TypeScript | User interface, auth, query building |
| Backend API | Express.js, TypeScript, Node.js | REST API, business logic, authentication |
| LLM Service | Claude/OpenAI API | Natural language β SQL translation |
| Query Driver | Python FastAPI | Query execution, result formatting |
| Database | PostgreSQL | Data storage, query execution |
| Database | MongoDB | User sessions, query history |
- Runtime: Node.js + TypeScript
- Framework: Express.js
- Database: PostgreSQL (data), MongoDB (metadata)
- Authentication: JWT-based
- LLM Integration: Claude/OpenAI API
- Framework: Next.js 14 (App Router)
- UI Library: React 18
- Language: TypeScript
- Styling: CSS Modules / Tailwind CSS
- HTTP Client: Axios
- Language: Python 3.x
- Framework: FastAPI
- Database Drivers: psycopg2 (PostgreSQL)
β Natural Language Query Generation
- Describe your data needs in plain English
- AI intelligently converts to SQL
β Query Execution & Results
- Execute generated queries directly
- View formatted results in the UI
β Schema Management
- Upload database schemas
- Schema-aware query generation
- Query history & analytics
β User Authentication
- Secure login/signup
- Session management
- API key support
β Query History
- Track all executed queries
- Re-run previous queries
- Query performance insights
- Node.js v18+ and npm/yarn
- Python 3.8+
- PostgreSQL 12+ (or configured remote instance)
- MongoDB 4.4+ (for session storage)
- OpenAI/Claude API Key (for LLM service)
git clone https://github.com/HaseebUllahButt/Query-Bot.git
cd QueryBotcd Backend-API
# Install dependencies
npm install
# Configure environment
cp .env.example .env
# Edit .env with your database credentials and API keys
# Initialize database
npm run db:setup
# Start backend server
npm start
# Server runs on http://localhost:5000cd ../Frontend-Web
# Install dependencies
npm install
# Configure environment
cp .env.example .env.local
# Edit with backend API URL
# Start development server
npm run dev
# Access at http://localhost:3000cd ../Driver-API
# Create virtual environment
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Configure environment
cp .env.example .env
# Start driver server
python main.py
# Runs on http://localhost:8000# Server
NODE_ENV=development
PORT=5000
# Database - PostgreSQL
DB_HOST=localhost
DB_PORT=5432
DB_NAME=querybot
DB_USER=postgres
DB_PASSWORD=your_password
# Database - MongoDB (Sessions)
MONGODB_URI=mongodb://localhost:27017/querybot
# JWT Authentication
JWT_SECRET=your_jwt_secret_key_here
# LLM Service
OPENAI_API_KEY=sk-...
OPENAI_MODEL=gpt-4
# OR
CLAUDE_API_KEY=sk-ant-...
CLAUDE_MODEL=claude-3-sonnet-20240229
# Driver API
DRIVER_API_URL=http://localhost:8000
# CORS
FRONTEND_URL=http://localhost:3000NEXT_PUBLIC_API_URL=http://localhost:5000
NEXT_PUBLIC_APP_NAME=Query-BotDATABASE_URL=postgresql://user:password@localhost:5432/querybot
PORT=8000
LOG_LEVEL=infoQueryBot/
βββ Backend-API/ # Express.js backend
β βββ routes/ # API endpoints (auth, query, schema)
β βββ services/ # Business logic (LLM service)
β βββ middleware/ # Authentication, error handling
β βββ database/
β β βββ models/ # Data models (User, Query, Schema, Session)
β β βββ connection.ts # DB initialization
β β βββ setup.ts # Database migrations
β βββ types/ # TypeScript interfaces
β βββ utils/ # Helpers (schema parser, constants)
β
βββ Frontend-Web/ # Next.js frontend
β βββ src/
β β βββ app/ # App Router pages
β β βββ components/ # React components
β β β βββ auth/ # Login, signup
β β β βββ dashboard/ # Main UI
β β β βββ query/ # Query builder
β β β βββ schemas/ # Schema management
β β βββ lib/
β β β βββ api/ # API client
β β β βββ context/ # React context (Auth, Schemas)
β β βββ types/ # TypeScript definitions
β βββ public/ # Static assets
β
βββ Driver-API/ # Python query executor
βββ main.py # FastAPI server
βββ requirements.txt # Python dependencies
POST /api/auth/signup
{
"email": "user@example.com",
"password": "secure_password",
"fullName": "John Doe"
}POST /api/auth/login
{
"email": "user@example.com",
"password": "secure_password"
}POST /api/query/generate
- Generate SQL from natural language
- Requires:
prompt(string),schemaId(string) - Returns: Generated SQL query
POST /api/query/execute
- Execute a query and get results
- Requires:
query(string),schemaId(string) - Returns: Query results
GET /api/query/history
- Fetch user's query history
- Returns: Array of previous queries
POST /api/schema/upload
- Upload database schema
- Requires: file upload (SQL or JSON)
GET /api/schema/list
- List all user schemas
GET /api/schema/:id
- Get specific schema details
- User Input β Types "Show me all users created in the last month"
- Frontend β Sends to
/api/query/generatewith schema context - Backend β Passes to LLM Service with schema information
- LLM Service β Generates optimized SQL query
- Backend β Validates query, sends to Driver API
- Driver β Executes query against PostgreSQL
- Results β Returned to frontend and displayed to user
# Backend tests
cd Backend-API
npm run test
# Frontend tests
cd ../Frontend-Web
npm run test| Issue | Solution |
|---|---|
| Port already in use | Change PORT in .env or kill existing process |
| Database connection failed | Verify DB credentials and ensure server is running |
| LLM API errors | Check API key validity and quota limits |
| CORS errors | Verify FRONTEND_URL matches your frontend origin |
| Schema parsing errors | Ensure uploaded schema is valid SQL/JSON |
# Build images
docker-compose build
# Start services
docker-compose upDeployable to: Vercel (frontend), Render/Railway (backend), AWS Lambda (driver)
- Support for multiple database types (MySQL, SQLite, MongoDB)
- Query optimization recommendations
- Advanced analytics & query performance tracking
- Team collaboration features
- Query scheduling & automation
- Advanced security (encryption, audit logs)
MIT License - See LICENSE file for details
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Commit changes with clear messages
- Submit a pull request
For issues or questions:
- Open an GitHub issue
Made with β€οΈ for making data accessible to everyone