An AI-powered database query interface that allows users to interact with databases using natural language. Ask questions in plain English, and QueryPilot converts them into SQL queries and executes them against your connected databases.
✨ Natural Language Processing: Convert plain text questions into SQL queries using AI
🤖 Powered by Google Gemini: Advanced AI for accurate query generation
🗄️ Multi-Database Support: Works with PostgreSQL, MySQL, and SQLite
💬 Chat Interface: Conversational UI similar to popular chat applications
🛡️ Query Safety: Built-in validation to prevent destructive operations
📊 Real-time Results: Execute queries and see results instantly
🎨 Modern UI: Clean, responsive interface built with Next.js and Tailwind CSS
QueryPilot is a full-stack application with a clear separation between frontend and backend:
- Frontend (
/client): Next.js 14 application with TypeScript and Tailwind CSS - Backend (
/server): Express.js API server with TypeScript, database adapters, and AI integration
- Next.js 14 (App Router)
- TypeScript
- Tailwind CSS
- Shadcn/UI components
- Node.js & Express.js
- TypeScript
- Google Gemini API
- PostgreSQL, MySQL, SQLite drivers
- Node.js 18+ and npm
- Google Gemini API key (Get one here)
- At least one database (PostgreSQL, MySQL, or SQLite)
-
Clone the repository:
git clone <repository-url> cd QueryPilot
-
Setup Backend:
cd server npm install cp .env.example .env # Edit .env and add your GEMINI_API_KEY and database credentials
-
Setup Frontend:
cd ../client npm install
You'll need two terminal windows:
Terminal 1 - Backend:
cd server
npm run devBackend runs on http://localhost:3001
Terminal 2 - Frontend:
cd client
npm run devFrontend runs on http://localhost:3000
Open your browser to http://localhost:3000 to use QueryPilot!
- Select your database type (PostgreSQL, MySQL, or SQLite)
- Enter connection credentials
- Click "Connect"
Once connected, you can ask questions like:
- "Show me all users"
- "How many orders were placed last month?"
- "List the top 10 products by sales"
- "What are the most recent customer registrations?"
QueryPilot will:
- Convert your question to SQL
- Display the generated SQL query
- Execute the query safely
- Show results in a table format
Create a .env file in the /server directory:
# Required
GEMINI_API_KEY=your_api_key_here
# Server Config
NODE_ENV=development
PORT=3001
CLIENT_URL=http://localhost:3000
# Database credentials (configure at least one)
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DB=your_database
POSTGRES_USER=your_username
POSTGRES_PASSWORD=your_password
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_DB=your_database
MYSQL_USER=your_username
MYSQL_PASSWORD=your_password
SQLITE_PATH=./database.sqliteCreate a .env.local file in the /client directory if you need to customize the API URL:
NEXT_PUBLIC_API_URL=http://localhost:3001QueryPilot/
├── client/ # Frontend (Next.js)
│ ├── app/ # Next.js App Router
│ ├── components/ # React components
│ │ ├── ChatInterface.tsx # Main chat UI
│ │ ├── MessageList.tsx # Message history
│ │ ├── QueryInput.tsx # User input
│ │ ├── ResultsDisplay.tsx # Query results table
│ │ └── ConnectionPanel.tsx # Database connection UI
│ ├── lib/
│ │ └── api-client.ts # API client
│ └── package.json
├── server/ # Backend (Express.js)
│ ├── src/
│ │ ├── config/ # Configuration
│ │ ├── controllers/ # Route controllers
│ │ ├── middleware/ # Express middleware
│ │ ├── routes/ # API routes
│ │ ├── services/ # Business logic
│ │ │ ├── ai/ # Gemini AI service
│ │ │ ├── database/ # Database adapters
│ │ │ └── validation/ # SQL validation
│ │ ├── types/ # TypeScript types
│ │ ├── app.ts # Express app
│ │ └── index.ts # Entry point
│ └── package.json
├── CONTEXT.md # Detailed project documentation
└── README.md # This file
The backend exposes three main endpoints:
Convert natural language to SQL and execute
Request:
{
"question": "Show me all users",
"database": "postgresql",
"schema": { ... }
}Response:
{
"sql": "SELECT * FROM users",
"results": [...],
"rowCount": 10
}Connect to a database
Request:
{
"type": "postgresql",
"credentials": {
"host": "localhost",
"port": 5432,
"database": "mydb",
"user": "user",
"password": "pass"
}
}Validate SQL query without executing
Request:
{
"sql": "SELECT * FROM users",
"database": "postgresql"
}QueryPilot implements multiple security measures:
- Input validation and sanitization
- Parameterized queries
- Query validation before execution
- Read-only mode: Only SELECT, SHOW, DESCRIBE, EXPLAIN queries allowed
- Blacklist: Dangerous operations (DROP, DELETE, UPDATE, etc.) are blocked
- Single statement: Multiple SQL statements are not permitted
- Validation: All queries validated before execution
- Credentials stored in environment variables
- No hardcoded credentials
- Secure connection handling
- Ensure
GEMINI_API_KEYis set in/server/.env - Check that port 3001 is available
- Verify Node.js version is 18+
- Ensure backend is running on port 3001
- Check CORS settings in backend
- Verify
NEXT_PUBLIC_API_URLif using custom backend URL
- Verify database credentials in
.env - Ensure database server is running and accessible
- Check firewall settings
- For PostgreSQL/MySQL, verify database exists
- Verify
GEMINI_API_KEYis valid - Check Google Gemini API quota/limits
- Review backend logs for error details
cd server
npm run dev # Start with auto-reload
npm run build # Build for production
npm start # Run production buildcd client
npm run dev # Start dev server
npm run build # Build for production
npm start # Run production build- Build:
cd server && npm run build - Deploy
dist/folder to Node.js hosting (AWS, Heroku, DigitalOcean, etc.) - Set environment variables on hosting platform
- Start:
npm start
- Build:
cd client && npm run build - Deploy to Vercel, Netlify, or static hosting
- Set
NEXT_PUBLIC_API_URLto production backend URL
Contributions are welcome! Please feel free to submit a Pull Request.
MIT
For issues and questions, please open an issue on GitHub.
Made with ❤️ using Next.js, Express.js, and Google Gemini