A modular, scalable, and extensible notification system built with NestJS, BullMQ, and TypeORM, designed to handle queued and immediate notification delivery through various strategies (email, SMS, etc.).
- Each notification type has its own strategy implementing a common
NotificationStrategyinterface. - Currently only email is implemented; others can be easily extended.
- Redis is used for BullMQ queue handling.
- Notifications and delivery attempts are saved in a PostgreSQL database.
- Clean Architecture principles are used for separation of concerns.
git clone https://github.com/amir-mirjalili/notification-system.git
cd notification-system npm installCreate a .env file:
DB_HOST=localhost
DB_PORT=5432
DB_USER=USER
DB_PASS=PASSWORD
DB_NAME=DBNAME npm run migration:create npm run start:dev npm run testsrc/
:moduleName
├── entities/ # TypeORM Entities (Notification, Attempt)
├── strategies/ # Notification strategies (EmailStrategy)
├── queue/ # Queue processor logic (BullMQ)
├── notification/ # Core module and service
├── exceptions/ # Custom exceptions like RetryableException
└── main.ts # App bootstrap
- BullMQ Queue: Background job processing.
- Persistence: All attempts tracked with success/failure.
- Pluggable Strategies: Easy to add new channels (SMS, Push).
await notificationService.send('EMAIL', {
recipient: 'user@example.com',
subject: 'Welcome!',
data: {
template: 'welcome',
templateData: { name: 'Amir' },
},
});await notificationService.sendImmediate('EMAIL', {
recipient: 'user@example.com',
subject: 'Your OTP',
data: {
template: 'otp',
templateData: { code: '123456' },
},
});- Add SMS/Push strategies
- Notification templates (Handlebars or EJS)
- Multi-tenant support
- Dashboard for retry/resend & analytics
Amir Mirjalili
GitHub: amir-mirjalili
MIT License