Skip to content

amanaks8055/QuerySense

Repository files navigation

Deployed on Render TypeScript React Node.js PostgreSQL Docker

QuerySense 🧠

AI-Powered Natural Language to SQL Query Assistant with Real-Time Insights

Live Demo: querysense.onrender.com

Note: Backend may take 30 seconds to wake from sleep on first request (free tier)


🎯 Overview

QuerySense is a modern full-stack web application that transforms natural language questions into SQL queries using AI, executes them safely on a PostgreSQL database, and provides intelligent business insights in real-time.

Perfect for demonstrating full-stack development, AI integration, real-time features, and Docker deployment skills.


✨ Key Features

  • πŸ€– AI-Powered Query Generation - OpenRouter API integration (GPT-4, Claude, Gemini support)
  • πŸ”’ Safe SQL Execution - Sandboxed execution with validation and timeout protection
  • ⚑ Real-Time Updates - WebSocket notifications throughout query lifecycle
  • πŸ“Š Interactive Results - Beautiful data tables with insights
  • πŸ’‘ Business Insights - AI-generated actionable recommendations
  • πŸ‘₯ Role-Based Access - User and Admin roles with different permissions
  • πŸ“ˆ Admin Dashboard - System analytics and query monitoring
  • 🎨 Premium Dark UI - Modern glassmorphism design with smooth animations
  • 🐳 Docker Ready - Complete containerization with Docker Compose

πŸ—οΈ Tech Stack

Frontend

  • React 18 + TypeScript
  • Vite (build tool)
  • Framer Motion (animations)
  • Socket.IO Client (real-time)
  • Axios (HTTP)

Backend

  • Node.js + Express
  • TypeScript
  • Socket.IO (WebSocket server)
  • PostgreSQL + pg
  • JWT authentication
  • bcrypt (password hashing)

Infrastructure

  • Docker + Docker Compose
  • PostgreSQL 15
  • Nginx (production)
  • Render.com (deployment)

πŸš€ Quick Start

Option 1: Docker (Recommended)

# Clone repository
git clone https://github.com/YOUR_USERNAME/querysense.git
cd querysense

# Configure environment
cp .env.example .env
# Edit .env and add your OPENROUTER_API_KEY

# Launch with Docker
docker-compose up --build

# Access the app
# Frontend: http://localhost:5173
# Backend: http://localhost:3000

Option 2: Local Development

Backend:

cd backend
npm install
npm run dev  # http://localhost:3000

Frontend:

cd frontend
npm install
npm run dev  # http://localhost:5173

πŸ”‘ Demo Credentials

User Account:

  • Email: demo@querysense.app
  • Password: demo123

Admin Account:

  • Email: admin@querysense.app
  • Password: admin123

πŸ’‘ Example Queries

Try asking:

  • "Show me all customers from USA"
  • "What are the top 5 best-selling products?"
  • "Calculate total revenue by product category"
  • "List all pending orders from the last week"
  • "Which customers haven't ordered in 30 days?"

πŸ“ Project Structure

querysense/
β”œβ”€β”€ backend/              # Express API server
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ config/      # Database configuration
β”‚   β”‚   β”œβ”€β”€ cont rollers/ # Route handlers
β”‚   β”‚   β”œβ”€β”€ middleware/  # Auth, validation
β”‚   β”‚   β”œβ”€β”€ models/      # TypeScript interfaces
β”‚   β”‚   β”œβ”€β”€ routes/      # API endpoints
β”‚   β”‚   β”œβ”€β”€ services/    # Business logic (AI, SQL, WebSocket)
β”‚   β”‚   └── index.ts     # Server entry point
β”‚   └── Dockerfile
β”œβ”€β”€ frontend/            # React SPA
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/  # Reusable UI components
β”‚   β”‚   β”œβ”€β”€ pages/       # Main pages
β”‚   β”‚   β”œβ”€β”€ services/    # API, Socket.IO clients
β”‚   β”‚   └── styles/      # CSS design system
β”‚   └── Dockerfile
β”œβ”€β”€ database/
β”‚   β”œβ”€β”€ init.sql        # Schema definition
β”‚   └── seed.sql        # Demo data
└── docker-compose.yml  # Service orchestration

πŸ”’ Security Features

  • βœ… SQL injection prevention
  • βœ… SELECT-only query execution
  • βœ… Query timeout limits (10s)
  • βœ… JWT authentication
  • βœ… Password hashing (bcrypt)
  • βœ… CORS protection
  • βœ… Environment-based secrets

🌐 Deployment

See RENDER_DEPLOYMENT_GUIDE.md for complete deployment instructions.

Quick Deploy to Render:

  1. Push to GitHub
  2. Create Render account
  3. Deploy database, backend, frontend
  4. Done! (~15 minutes)

Alternative Options:


πŸ“Š API Endpoints

Authentication

  • POST /api/auth/register - Register user
  • POST /api/auth/login - Login user
  • GET /api/auth/profile - Get profile (protected)

Queries

  • POST /api/query - Submit new query (protected)
  • GET /api/query/history - Get query history (protected)
  • GET /api/query/:id - Get specific query (protected)

Admin

  • GET /api/admin/analytics - System analytics (admin only)
  • GET /api/admin/users - All users (admin only)
  • GET /api/admin/queries - All queries (admin only)

🎯 Skills Demonstrated

This project showcases:

  • βœ… Full-stack TypeScript development
  • βœ… AI/ML API integration
  • βœ… Real-time WebSocket communication
  • βœ… PostgreSQL database design
  • βœ… RESTful API development
  • βœ… Docker containerization
  • βœ… Authentication & authorization
  • βœ… Modern React patterns
  • βœ… Production deployment
  • βœ… Security best practices

πŸ“Έ Screenshots

Coming soon - deploy to Render first!


🀝 Contributing

This is a portfolio project, but suggestions are welcome!


πŸ“ License

MIT License - Free to use for learning and portfolio purposes


πŸ‘€ Author

Your Name

  • GitHub: Aman Sharma

πŸ™ Acknowledgments

  • OpenRouter for AI API access
  • Render for free hosting
  • PostgreSQL community
  • React & Node.js ecosystems

⭐ Star this repo if you found it helpful!

Built with ❀️ for learning and demonstration

About

QuerySense is a production-ready AI-powered web application that converts natural language questions into SQL queries, executes them safely, and provides intelligent business insights in real-time.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors