Monorepo: Express + Prisma + MySQL API and React + Vite SPA for customer analytics, auth, and KPI/segmentation endpoints.
| Component | Version (tested expectation) |
|---|---|
| Node.js | >= 20 |
| npm | >= 10 |
| MySQL | >= 8 |
Pin your local toolchain to satisfy the table above before installing dependencies. The backend documents the same constraints in backend/Requirements.txt.
REST-app/
backend/ # REST API (TypeScript, Express, Prisma)
frontend/ # SPA (React, Vite)
-
Node.js 20+ and npm 10+
Verify:node -v npm -v
-
MySQL 8+ running locally (or reachable network host) with permission to create a database.
-
Git (for clone/checkout).
Create an empty database matching your DATABASE_URL (default name from .env.example: customer_analytics).
Example (MySQL client):
CREATE DATABASE customer_analytics CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;Ensure the user in DATABASE_URL has CREATE, ALTER, SELECT, INSERT, UPDATE, DELETE on that schema (Prisma migrations need DDL).
All commands below are run from backend/.
Copy the example file and edit secrets:
cd backend
cp .env.example .envRequired / validated behavior (see src/config/env.ts):
DATABASE_URL— non-empty MySQL URL.JWT_SECRET— at least 16 characters.JWT_REFRESH_SECRET— at least 16 characters (or omit and the app may derive fromJWT_SECRETin development only; set explicitly in production).
Example shape (adjust user, password, host, port, database):
DATABASE_URL="mysql://USER:PASSWORD@localhost:3306/customer_analytics"
JWT_SECRET="replace-with-strong-access-secret-min-16-chars"
JWT_REFRESH_SECRET="replace-with-strong-refresh-secret-min-16-chars"
CORS_ORIGIN="http://localhost:5173"Keep .env out of version control; use .env.example as the contract.
npm installnpm run prisma:generate
npm run prisma:migrate -- --name init
npm run prisma:seedReproducibility note: After pulling new commits, run npm install and npm run prisma:migrate again so your schema matches prisma/migrations.
npm run devDefault: listens on http://localhost:4000 (override with PORT in .env).
npm run build
npm run startnpm run testnpm run perf:benchmarkWrites a report under backend/outputs/perf/ (see backend/README.md).
All commands below are run from frontend/.
cd frontend
cp .env.example .envDefault API base:
VITE_API_BASE_URL=http://localhost:4000/api/v1Change this if the API runs on another host/port. Must match backend CORS_ORIGIN (browser origin) and the actual API URL.
npm install
npm run devVite dev server defaults to http://localhost:5173, which aligns with CORS_ORIGIN in backend/.env.example.
npm run testnpm run build
npm run preview # optional local preview of production bundle- Backend:
cd backend && npm run dev— confirm log shows API on port 4000. - Frontend:
cd frontend && npm run dev— open http://localhost:5173. - Register or log in via the UI (auth routes under
/api/v1/auth/*).
If login fails with CORS errors, align CORS_ORIGIN with the exact origin Vite prints (scheme + host + port).
Base path: /api/v1.
Detailed route list and behaviors: backend/README.md.
| Symptom | Likely cause |
|---|---|
Invalid environment configuration on backend start |
Missing/short JWT_SECRET or JWT_REFRESH_SECRET, or missing DATABASE_URL. |
| Prisma migration errors | Wrong DATABASE_URL, DB user lacks DDL rights, or MySQL not running. |
| CORS / cookie auth issues | CORS_ORIGIN does not match the SPA origin; COOKIE_SECURE vs HTTPS mismatch in production. |
| Frontend cannot reach API | Wrong VITE_API_BASE_URL; API not running; rebuild frontend after changing .env (Vite embeds env at build time for production). |
- Do not commit
backend/.envorfrontend/.env. - Use strong, independent values for JWT secrets in any shared or production environment.
See repository files for license terms (if applicable).