Skip to content

NitinMoturu72/Querva

Repository files navigation

Querva — AI SQL Assistant

Querva is an AI-powered SQL assistant that converts natural-language questions into accurate, executable SQL queries using your database schema. Upload a schema (SQL, JSON, or CSV), name a conversation, and chat to generate and explain queries.

Live demo

We have a public demo deployed on EC2: http://98.93.163.183/

Use the demo to evaluate functionality before running the app locally.

Highlights

  • Schema support: SQL (CREATE TABLE), structured JSON, and CSV
  • AI query generation and explanation via Groq
  • JWT-based authentication and per-user conversation storage (up to 5 saved conversations)
  • Dockerized (docker-compose) local and production workflows

Tech stack

  • Frontend: React 18 + Vite, TailwindCSS
  • Backend: Node.js 18 + Express
  • Database: PostgreSQL 15
  • AI: Groq API
  • DevOps: Docker Compose, optional EC2/Jenkins deployment

Quick start (recommended)

The easiest way to run Querva locally is with Docker Compose — this starts the frontend, backend, and a Postgres database.

Docker (recommended)

# Build and start services
docker-compose up -d --build

# Follow logs (optional)
docker-compose logs -f

# Stop and remove services
docker-compose down

Manual local development

If you prefer running services on your host machine:

Prerequisites:

  • Node.js 18+
  • PostgreSQL 15+ (or use the Docker Compose Postgres service)
# Clone
git clone https://github.com/NitinMoturu72/Querva.git
cd Querva

# Frontend
npm install
npm run dev

# Backend (another terminal)
cd backend
npm install
cp .env.example .env
# Edit .env with your DB and API keys (see Required API Keys below)
npm run dev

Project layout

querva/
├── src/          # Frontend
├── backend/      # Backend (Express)
├── docker-compose.yml
├── DEPLOYMENT.md # Full deployment guide
└── README.md

Required API keys & environment variables

Copy .env.example to .env and set the following values before running the backend. Keep secrets out of source control.

  • DB_HOST — database host (postgres for Docker Compose, localhost for host runs)
  • DB_PORT — database port (default 5432)
  • DB_NAME — database name (default Querva)
  • DB_USER — database user (default postgres)
  • DB_PASSWORD — database password
  • JWT_SECRET — used to sign JWTs (set a strong random value)
  • GROQ_API_KEY — Groq AI API key (required for AI-powered query generation)
  • VITE_API_URL — frontend API base (default http://localhost:5000/api)

Example .env (local):

DB_HOST=localhost
DB_PORT=5432
DB_NAME=Querva
DB_USER=postgres
DB_PASSWORD=postgres

JWT_SECRET=replace_with_a_strong_secret
GROQ_API_KEY=your_groq_api_key_here

VITE_API_URL=http://localhost:5000/api

Testing

Run the backend tests:

cd backend
npm test

API reference (important endpoints)

  • POST /api/auth/register — create account
  • POST /api/auth/login — login and receive JWT
  • GET /api/auth/me — get authenticated user
  • POST /api/conversations — create a saved conversation (requires auth)
  • GET /api/conversations — list saved conversations (requires auth)
  • POST /api/query — generate SQL from question
  • POST /api/explain — explain a SQL query

Deployment

A production demo is available at: http://98.93.163.183/

For most use cases the Docker Compose workflow above is sufficient for local testing and development.

Notes & next steps

  • Keep JWT_SECRET and GROQ_API_KEY private and rotate them as needed.
  • The app stores conversations and schema in Postgres; use docker-compose down -v to remove volumes when you want a fresh database.
  • If you'd like, I can add a short annotated GIF showing: upload schema → name conversation → start chat, and example .env files for Docker vs local runs.

Questions or changes?

Open an issue or send a PR with suggested improvements. If you want me to add the GIF or an example .env.docker file, tell me which one and I will add it.

  • Delete conversations to free up slots
  • Full schema and message history persisted
  • User isolation enforced at database level

CI/CD Pipeline

Push to main → Jenkins automatically:

  1. ✅ Installs dependencies
  2. ✅ Runs all tests
  3. ✅ Builds Docker images
  4. ✅ Pushes to registry (optional)
  5. ✅ Deploys to EC2
  6. ✅ Health checks

PRs can't merge without passing pipeline! 🔒

Performance Optimizations

  • 💾 PostgreSQL query optimization with indexes
  • 🔄 Conversation history limited to 5 messages for context
  • 📦 Rate limiting prevents abuse

Security Features

  • 🔐 Password hashing with bcrypt
  • 🎫 JWT token-based auth
  • 🚫 Rate limiting on API endpoints
  • 👤 User isolation on database queries
  • 🔑 Environment variable secrets
  • 📝 SQL prepared statements (parameterized queries)

Troubleshooting

Backend won't connect to database

# Check PostgreSQL is running
docker-compose ps

# Check connection in logs
docker-compose logs backend

Tests failing

# Make sure test database exists
docker-compose up postgres -d

# Run tests with verbose output
cd backend && npm test -- --verbose

Nginx returns 502 Bad Gateway

# Check backend is running
curl http://localhost:5000/health

# Check Nginx logs
sudo tail -f /var/log/nginx/error.log

See DEPLOYMENT.md Troubleshooting for more.

Contributing

  1. Fork repository
  2. Create feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open Pull Request

Pull requests require:

  • ✅ Tests passing (Jest)
  • ✅ Linting pass
  • ✅ Code review approval
  • ✅ Branch protection enforced

Development Workflow

# Start local development
npm run dev              # Frontend (port 5173)
cd backend && npm run dev # Backend (port 5000)

# Run tests
cd backend && npm test

# Run tests in watch mode
cd backend && npm run test:watch

# Build for production
npm run build

# Build Docker images
docker-compose build

# Deploy to AWS
# Push to main, Jenkins handles rest
git push origin main

Monitoring

Local Development

Roadmap

  • HTTPS/SSL with Let's Encrypt
  • User profiles and preferences
  • Query history and favorites
  • Real-time collaboration
  • Database connection testing
  • Advanced query suggestions
  • Slack bot integration
  • API documentation (Swagger)
  • Performance analytics

License

MIT License - see LICENSE file

Support

  • 🧪 Testing Guide
  • 💬 Open an issue for bugs
  • 🚀 Discussions for features

Built with ❤️ by the Querva team

Latest commit: git log -1 --oneline

Docker ready • Tested • Production-grade CI/CD

About

AI-powered natural language to SQL query generator. Upload your database schema and chat to generate accurate SQL queries.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors