A microservices-based application using NestJS that demonstrates user management with event-driven notifications. The application consists of two services: a User Service for managing user data and a Notification Service for handling user-related notifications.
- User Service: RESTful API handling CRUD operations for users
- Notification Service: Event-driven service for sending notifications
- Message Broker: Redis for inter-service communication
- Error Handling: Comprehensive error handling with custom exceptions
- Testing: Unit tests for critical components
- Node.js (v16 or later)
- npm (v8 or later)
- Docker and Docker Compose (for Redis)
- Install dependencies for both services:
# Install User Service dependencies
cd user-service
npm install
# Install Notification Service dependencies
cd ../notification-service
npm install
- Install global dependencies:
npm install -g @nestjs/cli
The application uses Redis as a message broker. The default configuration assumes Redis is running on localhost:6379. You can modify the connection settings in:
user-service/src/users/users.module.ts
notification-service/src/main.ts
- Start Redis using Docker:
docker-compose up -d
- Start the User Service (in a new terminal):
cd user-service
npm run start:dev
- Start the Notification Service (in a new terminal):
cd notification-service
npm run start:dev
The services will be available at:
- User Service: http://localhost:3000
- Notification Service: Running as a microservice (no HTTP endpoint)
-
POST /users
- Create a new usercurl -X POST http://localhost:3000/users \ -H "Content-Type: application/json" \ -d '{"email": "test@example.com", "name": "Test User"}'
-
GET /users
- Get all userscurl http://localhost:3000/users
-
GET /users/:id
- Get a specific usercurl http://localhost:3000/users/:id
-
PUT /users/:id
- Update a usercurl -X PUT http://localhost:3000/users/:id \ -H "Content-Type: application/json" \ -d '{"name": "Updated Name"}'
-
DELETE /users/:id
- Delete a usercurl -X DELETE http://localhost:3000/users/:id
Both services include unit tests for critical components.
# Run User Service tests
cd user-service
npm run test
# Run Notification Service tests
cd notification-service
npm run test