Notification Dispatch Services
Relevant source files
The following files were used as context for generating this wiki page:
Notification Dispatch Services manage the delivery of automated messages to customers and cleaners through multiple channels, including Email, SMS, and Push Notifications. These services integrate with external providers like Firebase and SMTP servers to ensure timely updates regarding account status, booking confirmations, and system alerts.
The system centralizes dispatch logic into dedicated infrastructure services, which are consumed by application use cases and exposed via internal API routes for administrative previews.
Sources: backend/src/app.ts:162-165, backend/src/interfaces/http/routes/notification.routes.ts:10-14
Service Architecture
The architecture follows a provider-based pattern where specific infrastructure services handle the technical implementation of different communication protocols. These services are injected into the application as dependencies.
The diagram shows the flow from the API routing layer to the concrete infrastructure services that interact with external delivery gateways.
Sources: backend/src/app.ts:114-116, backend/src/interfaces/http/routes/notification.routes.ts:17-36
Core Dispatch Components
EmailService
The EmailService uses nodemailer to send HTML-formatted emails. It supports both standard SMTP configurations and a fallback JSON transport for local development environments.
- Key Functions:
sendWelcomeEmail(email, name): Dispatches a welcome message when a new user registers.sendBookingConfirmation(email, bookingId): Notifies a user of a successful service booking.sendMail(message): Generic internal method that handles the actual transmission and logs themessageId.
Sources: backend/src/infrastructure/services/EmailService.ts:7-38
FirebaseService
The FirebaseService handles push notifications using the firebase-admin SDK. It initializes a connection to Firebase Cloud Messaging (FCM) using project credentials.
- Key Functions:
sendPushNotification(token, title, body): Sends a notification to a specific device identified by adeviceToken. If Firebase is not configured in the environment variables, the service logs the attempt and skips delivery.
Sources: backend/src/infrastructure/services/FirebaseService.ts:11-38
SmsService
The SmsService provides the interface for sending text messages to user phone numbers. It is primarily utilized for notification previews and urgent alerts.
Sources: backend/src/infrastructure/services/SmsService.ts, backend/src/interfaces/http/routes/notification.routes.ts:31
Notification Data Model
User notification preferences are stored in the database as part of the User model. These preferences determine which channels are active for a specific account.
| Field | Type | Description |
|---|---|---|
email | String | Primary destination for email notifications. |
phone | String (Optional) | Destination for SMS alerts. |
preferences | Json | Stores smsNotifications (Boolean) and emailNotifications (Boolean) flags. |
Sources: backend/src/infrastructure/database/prisma/schema.prisma:48-61
API Implementation
The system exposes a preview endpoint allowing authenticated users to test notification delivery across all three channels simultaneously.
POST /api/v1/notifications/preview
This endpoint requires authentication and accepts a payload containing identifiers for different channels.
The sequence diagram illustrates the multi-channel dispatch triggered by a single preview request.
Sources: backend/src/interfaces/http/routes/notification.routes.ts:15-38
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
email | String | No | Recipient email address. |
phone | String | No | Recipient phone number. |
deviceToken | String | No | Firebase FCM device token. |
Sources: backend/src/interfaces/http/routes/notification.routes.ts:19
Configuration and Setup
Services rely on environment variables for provider credentials. If credentials are missing, services are either not initialized or perform no-op actions with logging.
| Service | Required Config Keys |
|---|---|
smtp.host, smtp.port, smtp.user, smtp.pass, smtp.from | |
| Firebase | firebase.projectId, firebase.clientEmail, firebase.privateKey |
Sources: backend/src/infrastructure/services/EmailService.ts:8-14, backend/src/infrastructure/services/FirebaseService.ts:14-25
Conclusion
Notification Dispatch Services provide a scalable and modular way to communicate with users. By abstracting SMTP, SMS, and FCM logic into separate infrastructure classes, the AtlasCleanAI platform maintains a clean separation between business logic and delivery mechanics. This structure allows the system to easily toggle notification channels based on user preferences and environment configuration.