Transform Natural Language into Production-Ready SQL. QueryGenie is a full-stack, AI-powered database assistant that allows developers and data analysts to generate complex PostgreSQL queries using plain English. By providing custom database schemas as context, it delivers highly accurate, schema-aware SQL instantly.
- AI-Powered Query Generation: Utilizes Google's Gemini 3.5 Flash model to translate natural language into optimized SQL.
- Schema Awareness: Upload or paste your custom database schema context so the AI understands your specific table structures and relationships.
- Secure Authentication: Complete user registration and login system protected by JSON Web Tokens (JWT).
- Query History: Automatically logs all successfully generated queries to a serverless PostgreSQL database for easy retrieval and auditing.
- Modern UI/UX: Built with React and Tailwind CSS, featuring a sleek, responsive, code-editor-style interface with one-click clipboard copying.
QueryGenie utilizes a decoupled, modern full-stack architecture optimized for speed, security, and scalability.
┌─────────────────────────────────────────────────────────┐
│ User Browser (Client) │
│ [ Login / Register ] [ Schema Input ] [ Natural Lang ] │
└───────────────────────────┬─────────────────────────────┘
│
▼ REST API (JSON / JWT)
┌─────────────────────────────────────────────────────────┐
│ Frontend (Vercel) │
│ React.js + Vite + Tailwind │
│ Manages UI state, route protection, and API requests │
└───────────────────────────┬─────────────────────────────┘
│
▼ HTTPS
┌─────────────────────────────────────────────────────────┐
│ Backend API (Render) │
│ Node.js + Express.js │
│ Handles Auth Middleware, API Routing, and CORS │
└──────────────┬────────────────────────────┬─────────────┘
│ │
▼ ▼
┌────────────────────────────┐ ┌──────────────────────────┐
│ AI Inference │ │ Serverless Database │
│ Google Gemini (2.5 Flash) │ │ Neon.tech (PostgreSQL) │
│ Generates structured SQL │ │ Stores Users & History │
└────────────────────────────┘ └──────────────────────────┘
- React.js (Vite)
- Tailwind CSS
- React Router DOM (SPA Routing)
- Hosted on Vercel
- Node.js & Express.js
- JSON Web Tokens (JWT) & bcrypt (Authentication)
- Google @google/genai SDK
- Hosted on Render
- PostgreSQL (Serverless via Neon.tech)
- pg Node module (Connection Pooling & SSL)
- Clone the Repository
git clone https://www.google.com/search?q=https://github.com/YOUR_USERNAME/QueryGenie.git
cd QueryGenie- Install Dependencies You will need two terminal windows to run the frontend and backend simultaneously.
Terminal 1: Backend
cd backend
npm install
Terminal 2: Frontend
cd frontend
npm install- Environment Variables Create a .env file in the backend directory and add the following keys.
backend/.env
Server Config
PORT=5001
Database (Neon Serverless Postgres)
DATABASE_URL=postgresql://your_db_owner:your_password@your_neon_host.aws.neon.tech/your_db_name?sslmode=require
Authentication
JWT_SECRET=your_super_secret_jwt_string
AI Provider
GEMINI_API_KEY=your_google_gemini_api_keyCreate a .env file in the frontend directory:
frontend/.env
VITE_API_URL=http://localhost:5000/api- Run the Application
In the backend terminal
npm start
In the frontend terminal
npm run devThe application will be running at http://localhost:5173.
Building this as my first full-stack production grade project involved solving several real-world infrastructure and deployment bottlenecks:
-
Serverless Database Migration: Transitioned from a local Postgres instance to a Neon.tech serverless architecture, implementing conditional SSL routing in Node.js to ensure secure cloud connections without breaking the local development environment.
-
Strict CORS & API Security: Navigated cross-origin resource sharing (CORS) constraints between Vercel and Render by configuring strict origin matching and resolving trailing-slash network rejections.
-
Client-Side Routing in Production: Solved Vercel's SPA (Single Page Application) 404 refresh errors by writing custom vercel.json rewrite rules to hand routing control back to React.
-
AI Output Optimization: Upgraded to the modern @google/genai SDK and resolved token-generation latency by enforcing strict output schemas and optimizing the LLM prompt instructions.
-
Hybrid Schema Resolution: Engineered a dynamic prompt-building system that intelligently toggles between raw text inputs and database-stored schemas, preventing LLM hallucinations and ensuring precise, highly accurate SQL generation.
-
Explainable AI: Demystifies the "black box" of LLM generation by outputting structured JSON that includes both the raw PostgreSQL code and a human-readable, plain-English breakdown of the logic (e.g., explaining why a specific JOIN or aggregation was used).

