Backend
The API is an Express server in api/src/index.ts, mounted at /api on Vercel and proxied locally during development.
Express & routing
- Express 4 — REST handlers in
api/src/routes/ - Route groups: auth, beats, users, admin, purchases, messages, comments
- Static assets:
/storageand/audiowith Range request support - Health:
GET /health,GET /health/ffmpeg - Socket.IO — real-time messaging when hosted on a persistent server
Authentication
- Email/password register and login with bcrypt
- Google OAuth (
/api/auth/google+ callback) - JWT in
Authorization: Bearerheader - Roles:
USER,PRODUCER,ADMIN - Middleware:
authenticate,authorize,optionalAuthenticate
Security & validation
- helmet, CORS allow-list, rate limiting in production
- Zod — input validation on critical routes
- Centralized
errorHandlermiddleware - File uploads via multer; audio processing with ffmpeg when available
Integrations
- Storage — R2 / local file serving and downloads
- Cloudflare R2 — object storage (
api/src/services/r2.ts) - SMTP — password reset emails
Server structure
api/src/
├── index.ts # Express app entry
├── routes/ # REST route modules
├── middleware/ # auth, security, errors
├── services/ # storage, email, audio
├── config/ # URLs, JWT helpers
└── socket.ts # Socket.IO setupSee the API reference for the full endpoint list.