This repository demonstrates a microservices-based Notification System using Node.js with NestJS, RabbitMQ (message broker), and unit testing for building production-grade, scalable infrastructure. It is designed to process and deliver notifications (e.g., email, SMS) via queue-based architecture and strategy pattern.
✅ Ideal for developers and learners exploring real-world microservice design in Node.js.
| Layer/Component | Technology Used |
|---|---|
| Framework | NestJS |
| Language | TypeScript |
| Messaging | RabbitMQ (via amqplib) |
| Email Client | SMTP / Nodemailer |
| Design Pattern | Strategy Pattern |
| Persistence | MongoDB (via Mongoose) |
| Validation | Joi, class-validator |
| Testing | Jest + Supertest |
| Containerization | Docker + Docker Compose |
micro-notify/
├── services/
│ ├── notification-service/ # Main API service
│ │ ├── application/
│ │ ├── domain/
│ │ ├── infrastructure/
│ │ ├── presentation/
│ │ └── queue/ # Queue publishing logic
│ └── email-worker/ # Worker service that consumes queue and sends emails
│ ├── queue/
│ └── mail/
- REST API for triggering notifications
- RabbitMQ integration for decoupled message handling
- Email strategy using SMTP
- SMS strategy (stubbed for extension)
- Strategy Pattern for dynamic message handling (Email, SMS, etc.)
- Worker service that consumes queue and sends notifications
- Unit tests for controller layer (using Jest)
- Docker support for simplified local setup
- Node.js
>= 18 - MongoDB running locally (
mongodb://localhost:27017) - RabbitMQ running locally (
amqp://localhost) - Docker (optional for running RabbitMQ/MongoDB containers)
git clone https://github.com/yourusername/micro-notify.git
cd micro-notifyIf you don’t have RabbitMQ locally, you can use:
docker-compose -f docker-compose.local.yml up -dThis will start RabbitMQ at
localhost:5672and MongoDB atlocalhost:27017.
cd services/notification-service
npm install
cd ../email-worker
npm install- Run Notification API:
cd services/notification-service
npm run start:dev- Run Email Worker:
cd services/email-worker
npm run start:devSend a POST request to:
POST http://localhost:3000/notificationsWith body:
{
"recipient": "test@example.com",
"subject": "Welcome to our system",
"body": "<b>Hello!</b> You have a new message.",
"notificationType": "WELCOME",
"mediaType": "EMAIL"
}cd services/notification-service
npm run test✅ Jest-based unit tests are implemented for controller endpoints.
Each service has its own Dockerfile.
You can also run both services together using a full docker-compose.yml (optional).
This project helps you learn:
- Microservice architecture using NestJS
- Queue-based communication using RabbitMQ
- Dynamic messaging using the Strategy pattern
- Dependency injection and modular codebase
- Controller, Service, and Factory design separation
- Robust error handling and reconnection logic
- Writing unit tests for REST APIs
- Add support for AWS SNS/SQS
- Extend SMS sending via Twilio
- Add custom retry logic for failed messages
- UI dashboard for queue monitoring
- Log aggregator (e.g., ELK or Prometheus)
Author: Mostafizur Rahman LinkedIn: linkedin.com/in/mostafiz Email: mostafiz571@gmail.com
This project is open-source and available under the MIT License.
micro-notify/
├── services/ # Microservices directory
│ ├── notification-service/ # Core notification logic
│ ├── user-service/ # Authentication and user management
│ ├── email-worker/ # Email processing worker
│ ├── audit-service/ # Logging and auditing
│ └── api-gateway/ # API Gateway
├── ui/ # Next.js frontend dashboard
├── docker-compose.yml # Container orchestration
├── .env.example # Environment variables template
└── README.md # Project documentation
- notification-service: Handles core notification logic and storage
- user-service: Manages authentication and user profiles
- email-worker: Processes email notifications asynchronously
- audit-service: Handles logging and auditing of operations
- api-gateway: Central entry point for all API requests
- ui: Next.js based frontend dashboard
- Clone the repository
- Copy
.env.exampleto.envand configure environment variables - Run
docker-compose upto start all services