How fikriandrrhm19/wad-capstone works
Purpose and Runtime Entry Points
This repository is the Node.js backend for a task-management platform. It exposes REST APIs, Swagger documentation, health checks, and Socket.IO real-time updates for a separate React frontend. The application starts in src/index.js; Socket.IO integration is defined in src/socket.js; API documentation is configured in src/docs/swagger.js.
HTTP Composition and Request Boundary
Express routes aggregate task, milestone, authentication, user, and admin endpoints. Requests flow from route definitions to controllers, then into service/repository layers where applicable.
• src/routes/index.js
• src/routes/tasks.routes.js
• src/routes/milestones.routes.js
• src/routes/auth.routes.js
The public API boundary includes REST endpoints, /health, and Swagger UI. Cross-origin, rate-limiting, Prisma, and other app-wide setup reside under src/config/.
Security and Identity Lifecycle
Authentication uses JWT access tokens plus persisted refresh tokens with rotation. Credentials and token operations are centralized in the auth service; refresh-token persistence is separate from user persistence. Middleware enforces identity, role permissions, ownership, validation, and input sanitization before protected controller actions.
• src/services/auth.service.js
• src/repositories/refreshToken.repository.js
• src/middleware/authenticate.js
• src/middleware/authorize.js
• src/middleware/checkOwnership.js
Task and Milestone Domain
Tasks and milestones are the primary business entities. CRUD operations support task ownership and assignment constraints, while milestone relationships enable milestone progress derived from linked task status. Controller-facing logic is backed by Prisma repositories rather than direct database calls.
• src/controllers/tasks.controller.js
• src/controllers/milestone.controller.js
• src/repositories/task.repository.js
• src/repositories/milestone.repository.js
A legacy/in-memory task store also exists at src/data/tasks.store.js, but the repository layer and Prisma schema define the durable application path.
Persistence Model
PostgreSQL is accessed through Prisma. The schema and migrations establish users, roles, tasks, milestones, and refresh-token relationships; seed data supports local initialization.
• prisma/schema.prisma
• src/config/prisma.js
• prisma/migrations/20260616133554_add_milestone_model_and_relations/migration.sql
• prisma/seed.js
The database is intended to remain private to the application host; no external clients should bypass the API/repository boundary.
Real-Time Synchronization
Socket.IO runs alongside Express and broadcasts task and milestone lifecycle events, notifications, and online-user counts. REST mutations are the likely command path; after successful persistence, the backend emits events so connected frontend clients synchronize without polling.
• src/socket.js
• src/controllers/tasks.controller.js
• src/controllers/milestone.controller.js
Key broadcast categories are task/milestone create-update-delete, including milestone progress updates caused by task state changes.
Deployment and External Infrastructure
Production consists of a Node.js 20+ backend managed by PM2 behind Nginx. Nginx proxies /api and /socket.io to the backend, while a separately deployed React frontend is proxied at /. PostgreSQL runs locally on the VPS; Cloudflare provides DNS/edge HTTPS handling. Deployment automation is implemented through GitHub Actions and SSH.
• .github/workflows/deploy.yml
• src/index.js
• .env.example
Main entry points: routes/index.js REST, health, and Swagger · prisma.js Prisma client · src/index.js Node backend · authenticate.js Identity and authorization
Components 21
Backend Runtime
- Node backend · PM2-managed Node.js application.
src/index.js - REST, health, and Swagger
src/routes/index.js - Swagger docs
src/docs/swagger.js - Socket.IO · Broadcasts lifecycle events and presence updates.
src/socket.js
Application Domain
- Auth routes
src/routes/auth.routes.js - Task routes
src/routes/tasks.routes.js - Milestone routes
src/routes/milestones.routes.js - Identity and authorization · Authenticates JWTs and enforces roles and ownership.
src/middleware/authenticate.js - Auth service · Issues access tokens and rotates persisted refresh tokens.
src/services/auth.service.js - Task controller · Applies task commands and emits realtime updates after persistence.
src/controllers/tasks.controller.js - Milestone controller · Maintains milestones and derived progress from task state.
src/controllers/milestone.controller.js
Persistence
- Task repository
src/repositories/task.repository.js - Milestone repository
src/repositories/milestone.repository.js - Refresh-token repository
src/repositories/refreshToken.repository.js - Prisma client
src/config/prisma.js - Prisma schema · Defines users, roles, tasks, milestones, and refresh-token relations.
prisma/schema.prisma - PostgreSQL
Production Edge
- Cloudflare
- Nginx · Routes frontend traffic separately from API and Socket.IO.
- React frontend
- GitHub Actions deploy · Deploys to the VPS over SSH.
.github/workflows/deploy.yml
Connections 27
- Cloudflare → Nginx: HTTPS traffic
- Nginx → React frontend: /
- Nginx → Node backend: /api and /socket.io
- GitHub Actions deploy → Node backend: deploys
- Node backend → REST, health, and Swagger: mounts
- Node backend → Socket.IO: hosts
- REST, health, and Swagger → Swagger docs: serves docs
- REST, health, and Swagger → Auth routes: routes
- REST, health, and Swagger → Task routes: routes
- REST, health, and Swagger → Milestone routes: routes
- Auth routes → Auth service: credentials and refresh
- Task routes → Identity and authorization: protected requests
- Milestone routes → Identity and authorization: protected requests
- Identity and authorization → Task controller: authorized task actions
- Identity and authorization → Milestone controller: authorized milestone actions
- Task controller → Task repository: CRUD
- Milestone controller → Milestone repository: CRUD and progress
- Task controller → Socket.IO: task events
- Milestone controller → Socket.IO: milestone events
- Auth service → Refresh-token repository: stores rotated tokens
- Task repository → Prisma client: queries
- Milestone repository → Prisma client: queries
- Refresh-token repository → Prisma client: queries
- Prisma client → Prisma schema: uses model
- Prisma client → PostgreSQL: private connection
- React frontend → REST, health, and Swagger: REST commands
- React frontend → Socket.IO: realtime subscription