How collatzconjecture/nestjs-clean-architecture works
This NestJS application exposes versioned HTTP authentication and profile APIs. The main workflow is request → controller → application orchestration/CQRS → domain rules and repository contracts → MongoDB-backed repositories, with response handling on the way out. Authentication also supports JWT refresh, Google OAuth, RBAC, and registration events/saga orchestration; profile management has its own commands and services. The README documents broader architecture and operational capabilities, but sampled files do not establish all runtime wiring, so uncertain links are omitted.
Main entry points: auth.service.ts Auth Orchestration · app.module.ts Root Module · create-auth-user.handler.ts Auth Commands · auth.controller.ts Auth Endpoints
Components 30
HTTP API
- Auth Endpoints
src/api/controllers/auth.controller.ts - Profile Endpoints
src/api/controllers/profile.controller.ts - API Module
src/api/api.module.ts
Application Workflows
- Response Formatting
src/application/services/response.service.ts - Auth Orchestration
src/application/services/auth.service.ts - Auth Commands
src/application/auth/command/handler/create-auth-user.handler.ts - Registration Saga
src/application/auth/sagas/registration.saga.ts - Auth Strategies & RBAC
src/application/auth - Profile Service
src/application/services/profile.service.ts - Profile Command Handler
src/application/profile/command/handler/create-profile.handler.ts - Request Middleware
src/application/middlewere - Response & Errors
src/application/interceptors/response.interceptor.ts
Domain Model
- Auth Rules
src/domain/services/auth-domain.service.ts - Profile Rules
src/domain/services/profile-domain.service.ts - Auth Entity
src/domain/entities/Auth.ts - Profile Entity
src/domain/entities/Profile.ts - Auth Repository Contract
src/domain/interfaces/repositories/auth-repository.interface.ts - Profile Repository Contract
src/domain/interfaces/repositories/profile-repository.interface.ts
Infrastructure
- Auth Repository
src/infrastructure/repository/auth.repository.ts - Profile Repository
src/infrastructure/repository/profile.repository.ts - Auth Mongo Model
src/infrastructure/models/auth.model.ts - Profile Mongo Model
src/infrastructure/models/profile.model.ts - Health Checks
src/infrastructure/health/health.controller.ts - Logging & Metrics
src/infrastructure - Root Module
src/app.module.ts - Nest Bootstrap
src/main.ts - Database Provider
src/infrastructure/database/database.providers.ts
Other components
- API Client
- MongoDB
- Google OAuth
Connections 29
- API Client → Auth Endpoints: sends requests
src/api/controllers/auth.controller.ts - API Client → Profile Endpoints: sends requests
src/api/controllers/profile.controller.ts - Auth Endpoints → Auth Orchestration: calls
src/api/controllers/auth.controller.ts - Profile Endpoints → Profile Service: calls
src/api/controllers/profile.controller.ts - Auth Endpoints → Response Formatting: formats results
src/api/controllers/auth.controller.ts - Profile Endpoints → Response Formatting: formats results
src/api/controllers/profile.controller.ts - Auth Orchestration → Auth Commands: dispatches commands
src/application/services/auth.service.ts - Auth Orchestration → Auth Repository Contract: reads and writes
src/application/services/auth.service.ts - Auth Orchestration → Auth Rules: applies rules
src/application/services/auth.service.ts - Auth Orchestration → Profile Repository Contract: accesses profiles
src/application/services/auth.service.ts - Auth Orchestration → Profile Rules: checks creation
src/application/services/auth.service.ts - Auth Orchestration → Google OAuth: requests OAuth data
src/application/services/auth.service.ts - Auth Commands → Auth Repository Contract: creates user
src/application/auth/command/handler/create-auth-user.handler.ts - Auth Commands → Auth Rules: validates creation
src/application/auth/command/handler/create-auth-user.handler.ts - Auth Commands → Registration Saga: publishes event
- Profile Service → Profile Command Handler: coordinates commands
- Profile Service → Profile Repository Contract: uses repository
- Auth Repository Contract → Auth Repository: implemented by
- Profile Repository Contract → Profile Repository: implemented by
- Auth Repository → Auth Mongo Model: queries
src/infrastructure/repository/auth.repository.ts - Auth Repository → MongoDB: persists data
- Profile Repository → Profile Mongo Model: uses model
- Profile Repository → MongoDB: persists data
- Nest Bootstrap → Root Module: bootstraps
src/main.ts - Root Module → API Module: imports
src/app.module.ts - Root Module → Response & Errors: registers globally
src/app.module.ts - Root Module → Request Middleware: applies to routes
src/app.module.ts - Root Module → Health Checks: registers controller
src/app.module.ts - Database Provider → MongoDB: connects
src/infrastructure/database/database.providers.ts