Next.js frontend for QueryLab, a zero-install, in-browser PostgreSQL learning application powered by PGlite.
- Node.js 18+
- npm or pnpm
- Backend API running (see Backend README)
-
Clone the repository (if not already done):
git clone https://github.com/zamdevio/querylab.git cd querylab/Frontend -
Install dependencies:
npm install
-
Configure API URL:
Create
Frontend/.env.localfile (this file is gitignored):NEXT_PUBLIC_API_URL=http://localhost:8787
Or update
src/lib/config.ts:const DEFAULT_API_URL = 'http://localhost:8787';
-
Start development server:
npm run dev
The frontend will run on
http://localhost:3000
| Variable | Description | Required |
|---|---|---|
NEXT_PUBLIC_API_URL |
Backend API URL | Yes |
The API URL can be set in two ways:
-
Environment variable (recommended for production):
NEXT_PUBLIC_API_URL=https://your-api.workers.dev
-
Config file (
src/lib/config.ts):const DEFAULT_API_URL = 'https://your-api.workers.dev';
Priority: Environment variable > Config file default
- Next.js 16: React framework with App Router
- React 19: UI library
- PGlite: PostgreSQL compiled to WebAssembly for client-side execution
- Monaco Editor: VS Code's editor for SQL editing
- Tailwind CSS: Utility-first CSS framework
- IndexedDB: Browser storage for database persistence
- Lucide React: Icon library
Frontend/
├── src/
│ ├── app/
│ │ ├── layout.tsx # Root layout
│ │ ├── page.tsx # Main application page
│ │ └── docs/
│ │ └── page.tsx # Documentation page
│ ├── components/ # React components
│ │ ├── Editor.tsx # Monaco SQL editor
│ │ ├── ResultTable.tsx # Query results table
│ │ ├── SchemaExplorer.tsx # Database schema viewer
│ │ ├── AiModal.tsx # AI query generation
│ │ ├── LoginModal.tsx # User authentication
│ │ └── ...
│ └── lib/
│ ├── config.ts # Configuration
│ ├── api.ts # API client
│ ├── sqlClient.ts # PGlite database client
│ ├── indexedDb.ts # IndexedDB persistence
│ └── ...
├── public/ # Static assets
├── next.config.js # Next.js configuration
└── package.json
- Client-Side PostgreSQL: All SQL execution happens in the browser using PGlite
- AI Integration: Generate and fix SQL queries using AI
- Database Persistence: Databases stored in IndexedDB
- Import/Export: Load and save .sql files
- Schema Explorer: Visualize database structure
- Responsive Design: Mobile-first, works on all devices
- Dark Mode: Automatic theme switching
📖 SQL Editor Guide: See
../Documentations/sql-editor.mdfor detailed SQL editor features and keyboard shortcuts
📖 Database Management: See
../Documentations/database-management.mdfor import/export and database operations
📖 AI Features: See
../Documentations/ai-features.mdfor AI-powered SQL generation and error fixing
npm run devVisit http://localhost:3000
npm run buildOutput will be in the out/ directory (static export).
npm run lint📖 Detailed Deployment Guide: See
../Documentations/deployment.mdfor complete step-by-step deployment instructions for all platforms
-
Build the project:
npm run build
-
Deploy using Wrangler:
npm run cf:deploy
Or manually:
wrangler pages deploy out --project-name querylab
-
Set environment variables in Cloudflare Pages dashboard:
NEXT_PUBLIC_API_URL: Your backend Worker URL
-
Connect your GitHub repository to Vercel
-
Set environment variables:
NEXT_PUBLIC_API_URL: Your backend API URL
-
Deploy: Vercel will automatically build and deploy
- Build command:
npm run build - Publish directory:
out - Environment variables:
NEXT_PUBLIC_API_URL: Your backend API URL
The frontend needs to know where the backend API is located.
For local development:
# .env.local
NEXT_PUBLIC_API_URL=http://localhost:8787For production: Set in your deployment platform's environment variables:
- Cloudflare Pages: Settings > Environment Variables
- Vercel: Project Settings > Environment Variables
- Netlify: Site Settings > Environment Variables
- Theme: Edit
src/lib/theme.tsxfor theme configuration - API Client: Modify
src/lib/api.tsfor API behavior - Database Client: Update
src/lib/sqlClient.tsfor PGlite configuration
- Verify
NEXT_PUBLIC_API_URLis set correctly - Check backend is running and accessible
- Check browser console for CORS errors
- Verify backend CORS allows your frontend domain
- Check IndexedDB is enabled in browser
- Clear browser storage and try again
- Check browser console for errors
- Verify PGlite WASM files are loading
- Ensure all dependencies are installed:
npm install - Check Node.js version (18+ required)
- Clear
.nextandoutdirectories and rebuild - Check for TypeScript errors:
npm run lint
- Verify cookies are enabled in browser
- Check backend authentication endpoints are working
- Ensure CORS credentials are configured correctly
- Check browser console for cookie-related errors
See the main README.md for contribution guidelines.