All accounts use a one-time default password. On first login, the platform forces a mandatory password reset before granting access — an industry-standard security practice.
| Username | Default Password | Role | Access Level |
|---|---|---|---|
admin_sarah |
password123 |
Admin | User management, permissions, audit logs |
dba_michael |
password123 |
DBA | Full DDL/DML, schema browser, query execution |
user_jessica |
password123 |
User | SELECT on granted tables, export results |
💡 To reset accounts to default: run
backend/seed.sqlin your Supabase SQL Editor.
|
|
|
|
|
|
┌─────────────────────────────────────────────────────────┐
│ CLIENT (Vercel) │
│ React 18 + Vite + Monaco Editor + Split.js │
│ Landing → Login → [User | DBA | Admin] Dashboard │
└──────────────────────┬──────────────────────────────────┘
│ HTTPS + httpOnly Cookies
┌──────────────────────▼──────────────────────────────────┐
│ BACKEND (Render) │
│ Express.js + Helmet + CORS + Rate Limiter │
│ │
│ ┌─────────────┐ ┌──────────────┐ ┌───────────────┐ │
│ │ JWT Auth │ │ RBAC Middle │ │ Query │ │
│ │ Middleware │ │ -ware │ │ Validator │ │
│ └─────────────┘ └──────────────┘ └───────────────┘ │
│ │
│ ┌─────────────┐ ┌──────────────┐ ┌───────────────┐ │
│ │ Groq │ │ Audit │ │ Permission │ │
│ │ Service │ │ Service │ │ Service │ │
│ └─────────────┘ └──────────────┘ └───────────────┘ │
└──────────┬───────────────────────────────┬──────────────┘
│ │
┌──────────▼──────────┐ ┌─────────────▼──────────────┐
│ Supabase │ │ Groq API │
│ PostgreSQL │ │ LLaMA 3.3 70B │
│ (Schema + Data) │ │ (SQL Generation) │
└─────────────────────┘ └────────────────────────────┘
User Request
│
▼
┌─────────────────────┐
│ Rate Limiter │ ← 10 req/min per IP (query routes)
│ Helmet.js Headers │ ← XSS, CSRF, clickjacking protection
│ CORS Whitelist │ ← Frontend origin only
└────────┬────────────┘
│
▼
┌─────────────────────┐
│ JWT Verification │ ← httpOnly cookie, role embedded
│ Session Check │ ← Suspended users blocked
└────────┬────────────┘
│
▼
┌─────────────────────┐
│ RBAC Middleware │ ← Role-based route access
│ Permission Check │ ← Table-level permission lookup
└────────┬────────────┘
│
▼
┌─────────────────────┐ ← Layer 1: AI refuses unauthorized ops
│ Groq AI Layer │ ← Schema DDL only — zero row data
└────────┬────────────┘
│
▼
┌─────────────────────┐ ← Layer 2: node-sql-parser AST check
│ Query Validator │ ← Blocks DDL/TCL for users
│ (node-sql-parser) │ ← Verifies table permissions
│ Row Limit Injector │ ← Appends LIMIT N silently
└────────┬────────────┘
│
▼
┌─────────────────────┐
│ Supabase Execute │ ← Query runs only if all layers pass
│ Audit Logger │ ← Every execution logged, append-only
└─────────────────────┘
| Layer | Technology | Purpose |
|---|---|---|
| Frontend | React 18 + Vite | UI framework |
| Editor | Monaco Editor | SQL editor with syntax highlighting |
| Layout | Split.js | Resizable panels |
| Routing | React Router v6 | SPA navigation |
| HTTP Client | Axios | API calls with cookie support |
| Icons | Lucide React | UI icons |
| Backend | Node.js + Express | REST API server |
| Auth | JWT + bcryptjs | Secure authentication |
| Database | Supabase (PostgreSQL) | Data storage |
| AI | Groq (LLaMA 3.3 70B) | SQL generation |
| SQL Parser | node-sql-parser | Query validation |
| Security | Helmet.js + CORS | HTTP hardening |
| Rate Limiting | express-rate-limit | Abuse prevention |
| Brevo API | Transactional emails (OTP, resets, credentials) | |
| Deployment | Vercel + Render | Frontend + Backend hosting |
AI_Powered_SQL_Query_Generator/
├── backend/
│ ├── src/
│ │ ├── config/ # DB + env configuration
│ │ ├── middleware/ # Auth, RBAC, rate limiter, validator
│ │ ├── controllers/ # Route handlers
│ │ ├── routes/ # API route definitions
│ │ └── services/ # Groq, audit, permission services
│ ├── seed.sql # Database schema + demo data
│ └── .env.example # Environment variable template
├── frontend/
│ ├── src/
│ │ ├── components/ # Reusable UI components
│ │ │ ├── Editor/ # Monaco + Results panel
│ │ │ ├── AIAssistant/ # AI suggestion panel
│ │ │ ├── Sidebar/ # User + DBA sidebars
│ │ │ └── shared/ # Navbar, RouteGuard, Toast
│ │ ├── pages/ # Login, Dashboards, Landing
│ │ ├── hooks/ # useAuth, useDebounce
│ │ ├── services/ # Axios API instance
│ │ └── styles/ # Theme + global CSS
│ └── vercel.json # SPA routing config
└── README.md
# Clone the repository
git clone https://github.com/mohdarsh786/AI_Powered_SQL_Query_Generator.git
cd AI_Powered_SQL_Query_Generator
# Setup backend
cd backend
cp .env.example .env
# Fill in your values in .env
npm install
npm run dev
# Setup frontend (new terminal)
cd frontend
echo "VITE_API_URL=http://localhost:5000" > .env
npm install
npm run dev- Go to your Supabase project → SQL Editor
- Run the entire contents of
backend/seed.sql - Run the first-login migration:
ALTER TABLE app_users
ADD COLUMN IF NOT EXISTS requires_password_change BOOLEAN DEFAULT FALSE;
UPDATE app_users
SET requires_password_change = TRUE
WHERE username IN ('admin_sarah', 'dba_michael', 'user_jessica');Backend .env:
PORT=5000
NODE_ENV=development
FRONTEND_URL=http://localhost:5173
SUPABASE_URL=your_supabase_url
SUPABASE_SERVICE_ROLE_KEY=your_service_role_key
SUPABASE_ANON_KEY=your_anon_key
JWT_SECRET=your_jwt_secret_min_32_chars
JWT_EXPIRES_IN=7d
GROQ_API_KEY=your_groq_api_key
BREVO_API_KEY=your_brevo_api_key
BREVO_FROM_EMAIL=noreply@yourdomain.comFrontend .env:
VITE_API_URL=http://localhost:5000User logs in with default password (password123)
│
▼
Backend checks requires_password_change flag
│
┌─────▼─────┐
│ TRUE │ → Issues 15-min temp_token (purpose: password_change only)
└─────┬─────┘ Frontend redirects to /change-password
│
▼
User sets new password
(min 8 chars, strength meter, cannot reuse password123)
│
▼
Backend: bcrypt hash saved, flag set FALSE
Real JWT issued → User enters platform
│
┌─────▼─────┐
│ FALSE │ → Normal login, real JWT issued immediately
└───────────┘
| Permission | Admin | DBA | User |
|---|---|---|---|
| SELECT queries | ✗ | ✓ | ✓ (granted tables) |
| INSERT / UPDATE | ✗ | ✓ | ✓ (if granted) |
| DELETE | ✗ | ✓ + confirmation | ✓ (if granted) |
| DDL (CREATE/DROP) | ✗ | ✓ + confirmation | ✗ |
| COMMIT / ROLLBACK | ✗ | ✓ | ✗ |
| Grant permissions | ✓ | ✓ (user-level) | ✗ |
| User management | ✓ | ✗ | ✗ |
| Audit log access | ✓ | ✗ | ✗ |
| Row limit enforcement | Sets limits | No limit | Enforced |
| Export results | ✗ | ✓ | ✓ (if granted) |
Features planned for v2.0:
- SSO / SAML — Enterprise single sign-on integration
- Query Scheduling — Schedule recurring queries with result notifications
- Real-time Collaboration — Multiple users editing queries simultaneously
- OAuth Integration — Google/GitHub SSO support
MIT License — see LICENSE for details.