How tanvir1017/task-management works
1. Overall shape
- This is a NestJS backend API for task management.
- The application is organized by domain modules: auth, users, task, and audit, with shared infrastructure under src/common.
- The core request path is: HTTP controller → service layer → Prisma persistence → response/filter/interceptor pipeline.
2. Runtime and deployment boundary
- The repo is designed to run either locally or via Docker Compose.
- The documented stack includes the API, PostgreSQL, Redis, and PgAdmin.
- The API is exposed under /api/v1, and Swagger docs under /api/docs.
3. Composition root
- src/main.ts bootstraps the Nest application.
- src/main/app.module.ts is the main wiring point that imports feature modules.
- app.controller.ts and app.service.ts appear to be the minimal root endpoint layer, while most business logic lives in feature modules.
4. Shared platform layer
- src/common/providers/prisma.module.ts and prisma.service.ts provide the database client as a shared infrastructure dependency.
- src/common/filters/http-exception.filter.ts standardizes API error handling.
- src/common/interceptors/response.interceptor.ts suggests a consistent response envelope or output shaping across endpoints.
- src/common/interfaces/api-response.interface.ts defines that shared API response contract.
5. Security and authorization
- Authentication is JWT-based, with jwt.strategy.ts and jwt-auth.guard.ts enforcing identity checks.
- Authorization is role-driven through roles.decorator.ts and roles.guard.ts.
- public.decorator.ts marks endpoints that bypass auth, so the access control boundary is explicit at the controller level.
6. Auth module
- auth.controller.ts and auth.service.ts handle login, registration, profile update, and user lookup flows.
- DTOs such as login.dto.ts, register.dto.ts, and update-profile.dto.ts show that input validation is part of the API boundary.
- The module also owns the JWT payload contract and strategy integration, making it the identity source for the rest of the system.
7. Users module
- users looks like the administrative/user-management boundary separate from authentication.
- It likely supports user listing and user updates, with DTOs for query filtering and edits.
- This separation keeps identity concerns in auth and CRUD/admin concerns in users.
8. Task module
- task is the primary business module.
- The DTO set indicates task creation, full updates, status changes, and two list modes: “all tasks” and “my tasks”.
- That implies both admin-wide task views and user-scoped task views, with authorization determining which controller paths are allowed.
9. Audit module
- audit is a dedicated subsystem for tracking system activity.
- The presence of audit.controller.ts, audit.service.ts, and audit.processor.ts suggests audit events are collected centrally and may be processed separately from the main request path.
- get-audit-logs-query.dto.ts indicates filtered audit-log retrieval for administrative inspection.
10. Persistence and data lifecycle
- Prisma is the single persistence layer, with schema in prisma/schema.prisma and migrations in prisma/migrations.
- prisma/seed.ts loads demo data, including seeded admin and regular users described in the README.
- The database is therefore a first-class architectural boundary: modules talk to Prisma, not directly to SQL.
11. Configuration and environment
- Environment-driven setup is present via .env / .env.example.
- src/configs/request.config.ts likely centralizes runtime request or connection configuration, tying the app to environment-specific settings.
- Docker files plus compose define the production-like local topology, while local development relies on Node.js, PostgreSQL, and Redis.
12. How to draw the architecture
- Put NestJS at the center with four domain boxes: Auth, Users, Tasks, Audit.
- Draw shared cross-cutting boxes around them for Prisma, JWT/roles security, response/error handling, and Swagger/API docs.
- Show PostgreSQL as the primary data store, Redis as supporting infrastructure in the dockerized stack, and seed/migration scripts as the database initialization path.
Main entry points: app.module.ts App module · prisma.service.ts Prisma service · auth.module.ts Auth module · users.controller.ts Users controller
Components 34
Runtime
NestJS bootstrapping and root API layer
- Main · Starts the Nest application
src/main.ts - App module · Wires application modules together
src/main/app.module.ts - Root controller · Minimal top-level endpoint layer
src/main/app.controller.ts - Root service · Minimal root application service
src/main/app.service.ts
Platform
Shared infrastructure and API pipeline
- Prisma module · Registers the shared Prisma provider
src/common/providers/prisma.module.ts - Prisma service · Database client wrapper used by modules
src/common/providers/prisma.service.ts - Response interceptor · Shapes outgoing responses consistently
src/common/interceptors/response.interceptor.ts - HTTP filter · Standardizes API exception responses
src/common/filters/http-exception.filter.ts - API contract · Shared response envelope interface
src/common/interfaces/api-response.interface.ts
Security
Identity and authorization boundary
- Public · Marks endpoints that bypass auth
src/common/decorators/public.decorator.ts - Roles · Declares role requirements on handlers
src/common/decorators/roles.decorator.ts - JWT guard · Enforces authenticated access
src/common/guards/jwt-auth.guard.ts - Roles guard · Enforces role-based authorization
src/common/guards/roles.guard.ts - JWT strategy · Validates JWT payloads and identity
src/modules/auth/jwt.strategy.ts
Domains
Feature modules for business workflows
- Auth module · Authentication and identity workflows
src/modules/auth/auth.module.ts - Auth controller · Login, register, profile, and user lookup endpoints
src/modules/auth/auth.controller.ts - Auth service · Implements authentication and profile flows
src/modules/auth/auth.service.ts - Users module · Administrative user management
src/modules/users/users.module.ts - Users controller · User management endpoints
src/modules/users/users.controller.ts - Users service · Implements user administration logic
src/modules/users/users.service.ts - Task module · Primary task management domain
src/modules/task/task.module.ts - Task controller · Task list and mutation endpoints
src/modules/task/task.controller.ts - Task service · Implements task workflows and queries
src/modules/task/task.service.ts - Audit module · Audit logging and retrieval subsystem
src/modules/audit/audit.module.ts - Audit controller · Audit log query endpoints
src/modules/audit/audit.controller.ts - Audit service · Coordinates audit log operations
src/modules/audit/audit.service.ts - Audit processor · Processes audit events separately from requests
src/modules/audit/audit.processor.ts
Data
Persistence and local deployment
- Schema · Database schema definition
prisma/schema.prisma - Seed data · Loads initial demo users and sample data
prisma/seed.ts - Migrations · Database evolution scripts
prisma/migrations - PostgreSQL · Primary persistent data store
- Redis · Supporting runtime infrastructure in compose
- Compose · Local multi-service runtime definition
docker-compose.yml - Dockerfile · Container build for the API service
dockerfile
Connections 45
- Main → App module: boots · Entry point creates the Nest application
- App module → Root controller: hosts · Wires the root controller into the app
- App module → Root service: provides · Registers the root application service
- App module → Prisma module: imports · Shares the database provider across modules
- App module → Auth module: imports · Composes authentication features
- App module → Users module: imports · Composes user-management features
- App module → Task module: imports · Composes task-management features
- App module → Audit module: imports · Composes audit features
- Auth module → Auth controller: exposes · Serves authentication endpoints
- Auth module → Auth service: provides · Contains auth business logic
- Auth module → JWT strategy: uses · Adds JWT validation to the auth boundary
- Auth controller → Public: marks · Some routes bypass authentication
- Auth controller → JWT guard: protected by · Authenticated routes use the JWT guard
- Auth service → Prisma service: queries · Auth flows read and update users through Prisma
- Users module → Users controller: exposes · Serves user-management endpoints
- Users module → Users service: provides · Contains user administration logic
- Users controller → JWT guard: protected by · User admin endpoints require authentication
- Users controller → Roles guard: protected by · Sensitive routes require role checks
- Users controller → Roles: declares · Routes declare required roles
- Users service → Prisma service: queries · Reads and updates users in the database
- Task module → Task controller: exposes · Serves task endpoints
- Task module → Task service: provides · Contains task business logic
- Task controller → JWT guard: protected by · Task routes require authenticated access
- Task controller → Roles guard: protected by · Task routes are role-scoped where needed
- Task controller → Roles: declares · Task handlers declare access roles
- Task service → Prisma service: queries · Task workflows persist via Prisma
- Audit module → Audit controller: exposes · Serves audit-log query endpoints
- Audit module → Audit service: provides · Contains audit coordination logic
- Audit module → Audit processor: runs · Processes audit events asynchronously
- Audit controller → JWT guard: protected by · Audit visibility is authenticated
- Audit controller → Roles guard: protected by · Audit access is role restricted
- Audit service → Prisma service: stores · Writes and retrieves audit records
- Audit processor → Prisma service: persists · Worker writes audit data through Prisma
- Prisma module → Prisma service: provides · Registers the shared Prisma client
- Prisma service → Schema: maps to · Client is generated from the schema
- Prisma service → PostgreSQL: connects to · Primary persistence target
- Seed data → PostgreSQL: initializes · Loads demo data into the database
- Migrations → PostgreSQL: evolves · Applies schema changes to the database
- Response interceptor → API contract: enforces · Shapes responses to the shared contract
- HTTP filter → API contract: standardizes · Error responses align with API conventions
- Compose → PostgreSQL: runs · Local stack includes PostgreSQL
- Compose → Redis: runs · Local stack includes Redis
- Compose → Dockerfile: builds · Compose uses the API container build
- Main → Response interceptor: registers · Global response shaping is applied at bootstrap
- Main → HTTP filter: registers · Global error handling is applied at bootstrap