How chatok-jnr/sammtech-backend-assignment works
1. Overall shape
This is a NestJS monolith organized by domain modules. The main runtime path is HTTP request → controller → service → Prisma ORM → PostgreSQL. The codebase is split into feature boundaries for auth, users, boards, columns, and tasks, with a shared common layer and a dedicated Prisma integration.
2. Core domain model
The persistence layer is centered on a Kanban hierarchy: users own boards, boards contain columns, and columns contain tasks. The schema also includes refresh_tokens, task_labels, and task_activities, so the system is not just CRUD—it tracks authentication state and task history as separate concerns.
3. Authentication subsystem
src/auth handles register, login, and refresh-token flows. JWT access tokens are used for request authorization, while refresh tokens are stored server-side and rotated on use. The auth module includes a JWT strategy and guard, so protected routes are enforced at the Nest middleware/guard layer rather than inside each controller.
4. Identity and request context
A custom CurrentUser decorator exposes the authenticated user payload to handlers. That means controllers can receive the current principal directly without manually parsing the JWT in each endpoint. The users module appears to provide a protected profile endpoint, likely used to return the current user’s identity and/or account state.
5. Board ownership boundary
Boards are the top-level authorization boundary. The README indicates ownership is enforced by traversing relationships rather than duplicating ownerId across child tables. In practice, board access determines whether a user can touch related columns and tasks, so board ownership is the key access-control pivot in the system.
6. Columns and tasks as nested resources
columns and tasks are separate modules/controllers/services, but they are not independent from the access model. Column ownership is derived from the parent board, and task ownership is derived from task.column.board.ownerId. This keeps authorization logic centralized around the board tree and avoids inconsistent owner fields.
7. Task movement and ordering
Task ordering is an explicit architectural concern. Tasks have an integer position, and reorder/move operations shift neighboring rows inside a Prisma transaction. That suggests the task service is responsible for both CRUD and stateful board-layout operations, including same-column reordering and cross-column moves.
8. Soft deletion and lifecycle data
Boards and tasks use soft delete via deletedAt instead of hard deletion. The README notes that board deletion does not automatically cascade tombstones to all descendants; instead, downstream queries filter deleted items out of normal views. Task activity logging is also present, which implies the task domain captures audit/history events separate from the live task row.
9. Shared infrastructure layer
src/prisma encapsulates the database client and module wiring, making PostgreSQL access a shared infrastructure service rather than something embedded in each feature. src/common holds cross-cutting concerns: a global HTTP exception filter, domain-specific exceptions, and request decorators. This is the main boundary for consistent API behavior across modules.
10. Error handling and API behavior
The app uses a global exception filter to normalize HTTP errors and sanitize unexpected failures. Domain errors like not-found and ownership violations are surfaced as structured HTTP responses, while internal failures are logged server-side and returned as generic 500s. That means controllers stay thin and the error policy is centralized.
11. API surface and tooling
The project exposes a REST API documented with Swagger at /api/docs. It runs on Node.js with TypeScript, uses Prisma migrations for schema evolution, and depends on PostgreSQL as the only external data store. The deployment target mentioned in the README is Render, but the architecture itself is a straightforward single-service backend.
12. Architectural diagram takeaway
For a diagram, draw one NestJS application boundary containing five domain slices: auth, users, boards, columns, tasks. Put Prisma/PostgreSQL as the shared persistence layer underneath, with auth guards and the common exception/decorator layer spanning all feature modules. Show the board as the authorization root, with columns and tasks as nested resources whose access and ordering logic flow through their parent relationships.
Main entry points: app.module.ts App module · prisma.service.ts Prisma client · auth.module.ts Auth · common Common
Components 27
Nest app
Application bootstrap and composition root
- main.ts · Starts the Nest application and installs global behavior
src/main.ts - App module · Wires feature modules together
src/app.module.ts
Domain modules
Feature modules around auth and the Kanban hierarchy
- Auth · Register, login, refresh, and JWT protection
src/auth/auth.module.ts - Auth API · Authentication endpoints
src/auth/auth.controller.ts - Auth service · Token issuance, refresh rotation, and auth flows
src/auth/auth.service.ts - JWT strategy · Validates access tokens for protected routes
src/auth/strategies/jwt.strategy.ts - JWT guard · Enforces authentication at the Nest guard layer
src/auth/guards/jwt-auth.guard.ts - Users · User identity and profile access
src/users/user.module.ts - User API · Protected user/profile endpoint
src/users/user.controller.ts - User service · User lookup and profile handling
src/users/user.service.ts - Boards · Top-level ownership and board lifecycle
src/boards/board.module.ts - Board API · Board endpoints and ownership boundary
src/boards/board.controller.ts - Board service · Board CRUD and access checks
src/boards/board.service.ts - Columns · Board-scoped column management
src/columns/column.module.ts - Column API · Column endpoints nested under boards
src/columns/columns.controller.ts - Column service · Column CRUD and parent-board authorization
src/columns/columns.service.ts - Tasks · Task lifecycle, ordering, and activity tracking
src/tasks/tasks.module.ts - Task API · Task endpoints for nested resources and moves
src/tasks/tasks.controller.ts - Task service · Task CRUD, reordering, and move transactions
src/tasks/tasks.service.ts
Shared layer
Cross-cutting decorators, exceptions, and filters
- Common · Cross-cutting decorators, exceptions, and filters
src/common - Current user · Injects the authenticated principal into handlers
src/common/decorators/current-user.decorator.ts - HTTP filter · Normalizes API errors and logs unexpected failures
src/common/filters/http-exception.filter.ts - Ownership error · Raised when a user touches resources they do not own
src/common/exceptions/ownership.exception.ts - Not found · Raised when a requested resource is missing
src/common/exceptions/resource-not-found.exception.ts
Data layer
Prisma integration and PostgreSQL persistence
- Prisma · Shared database client wiring
src/prisma/prisma.module.ts - Prisma client · Application-wide access to the ORM
src/prisma/prisma.service.ts - PostgreSQL · Primary persistence store for users, boards, columns, tasks, tokens, and activity
prisma/schema.prisma
Connections 48
- main.ts → App module: boots · Bootstrap starts the Nest application and loads the root module
- App module → Auth: imports · Composition root includes authentication features
- App module → Users: imports · Composition root includes user features
- App module → Boards: imports · Composition root includes board features
- App module → Columns: imports · Composition root includes column features
- App module → Tasks: imports · Composition root includes task features
- App module → Common: shares · Global filters and decorators support all modules
- App module → Prisma: imports · Root module wires in shared database access
- Auth → Auth API: contains · Authentication HTTP surface
- Auth → Auth service: contains · Authentication business logic
- Auth → JWT strategy: contains · JWT validation strategy
- Auth → JWT guard: contains · Guard enforcing protected routes
- Auth API → Auth service: uses · Endpoints delegate token and login work to the service
- Auth service → Prisma client: persists via · Auth flow reads and updates token and user state through Prisma
- Users → User API: contains · User HTTP surface
- Users → User service: contains · User domain logic
- User API → Current user: injects · Controller methods receive the authenticated principal directly
- User API → JWT guard: protected by · Profile route is guarded at the Nest layer
- User API → User service: uses · Endpoints delegate identity queries to the service
- User service → Prisma client: reads from · User data is loaded through the shared Prisma client
- Boards → Board API: contains · Board HTTP surface
- Boards → Board service: contains · Board domain logic
- Board API → JWT guard: protected by · Board routes require authenticated access
- Board API → Board service: uses · Endpoints delegate to the board service
- Board service → Prisma client: persists via · Boards are stored and queried through Prisma
- Board service → Ownership error: throws · Ownership checks fail with a domain error
- Columns → Column API: contains · Column HTTP surface
- Columns → Column service: contains · Column domain logic
- Column API → JWT guard: protected by · Column routes require authenticated access
- Column API → Column service: uses · Endpoints delegate to column operations
- Column service → Prisma client: persists via · Columns are stored and queried through Prisma
- Column service → Ownership error: throws · Board-scoped authorization failures surface as ownership errors
- Tasks → Task API: contains · Task HTTP surface
- Tasks → Task service: contains · Task domain logic
- Task API → JWT guard: protected by · Task routes require authenticated access
- Task API → Task service: uses · Endpoints delegate create/update/move flows to the service
- Task service → Prisma client: persists via · Tasks, ordering, and activity data are managed through Prisma
- Task service → Ownership error: throws · Board-tree authorization failures surface as ownership errors
- Task service → Not found: throws · Missing tasks or parents surface as not-found errors
- Common → HTTP filter: contains · Shared HTTP error normalization
- Common → Current user: contains · Shared request-context decorator
- Common → Ownership error: contains · Ownership-specific domain error
- Common → Not found: contains · Missing-resource domain error
- HTTP filter → Board API: applies to · Global error policy affects all controllers
- HTTP filter → Column API: applies to · Global error policy affects all controllers
- HTTP filter → Task API: applies to · Global error policy affects all controllers
- Prisma → Prisma client: provides · Module exports the shared Prisma client service
- Prisma client → PostgreSQL: connects to · ORM client talks to PostgreSQL