Fastify TypeScript backend for OJ Multimedia.
- ⚡ Fastify - Fast and low overhead web framework
- 🔐 JWT Authentication - Secure token-based authentication
- 📦 Redis - Caching and session management
- 🚀 BullMQ - Job queue management
- 📧 Email Service - Nodemailer integration
- 📝 Logging - Pino (HTTP via Fastify; workers/startup via
src/utils/logger) - ☁️ S3 Management - AWS S3 file storage
- 🎨 ESLint & Prettier - Code quality and formatting
- 📅 date-fns - Date manipulation utilities
- ✅ TypeScript - Full type safety
- Node.js 22+
- Redis server
- AWS S3 account (for file storage)
- SMTP server (for email)
- Install dependencies:
npm install- Copy
.env.exampleto.envand configure:
cp .env.example .env- Update
.envwith your configuration values.
# API (HTTP + Socket.io)
npm run dev
# BullMQ worker (separate terminal)
npm run dev:worker
# One-process local setup (colocated worker)
RUN_WORKER=true npm run dev
# Database seed (explicit — not run on API boot)
npm run seedProduction deploys should run API and worker as separate processes — see docs/runbooks/deploy-topology.md.
Business routes are served under /api/v1 (for example /api/v1/public/music, /api/v1/auth/login). Liveness and readiness stay at /health and /ready (unversioned).
Set NODE_ENV=production and provide strong, non-placeholder values for at least:
DATABASE_URLJWT_SECRET(minimum 16 characters)REFRESH_TOKEN_SECRET(minimum 16 characters)
The server refuses to start in production when these are missing or use known default placeholders.
# Build the project
npm run build
# Start the server
npm startBefore deploy:
-
npm run test:unit && npm run test:integration && npm run test:phase:integration -
npm run type-check && npm run lint && npm run format:check -
npm run audit:ci(fails on high or critical vulnerabilities) - Production env secrets verified (no placeholder JWT values)
-
/readyand/healthprobed in the target environment (MongoDB + Redis) - Log aggregator receives
request completedevents withdurationMsfor P95/P99 checks (target P95 ≤ 300ms on critical routes) - 5xx error rate within budget (< 0.5% on stable releases)
- Runbooks reviewed: docs/runbooks (Redis, MongoDB, BullMQ)
- Migrations/seed steps documented; rollback path agreed for this release
- Alerts configured for readiness failures, error spikes, and queue backlog
- Optional internal
GET /metricsreviewed whenENABLE_METRICS_ROUTE=1(see docs/observability.md) - Workspace release guide followed for coordinated deploy
npm run dev- Start development server with hot reloadnpm run build- Build TypeScript to JavaScriptnpm start- Start production servernpm run start:dev- Start with nodemonnpm run lint- Run ESLintnpm run lint:fix- Fix ESLint errorsnpm run format- Format code with Prettiernpm run format:check- Check code formattingnpm run type-check- Type check without buildingnpm run test:unit/test:integration/test:e2e/test:phase:*- Test suites (seetests/README.md)npm run audit- Dependency vulnerability reportnpm run audit:ci- Fail on high or critical vulnerabilitiesnpm run release:check- Type-check, lint, format, tests, phase contract, audit (pre-deploy)
src/
├── config/ # Configuration files
│ ├── env.ts # Environment variables
│ ├── redis.ts # Redis client setup
│ ├── bullmq.ts # BullMQ queue setup
│ └── s3.ts # AWS S3 client setup
├── plugins/ # Fastify plugins (security, auth decorators, observability)
├── repositories/ # Data access layer (Mongoose queries)
├── services/ # Business logic used by controllers
├── controllers/ # Route controllers
├── middleware/ # Custom middleware
├── routes/ # Route definitions
├── services/ # Business logic services
│ ├── auth.service.ts
│ ├── email.service.ts
│ └── s3.service.ts
├── utils/ # Utility functions
│ └── logger.ts # Winston logger
├── types/ # TypeScript type definitions
├── queues/ # BullMQ queue processors
├── plugins/ # Fastify plugins
├── app.ts # Fastify app setup
└── server.ts # Server entry point
See .env.example for all available environment variables.
ISC