# fikriandrrhm19/wad-capstone architecture

> Architecture diagram of the GitHub repository fikriandrrhm19/wad-capstone, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/fikriandrrhm19/wad-capstone
- Repository: https://github.com/fikriandrrhm19/wad-capstone

## Overview

#### 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: [`src/routes/index.js`](https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/routes/index.js) (REST, health, and Swagger), [`src/config/prisma.js`](https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/config/prisma.js) (Prisma client), [`src/index.js`](https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/index.js) (Node backend), [`src/middleware/authenticate.js`](https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/middleware/authenticate.js) (Identity and authorization)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Backend Runtime"]
  node_node["Node backend<br/>Express and Socket.IO runtime<br/>[index.js]"]
  node_api["REST, health, and Swagger<br/>public API boundary<br/>[index.js]"]
  node_swagger["Swagger docs<br/>API documentation<br/>[swagger.js]"]
  node_socket["Socket.IO<br/>realtime gateway<br/>[socket.js]"]
end

subgraph group_domain["Application Domain"]
  node_auth_routes["Auth routes<br/>route module<br/>[auth.routes.js]"]
  node_task_routes["Task routes<br/>route module<br/>[tasks.routes.js]"]
  node_milestone_routes["Milestone routes<br/>route module"]
  node_security["Identity and authorization<br/>middleware chain<br/>[authenticate.js]"]
  node_auth_service["Auth service<br/>identity service<br/>[auth.service.js]"]
  node_task_controller["Task controller"]
  node_milestone_controller["Milestone controller"]
end

subgraph group_data["Persistence"]
  node_task_repo["Task repository<br/>Prisma repository<br/>[task.repository.js]"]
  node_milestone_repo["Milestone repository<br/>Prisma repository"]
  node_refresh_repo["Refresh-token repository<br/>Prisma repository"]
  node_prisma["Prisma client<br/>data access client<br/>[prisma.js]"]
  node_schema["Prisma schema<br/>data model<br/>[schema.prisma]"]
  node_postgres[("PostgreSQL<br/>private database")]
end

subgraph group_deployment["Production Edge"]
  node_cloudflare{{"Cloudflare<br/>DNS and HTTPS edge"}}
  node_nginx{{"Nginx<br/>reverse proxy"}}
  node_frontend["React frontend<br/>external client"]
  node_deploy["GitHub Actions deploy<br/>deployment automation<br/>[deploy.yml]"]
end

node_cloudflare -->|"HTTPS traffic"| node_nginx
node_nginx -->|"/"| node_frontend
node_nginx -->|"/api and /socket.io"| node_node
node_deploy -->|"deploys"| node_node
node_node -->|"mounts"| node_api
node_node -->|"hosts"| node_socket
node_api -->|"serves docs"| node_swagger
node_api -->|"routes"| node_auth_routes
node_api -->|"routes"| node_task_routes
node_api -->|"routes"| node_milestone_routes
node_auth_routes -->|"credentials and refresh"| node_auth_service
node_task_routes -->|"protected requests"| node_security
node_milestone_routes -->|"protected requests"| node_security
node_security -->|"authorized task actions"| node_task_controller
node_security -->|"authorized milestone actions"| node_milestone_controller
node_task_controller -->|"CRUD"| node_task_repo
node_milestone_controller -->|"CRUD and progress"| node_milestone_repo
node_task_controller -->|"task events"| node_socket
node_milestone_controller -->|"milestone events"| node_socket
node_auth_service -->|"stores rotated tokens"| node_refresh_repo
node_task_repo -->|"queries"| node_prisma
node_milestone_repo -->|"queries"| node_prisma
node_refresh_repo -->|"queries"| node_prisma
node_prisma -.->|"uses model"| node_schema
node_prisma -->|"private connection"| node_postgres
node_frontend -->|"REST commands"| node_api
node_frontend -->|"realtime subscription"| node_socket

click node_node "https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/index.js"
click node_api "https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/routes/index.js"
click node_swagger "https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/docs/swagger.js"
click node_socket "https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/socket.js"
click node_auth_routes "https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/routes/auth.routes.js"
click node_task_routes "https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/routes/tasks.routes.js"
click node_milestone_routes "https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/routes/milestones.routes.js"
click node_security "https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/middleware/authenticate.js"
click node_auth_service "https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/services/auth.service.js"
click node_task_controller "https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/controllers/tasks.controller.js"
click node_milestone_controller "https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/controllers/milestone.controller.js"
click node_task_repo "https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/repositories/task.repository.js"
click node_milestone_repo "https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/repositories/milestone.repository.js"
click node_refresh_repo "https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/repositories/refreshToken.repository.js"
click node_prisma "https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/config/prisma.js"
click node_schema "https://github.com/fikriandrrhm19/wad-capstone/blob/main/prisma/schema.prisma"
click node_deploy "https://github.com/fikriandrrhm19/wad-capstone/blob/main/.github/workflows/deploy.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_node,node_api,node_swagger,node_socket toneBlue
class node_auth_routes,node_task_routes,node_milestone_routes,node_security,node_auth_service,node_task_controller,node_milestone_controller toneAmber
class node_task_repo,node_milestone_repo,node_refresh_repo,node_prisma,node_schema,node_postgres toneMint
class node_cloudflare,node_nginx,node_frontend,node_deploy toneRose
```

## Components

### Backend Runtime

- [Node backend](https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/index.js): Express and Socket.IO runtime · PM2-managed Node.js application. · `src/index.js`
- [REST, health, and Swagger](https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/routes/index.js): public API boundary · `src/routes/index.js`
- [Swagger docs](https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/docs/swagger.js): API documentation · `src/docs/swagger.js`
- [Socket.IO](https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/socket.js): realtime gateway · Broadcasts lifecycle events and presence updates. · `src/socket.js`

### Application Domain

- [Auth routes](https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/routes/auth.routes.js): route module · `src/routes/auth.routes.js`
- [Task routes](https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/routes/tasks.routes.js): route module · `src/routes/tasks.routes.js`
- [Milestone routes](https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/routes/milestones.routes.js): route module · `src/routes/milestones.routes.js`
- [Identity and authorization](https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/middleware/authenticate.js): middleware chain · Authenticates JWTs and enforces roles and ownership. · `src/middleware/authenticate.js`
- [Auth service](https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/services/auth.service.js): identity service · Issues access tokens and rotates persisted refresh tokens. · `src/services/auth.service.js`
- [Task controller](https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/controllers/tasks.controller.js): controller · Applies task commands and emits realtime updates after persistence. · `src/controllers/tasks.controller.js`
- [Milestone controller](https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/controllers/milestone.controller.js): controller · Maintains milestones and derived progress from task state. · `src/controllers/milestone.controller.js`

### Persistence

- [Task repository](https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/repositories/task.repository.js): Prisma repository · `src/repositories/task.repository.js`
- [Milestone repository](https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/repositories/milestone.repository.js): Prisma repository · `src/repositories/milestone.repository.js`
- [Refresh-token repository](https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/repositories/refreshToken.repository.js): Prisma repository · `src/repositories/refreshToken.repository.js`
- [Prisma client](https://github.com/fikriandrrhm19/wad-capstone/blob/main/src/config/prisma.js): data access client · `src/config/prisma.js`
- [Prisma schema](https://github.com/fikriandrrhm19/wad-capstone/blob/main/prisma/schema.prisma): data model · Defines users, roles, tasks, milestones, and refresh-token relations. · `prisma/schema.prisma`
- **PostgreSQL**: private database

### Production Edge

- **Cloudflare**: DNS and HTTPS edge
- **Nginx**: reverse proxy · Routes frontend traffic separately from API and Socket.IO.
- **React frontend**: external client
- [GitHub Actions deploy](https://github.com/fikriandrrhm19/wad-capstone/blob/main/.github/workflows/deploy.yml): deployment automation · Deploys to the VPS over SSH. · `.github/workflows/deploy.yml`

## Connections

- 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
