# aaditya514/notification-service architecture

> Architecture diagram of the GitHub repository aaditya514/notification-service, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aaditya514/notification-service
- Repository: https://github.com/aaditya514/notification-service

## Overview

This is a Node.js notification microservice: clients submit channel-specific requests, the API validates and stores them, then enqueues work for asynchronous delivery. The worker dispatches email and SMS, updates notification status, retries failures, and routes exhausted jobs to the DLQ, which the API can inspect or replay. The repository also contains a preference-based dispatcher and in-app persistence helper. The README describes in-app delivery as part of worker processing, but the sampled worker only logs in-app delivery; those implementations are shown separately.

Main entry points: [`src/workers/notificationWorker.js`](https://github.com/aaditya514/notification-service/blob/main/src/workers/notificationWorker.js) (Job Worker), [`src/queues/notificationQueue.js`](https://github.com/aaditya514/notification-service/blob/main/src/queues/notificationQueue.js) (Notification Queues), [`src/services/notificationService.js`](https://github.com/aaditya514/notification-service/blob/main/src/services/notificationService.js) (Preference Dispatcher), [`src/utils/emailClient.js`](https://github.com/aaditya514/notification-service/blob/main/src/utils/emailClient.js) (Email Client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API"]
  node_server["Express Server<br/>[app.js]"]
  node_routes["Notification Routes"]
  node_controller["Request Handlers"]
end

subgraph group_queue["Queue Processing"]
  node_queue["Notification Queues"]
  node_worker["Job Worker"]
end

subgraph group_delivery["Delivery Channels"]
  node_preference["Preference Dispatcher"]
  node_inapp["In-App Helper<br/>[inAppService.js]"]
  node_email["Email Client<br/>[emailClient.js]"]
  node_sms["SMS Client<br/>[smsService.js]"]
end

subgraph group_data["Persistence"]
  node_notification["Notification Records<br/>[Notification.js]"]
  node_user["User Preferences<br/>[User.js]"]
end

node_client(("API Client"))
node_redis[("Redis")]
node_mongodb[("MongoDB")]
node_smtp["SMTP Service"]
node_twilio["Twilio"]
node_config["Environment Config<br/>[index.js]"]
node_redisconfig["Redis Settings<br/>[redisConfig.js]"]

node_client -->|"sends requests"| node_server
node_server -->|"mounts routes"| node_routes
node_routes -->|"dispatches handlers"| node_controller
node_controller -->|"creates and queries"| node_notification
node_controller -->|"enqueues and replays"| node_queue
node_queue -->|"gets connection"| node_redisconfig
node_redisconfig -->|"reads URL"| node_config
node_queue -->|"stores jobs"| node_redis
node_worker -->|"consumes jobs"| node_queue
node_worker -->|"gets connection"| node_redisconfig
node_worker -->|"updates status"| node_notification
node_worker -->|"sends email"| node_email
node_email -->|"reads credentials"| node_config
node_email -.->|"sends mail"| node_smtp
node_worker -->|"sends SMS"| node_sms
node_sms -->|"reads credentials"| node_config
node_sms -.->|"sends messages"| node_twilio
node_worker -->|"adds exhausted jobs"| node_queue
node_notification -->|"persists history"| node_mongodb
node_server -->|"connects"| node_mongodb
node_worker -->|"connects"| node_mongodb
node_preference -->|"loads preferences"| node_user
node_preference -->|"dispatches email"| node_email
node_preference -->|"dispatches SMS"| node_sms
node_preference -->|"saves in-app"| node_inapp
node_inapp -->|"creates record"| node_notification

click node_server "https://github.com/aaditya514/notification-service/blob/main/src/app.js"
click node_routes "https://github.com/aaditya514/notification-service/blob/main/src/routes/notificationRoutes.js"
click node_controller "https://github.com/aaditya514/notification-service/blob/main/src/controllers/notificationController.js"
click node_queue "https://github.com/aaditya514/notification-service/blob/main/src/queues/notificationQueue.js"
click node_worker "https://github.com/aaditya514/notification-service/blob/main/src/workers/notificationWorker.js"
click node_notification "https://github.com/aaditya514/notification-service/blob/main/src/models/Notification.js"
click node_user "https://github.com/aaditya514/notification-service/blob/main/src/models/User.js"
click node_preference "https://github.com/aaditya514/notification-service/blob/main/src/services/notificationService.js"
click node_inapp "https://github.com/aaditya514/notification-service/blob/main/src/services/inAppService.js"
click node_email "https://github.com/aaditya514/notification-service/blob/main/src/utils/emailClient.js"
click node_sms "https://github.com/aaditya514/notification-service/blob/main/src/services/smsService.js"
click node_config "https://github.com/aaditya514/notification-service/blob/main/src/config/index.js"
click node_redisconfig "https://github.com/aaditya514/notification-service/blob/main/src/config/redisConfig.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_server,node_routes,node_controller,node_client toneBlue
class node_queue,node_worker,node_redis,node_mongodb,node_redisconfig toneAmber
class node_preference,node_inapp,node_email,node_sms toneMint
class node_notification,node_user toneRose
class node_smtp,node_twilio toneIndigo
class node_config toneTeal
```

## Components

### API

- [Express Server](https://github.com/aaditya514/notification-service/blob/main/src/app.js): `src/app.js`
- [Notification Routes](https://github.com/aaditya514/notification-service/blob/main/src/routes/notificationRoutes.js): `src/routes/notificationRoutes.js`
- [Request Handlers](https://github.com/aaditya514/notification-service/blob/main/src/controllers/notificationController.js): `src/controllers/notificationController.js`

### Queue Processing

- [Notification Queues](https://github.com/aaditya514/notification-service/blob/main/src/queues/notificationQueue.js): `src/queues/notificationQueue.js`
- [Job Worker](https://github.com/aaditya514/notification-service/blob/main/src/workers/notificationWorker.js): `src/workers/notificationWorker.js`

### Delivery Channels

- [Preference Dispatcher](https://github.com/aaditya514/notification-service/blob/main/src/services/notificationService.js): `src/services/notificationService.js`
- [In-App Helper](https://github.com/aaditya514/notification-service/blob/main/src/services/inAppService.js): `src/services/inAppService.js`
- [Email Client](https://github.com/aaditya514/notification-service/blob/main/src/utils/emailClient.js): `src/utils/emailClient.js`
- [SMS Client](https://github.com/aaditya514/notification-service/blob/main/src/services/smsService.js): `src/services/smsService.js`

### Persistence

- [Notification Records](https://github.com/aaditya514/notification-service/blob/main/src/models/Notification.js): `src/models/Notification.js`
- [User Preferences](https://github.com/aaditya514/notification-service/blob/main/src/models/User.js): `src/models/User.js`

### Other components

- **API Client**
- **Redis**
- **MongoDB**
- **SMTP Service**
- **Twilio**
- [Environment Config](https://github.com/aaditya514/notification-service/blob/main/src/config/index.js): `src/config/index.js`
- [Redis Settings](https://github.com/aaditya514/notification-service/blob/main/src/config/redisConfig.js): `src/config/redisConfig.js`

## Connections

- API Client → Express Server: sends requests (evidence: `README.md`)
- Express Server → Notification Routes: mounts routes (evidence: `src/app.js`)
- Notification Routes → Request Handlers: dispatches handlers (evidence: `src/routes/notificationRoutes.js`)
- Request Handlers → Notification Records: creates and queries (evidence: `src/controllers/notificationController.js`)
- Request Handlers → Notification Queues: enqueues and replays (evidence: `src/controllers/notificationController.js`)
- Notification Queues → Redis Settings: gets connection (evidence: `src/queues/notificationQueue.js`)
- Redis Settings → Environment Config: reads URL (evidence: `src/config/redisConfig.js`)
- Notification Queues → Redis: stores jobs (evidence: `README.md`)
- Job Worker → Notification Queues: consumes jobs (evidence: `README.md`)
- Job Worker → Redis Settings: gets connection (evidence: `src/workers/notificationWorker.js`)
- Job Worker → Notification Records: updates status (evidence: `src/workers/notificationWorker.js`)
- Job Worker → Email Client: sends email (evidence: `src/workers/notificationWorker.js`)
- Email Client → Environment Config: reads credentials (evidence: `src/utils/emailClient.js`)
- Email Client → SMTP Service: sends mail
- Job Worker → SMS Client: sends SMS (evidence: `src/workers/notificationWorker.js`)
- SMS Client → Environment Config: reads credentials (evidence: `src/services/smsService.js`)
- SMS Client → Twilio: sends messages
- Job Worker → Notification Queues: adds exhausted jobs (evidence: `src/workers/notificationWorker.js`)
- Notification Records → MongoDB: persists history (evidence: `README.md`)
- Express Server → MongoDB: connects (evidence: `src/app.js`)
- Job Worker → MongoDB: connects (evidence: `src/workers/notificationWorker.js`)
- Preference Dispatcher → User Preferences: loads preferences (evidence: `src/services/notificationService.js`)
- Preference Dispatcher → Email Client: dispatches email (evidence: `src/services/notificationService.js`)
- Preference Dispatcher → SMS Client: dispatches SMS (evidence: `src/services/notificationService.js`)
- Preference Dispatcher → In-App Helper: saves in-app (evidence: `src/services/notificationService.js`)
- In-App Helper → Notification Records: creates record (evidence: `src/services/inAppService.js`)
