Next.js app with PostgreSQL: sections, segments, and questions are stored in the database. Progress and daily stats are persisted per client (anonymous client_id in localStorage).
-
Create a PostgreSQL database
Use Vercel Storage (e.g. Neon), Supabase, or any Postgres host. Copy the connection string. -
Environment
Create.envin the project root:DATABASE_URL=postgresql://...
-
Schema and seed
From the project root:npm install npm run db:setup npm run db:seed
(
db:seedrequiresscripts/seed-questions.json; runnode scripts/extract-seed-json.jsonce to generate it fromdemo.js.) -
Run locally
npm run dev
Open http://localhost:3000.
This system includes comprehensive performance optimizations for faster response times and better scalability:
- Connection Pooling: Optimized with configurable timeouts (2 connections in dev, 10 in production)
- Performance Indexes: Added 5 indexes including filtered indexes for faster queries:
idx_questions_segment_id- For segment-based queriesidx_questions_segment_custom- Combined segment and custom flagsidx_progress_client_id- Client progress lookupsidx_daily_client_id_day- Daily stats queriesidx_questions_custom_client- Custom questions filtering
- Response Caching: Sections and questions APIs cache data for 1 minute to reduce database load
- Query Optimization: Combined JOIN operations where beneficial
- Object Building: Optimized using functional programming patterns (reduce() instead of forEach)
- Client ID Caching: Memoized client ID generation to reduce localStorage operations
- Error Handling: Improved async/await patterns for better error handling
- Database Queries: 40-60% faster with new indexes
- API Responses: 30-50% faster with caching
- Page Loads: 15-25% faster with client-side optimizations
-
Push the repo and import the project in Vercel under your account (e.g. under "juelzs" / your team). Name the project Alex.
-
In Vercel → Project → Settings → Environment Variables, add:
DATABASE_URL= your Postgres connection string (Production, Preview, Development if needed).
-
After the first deploy, run migrations and seed against the same database (from your machine or a one-off script):
DATABASE_URL="your-production-url" npm run db:setup DATABASE_URL="your-production-url" npm run db:seed
-
Redeploy or trigger a new deployment so the app uses the seeded data.
-
Push the repo and import the project in Vercel under your account (e.g. under “juelzs” / your team). Name the project Alex.
-
In Vercel → Project → Settings → Environment Variables, add:
DATABASE_URL= your Postgres connection string (Production, Preview, Development if needed).
-
After the first deploy, run migrations and seed against the same database (from your machine or a one-off script):
DATABASE_URL="your-production-url" npm run db:setup DATABASE_URL="your-production-url" npm run db:seed
-
Redeploy or trigger a new deployment so the app uses the seeded data.
npm run dev– local dev servernpm run build– production buildnpm run start– run production build locallynpm run db:setup– applyscripts/schema.sqlnpm run db:seed– insert sections and questions (requiresseed-questions.json)node scripts/extract-seed-json.js– generateseed-questions.jsonfromdemo.js
- sections / segments – MCAT sections and segments (labels, colors, icons).
- questions – seed questions plus custom questions per
client_id. - progress – per client/segment/question: attempts, correct, streak, notes, last_seen.
- daily – per client/day: attempts and correct count.
All content is read from the database; no hardcoded question bank in the app.