Environment & Deployment
All environment variables, local setup, Vercel deployment, database migrations, and cron configuration.
Required environment variables
Database:
DATABASE_URL — PostgreSQL via PgBouncer port 6543 with pgbouncer=true&connection_limit=1
DIRECT_URL — Direct port 5432 for migrations only
Auth:
JWT_SECRET — random 64-character string
SUPER_ADMIN_SECRET — random string
Supabase:
NEXT_PUBLIC_SUPABASE_URL — https://xxxx.supabase.co
SUPABASE_SERVICE_ROLE_KEY — eyJ...
NEXT_PUBLIC_SUPABASE_ANON_KEY — eyJ...
App:
NEXT_PUBLIC_APP_URL — https://doctor.clinit.app
Email:
RESEND_API_KEY — re_...
Payments:
PAYMOB_API_KEY — from Paymob dashboard
PAYMOB_INTEGRATION_ID — from Paymob dashboard
PAYMOB_IFRAME_ID — from Paymob dashboard
PAYMOB_HMAC_SECRET — from Paymob webhook settings
Cron:
CRON_SECRET — random string
DATABASE_URL must use port 6543 (PgBouncer) for serverless safety. Use DIRECT_URL port 5432 only for prisma migrate.
Local development setup
- Clone and install:
npm install
- Configure environment:
cp .env.example .env
Fill in DATABASE_URL, DIRECT_URL, JWT_SECRET, SUPABASE_*, RESEND_API_KEY
- Generate Prisma client:
npx prisma generate
- Push schema to database:
npx prisma db push
- Run Phase migrations in Supabase SQL Editor:
Open SQL Editor > paste phase1_phase2_part1.sql > Run
Open a NEW query tab > paste phase1_phase2_part2.sql > Run
(Two separate transactions required — see note below)
- Seed demo data:
npx prisma db seed
- Start development server:
npm run dev
App runs at http://localhost:3000
Demo login: owner@demo-dental.com / Demo@1234
Why two migration parts: Postgres requires ALTER TYPE ADD VALUE to commit before the new enum value (ARRIVED) can be referenced in any query or index. Running both in the same transaction causes ERROR 55P04. Part 1 adds the value; Part 2 creates the index in a fresh transaction.
Vercel deployment
Build command (set in Vercel dashboard):
prisma generate && next build (using webpack flag)
After schema changes:
- Supabase SQL Editor: run phase1_phase2_part1.sql — wait for Messages panel to show all NOTICE lines
- New Supabase SQL Editor tab: run phase1_phase2_part2.sql
- npx prisma generate locally
- Push to main branch — Vercel auto-deploys
Cron jobs (vercel.json):
Path /api/cron/daily — schedule: 0 2 * * * (02:00 UTC daily)
Path /api/cron/daily?task=reminders — schedule: 0 * * * * (hourly)
Cron routes are protected by Authorization: Bearer CRON_SECRET
Demo credentials
After running npx prisma db seed, 7 demo clinics are created. All use password Demo@1234:
owner@demo-dental.com — Dental
owner@demo-optical.com — Optical
owner@demo-pediatrics.com — Pediatrics
owner@demo-dermatology.com — Dermatology
owner@demo-cardiology.com — Cardiology
owner@demo-physiotherapy.com — Physiotherapy
owner@demo-general.com — General Medicine
Each clinic has: 30 patients, 5 doctors, 45 appointments, and full specialty data including tooth charts, growth records, eye exams, cardiac studies, skin conditions, and treatment plans.