A NestJS CRUD API for customer management with CQRS and Clean Architecture. Features PostgreSQL, Prisma ORM, input validation (phone/email/IBAN), Docker support, Swagger docs, and Jest tests. Follows DDD principles for scalable backend development.
- CQRS Architecture: Clear separation of commands and queries
- Domain-Driven Design: Focused business logic implementation
- Comprehensive Validation:
- Phone number validation using
Google LibPhoneNumber - Email and IBAN validation
- Unique customer constraints
- Phone number validation using
- Production-ready Infrastructure:
- Health checks via Terminus (
/healthendpoint) - API documentation with Swagger
- Consistent response formatting via
ResponseInterceptor - Global exception handling with
HttpExceptionFilter
- Health checks via Terminus (
- Docker
- Docker Compose
-
Setup .env
cp .env.example .env
-
Run the application
docker-compose up --build
-
Run tests
docker-compose -f docker-compose.test.yml up --build
-
Access Swagger UI
http://localhost:3000/api
.
├── customer-service
│ ├── dist
│ ├── package.json
│ ├── prisma
│ │ ├── migrations
│ │ └── schema.prisma
│ ├── test
│ │ ├── mocks
│ │ └── setup
│ └── src
│ ├── main.ts
│ ├── app.module.ts
│ ├── common
│ │ ├── exceptions
│ │ ├── filters
│ │ ├── interceptors
│ │ ├── logger
│ │ ├── utils
│ │ └── validations
│ ├── domain
│ │ └── customer
│ │ └── events
│ ├── application
│ │ ├── command
│ │ ├── handlers
│ │ ├── queries
│ │ └── services
│ ├── interface
│ │ ├── controllers
│ │ ├── docs
│ │ ├── dtos
│ │ └── pipes
│ └── infrastructure
│ ├── health
│ ├── prisma
│ └── repositories
├── docker-compose.yml
├── Dockerfile
└── README.md- Phone number validation for mobile numbers only
- IBAN validation for bank accounts
- Email format validation
- Unique constraints enforcement
- Partial update validation (ensures at least one field is present via
PipeTransform)
- Global
ResponseInterceptorfor consistent API responses - Custom exception formatting via
HttpExceptionFilter - Paginated response
DTOwith metadata - Sensitive customer data masking in logs
- Prisma ORM with PostgreSQL
- Schema location:
customer-service/prisma/schema.prisma - Automatic migrations on startup
- Isolated test database (created/destroyed during test runs)
Jesttest configuration- Database setup/teardown hooks
- Terminus healthcheck available at
/healthendpoint - Includes database connectivity check
- Custom health indicators can be added
IAppLogger: Custom logger interface injected via NestJS DI- Domain-specific events for customer operations