EcoTrack is The Circular Classroom's unified web platform for donation collection, inventory operations, analytics, reporting, and user administration.
This repository represents a migration from multi-service AWS infrastructure to a single Next.js application on Vercel with Supabase.
The current platform consolidates legacy systems into one codebase:
- AWS Cognito -> Supabase Auth
- AWS Lambda / ECS backends -> Next.js API Route Handlers
- AWS S3 -> Supabase Storage
- AWS SES / SNS -> Resend
- AWS-hosted PostgreSQL -> Supabase PostgreSQL (with Prisma)
Design goals implemented in this codebase:
- Single deployable Next.js app
- Shared domain logic under
lib/* - API-first backend surface under
app/api/* - Property-based and integration testing for migration correctness
- Authentication and account management
- Role-based access control (Admin, SchoolStaff, PsgVolunteer, Parent)
- User management and sync flows
- Inventory item types, balances, and transaction state transitions
- Donation drives and collection workflows
- CSV/Excel upload, validation, approval, and processing pipeline
- Analytics (overview, collection, assembly, school)
- PDF report generation and health monitoring
- Next.js 16 App Router
- TypeScript
- React 19
- MUI 7 + Emotion
- Tailwind CSS 4
- Recharts
- Prisma 7 + PostgreSQL (
@prisma/adapter-pg+pg) - Supabase (Auth + Storage)
- Resend (email)
- Vitest + fast-check
- pnpm
- UI routes and server rendering:
app/* - API handlers:
app/api/* - Domain logic:
lib/auth,lib/csv,lib/inventory,lib/analytics,lib/reports - Data layer:
lib/prisma/client.ts+prisma/schema.prisma - Supabase client factories:
lib/supabase/client.ts,lib/supabase/server.ts,lib/supabase/admin.ts - Middleware auth enforcement:
proxy.ts
app/
api/ # Auth, users, inventory, csv, analytics, reports, health
auth/ # Login, signup, reset, forgot, mfa, set-new-password flows
analytics/ # Dashboard pages
inventory/ # Inventory pages and subroutes
users/ # User management pages
components/ # Shared UI building blocks and domain widgets
lib/
auth/ # Validation, role checks, auth helpers
csv/ # Parse, validate, process pipeline
inventory/ # Balance and transaction rules
analytics/ # Metrics and aggregation logic
reports/ # PDF report logic
supabase/ # Browser/server/admin clients
prisma/ # Prisma client singleton
prisma/
schema.prisma
migrations/
__tests__/
- Node.js LTS
- pnpm 11+
- Supabase project credentials
- Postgres connection strings
pnpm installStart from the provided template:
cp .env.local.example .env.localRequired app keys:
# Supabase
NEXT_PUBLIC_SUPABASE_URL=
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=
SUPABASE_SECRET_KEY=
# Database
POSTGRES_PRISMA_URL=
POSTGRES_URL_NON_POOLING=
# Email
RESEND_API_KEY=
RESEND_FROM_EMAIL=Notes:
- Runtime validation is in
lib/env.ts. POSTGRES_PRISMA_URLis used for app queries.POSTGRES_URL_NON_POOLINGis used for migration/direct DB workflows.
pnpm devpnpm dev # Start development server
pnpm build # prisma generate + next build
pnpm start # Start production server
pnpm lint # Lint
pnpm test # Run tests once
pnpm test:watch # Watch tests
pnpm db:generate # Prisma client generation
pnpm db:migrate # Deploy migrations
pnpm db:push # Push schema (no migration files)
pnpm db:seed # Run seed command (if configured)Implemented under app/api/*:
auth/*: login, signup/register, mfa, password recovery, session/refresh, profileusers/*: list/create/update/delete/deactivate/sync/meinventory/*: item types, balances, transactions, config entitiescsv/*: upload, validate, approve processinganalytics/*: overview, collection, assemblydonations/*: donation drive operationsreports/*andreport/*: report payloads and PDF generationstorage/*: image/file storage operationshealth: system health + DB connectivity
- Unified Prisma schema in
prisma/schema.prisma User.supabaseAuthIdis the auth identity anchor- Middleware enforces protected-route auth and role checks
- Role model:
Admin,SchoolStaff,PsgVolunteer,Parent - RLS migration artifacts are included in Prisma migrations for DB-level defense-in-depth
Typical flow:
- Upload file (
csv,xls,xlsx) to pre-processing storage - Validate required fields and DB constraints
- Move to validated or failed storage path
- Notify uploader by email
- Admin approval triggers atomic DB write transaction
- Move successfully processed files to processed path
This repository includes:
- Integration tests for auth, CSV pipeline, inventory, and reporting flows
- Property-based tests for core correctness properties such as:
- role and auth validation
- pagination bounds
- file size/type validation
- transaction state transitions
- CSV validation invariants
- analytics filter validation
Run tests:
pnpm test- Deployment target: Vercel
- Build command:
pnpm build - Runtime command:
pnpm start - Project config:
vercel.json
For production and preview, set environment variables in Vercel project settings.
- The implementation intentionally preserves existing backend route behavior while modernizing the frontend and deployment surface.
- Some migration documents reference alternate env variable names (for example
*_ANON_KEYand*_SERVICE_ROLE_KEY), while this codebase usesNEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEYandSUPABASE_SECRET_KEYas the canonical keys.
pnpmis enforced viapreinstall.- Prisma client generation runs in
postinstall. pdfkitis configured as a server external package in Next.js config.