Notifications Module
The Notifications Module provides a comprehensive notification system including push notifications, reminder management, notification tracking, and multi-channel communication management within the DashClicks platform.
Brief Overview
The Notifications module serves as the central hub for all communication and notification activities in DashClicks. It manages multi-channel notifications (FCM, email, SMS), handles reminder systems, tracks notification delivery, and integrates with the Queue Manager for reliable message processing.
Directory Structure
internal/api/v1/notifications-center/
├── index.js # Module router and middleware setup
├── controllers/ # Request handlers
│ ├── index.js # Controller exports
│ ├── fcm.controller.js # Firebase Cloud Messaging
│ ├── reminder.controller.js # Reminder management
│ └── common.controller.js # Common notification operations
├── routes/ # Route definitions
│ ├── fcm.js # FCM routes
│ ├── reminder.js # Reminder routes
│ └── common.js # Common routes
├── services/ # Business logic layer
│ ├── fcm.service.js # FCM business logic
│ ├── reminder.service.js # Reminder logic
│ └── common.service.js # Common notification logic
└── validations/ # Joi validation schemas
├── fcm.js # FCM validation
├── reminder.js # Reminder validation
└── common.js # Common validation
MongoDB Collections Used
Primary Collections
notification-queue- Queued notifications awaiting deliverynotifications- Delivered notification history and trackingpush.tokens- FCM device tokens and registration datareminders- Scheduled reminders with trigger conditionsnotification.templates- Notification templates and content
Related Collections
notification.preferences- User notification preferencesnotification.subscriptions- Topic subscriptions and channelsnotification.delivery_logs- Delivery status and failure trackingnotification.analytics- Notification performance metricscrm.reminders- CRM-specific reminders integrationuser.preferences- User communication preferences
Data Flow & Workflow
Notification Processing Flow
graph TD
A[Notification Request] --> B[Validate Notification Data]
B --> C[Check User Preferences]
C --> D[Apply Templates]
D --> E[Queue for Delivery]
E --> F[Route to Channel Handler]
F --> G[FCM Push Notification]
F --> H[Email Notification]
F --> I[SMS Notification]
G --> J[Queue Manager Processing]
H --> J
I --> J
J --> K[Delivery Attempt]
K --> L[Track Delivery Status]
L --> M[Update Analytics]
M --> N[Handle Failures/Retries]
FCM Push Notification Flow
graph TD
A[Push Notification Request] --> B[Validate FCM Token]
B --> C[Prepare Message Payload]
C --> D[Send to FCM Service]
D --> E[Receive FCM Response]
E --> F[Update Token Status]
F --> G[Log Delivery Results]
G --> H[Queue Manager Processing]
H --> I[Handle Token Refresh]
H --> J[Update Analytics]
H --> K[Process Failures]
Reminder System Flow
graph TD
A[Reminder Creation] --> B[Validate Reminder Data]
B --> C[Calculate Trigger Time]
C --> D[Store Reminder Record]
D --> E[Schedule Processing]
E --> F[Queue Manager Processing]
F --> G[Monitor Due Reminders]
G --> H[Execute Reminder Delivery]
H --> I[Generate Notifications]
I --> J[Update Reminder Status]
J --> K[Handle Recurring Reminders]
Background Processing
Queue Manager Integration
The Notifications module relies heavily on Queue Manager for reliable processing:
Notification Delivery (QM_NOTIFICATIONS=true)
- Multi-channel notification processing
- Delivery retry logic and failure handling
- Template processing and personalization
- Delivery status tracking and analytics
FCM Processing (QM_FCM=true)
- Push notification batch processing
- Token validation and refresh
- Topic subscription management
- Device registration maintenance
Reminder Processing (QM_REMINDERS=true)
- Scheduled reminder execution
- Recurring reminder management
- Due date calculation and monitoring
- Reminder notification generation
Email Processing (QM_EMAIL=true)
- Email template processing
- SMTP delivery handling
- Email bounce and failure tracking
- Unsubscribe management
SMS Processing (QM_SMS=true)
- SMS message formatting
- Twilio integration processing
- Delivery confirmation tracking
- SMS opt-out management
Notifications Submodules
The Notifications module can be organized into specialized submodules for comprehensive communication management:
📧 Email Notifications
Email Communication System
- Email template management and customization
- SMTP integration and delivery management
- Email scheduling and bulk sending capabilities
- Bounce handling and delivery tracking
- Unsubscribe management and compliance
- Email analytics and performance monitoring
📱 SMS Notifications
SMS Communication Platform
- SMS template creation and management
- Twilio integration for SMS delivery
- SMS scheduling and batch processing
- SMS opt-out and compliance management
- International SMS support and routing
- SMS delivery tracking and analytics
🔔 Push Notifications
Mobile and Web Push Messaging
- FCM (Firebase Cloud Messaging) integration
- Push notification template management
- Device token management and registration
- Topic-based push notification campaigns
- Push notification analytics and engagement tracking
- Platform-specific push notification optimization
⏰ Reminders System
Task and Event Reminder Management
- Reminder creation and scheduling system
- Recurring reminder configuration and management
- Due date calculation and monitoring
- Reminder categorization and priority management
- Cross-platform reminder delivery
- Reminder completion tracking and analytics
🎯 Targeted Messaging
Personalized Communication Campaigns
- User segmentation for targeted messaging
- Personalized message content generation
- A/B testing for message optimization
- Campaign performance tracking and analytics
- Multi-channel campaign coordination
- Message frequency optimization and management
📊 Communication Analytics
Notification Performance Tracking
- Delivery rate monitoring and optimization
- Open rate and engagement analytics
- User preference analysis and insights
- Communication effectiveness metrics
- Cost analysis and optimization
- Compliance reporting and audit trails
API Endpoints Overview
| Method | Endpoint | Description |
|---|---|---|
GET | /v1/notifications/count | Get notification counts by module and type |
PUT | /v1/notifications/read | Mark notifications as read |
GET | /v1/notifications/reminders | Get user reminders |
POST | /v1/notifications/reminders | Create new reminder |
PUT | /v1/notifications/reminders/:id | Update reminder |
DELETE | /v1/notifications/reminders/:id | Delete reminder |
POST | /v1/notifications/fcm/send | Send FCM push notification |
POST | /v1/notifications/fcm/subscribe | Subscribe to FCM topic |
POST | /v1/notifications/fcm/unsubscribe | Unsubscribe from FCM topic |
GET | /v1/notifications/history | Get notification history |
POST | /v1/notifications/bulk | Send bulk notifications |
PUT | /v1/notifications/preferences | Update notification preferences |
GET | /v1/notifications/templates | Get notification templates |
POST | /v1/notifications/templates | Create notification template |
PUT | /v1/notifications/templates/:id | Update notification template |
DELETE | /v1/notifications/templates/:id | Delete notification template |
Core Notification Components
Notification Management
Notification Center
- Centralized notification management and tracking
- Multi-channel notification support (push, email, SMS)
- Notification categorization and priority management
- Real-time notification delivery and status tracking
- Notification history and audit trail
- User notification preferences and filtering
Notification Types
- System notifications for important updates
- Task and project-related notifications
- CRM activity and deal progression notifications
- Marketing campaign and automation notifications
- Security and account-related notifications
- Custom notification types and categories
Push Notification System
FCM Integration
- Firebase Cloud Messaging (FCM) integration
- Device token management and registration
- Topic-based subscription and broadcasting
- Targeted push notification delivery
- Push notification analytics and tracking
- Multi-platform push notification support
Device Management
- Device registration and token management
- Cross-device notification synchronization
- Device-specific notification preferences
- Push notification delivery optimization
- Device activity tracking and analytics
- Token refresh and maintenance automation
Reminder System
Reminder Management
- Personal and team reminder creation
- Recurring reminder setup and management
- Reminder priority and categorization
- Due date tracking and notification alerts
- Reminder completion and status tracking
- Integration with calendar and task systems
Automated Reminders
- System-generated reminder automation
- CRM activity and follow-up reminders
- Task deadline and milestone reminders
- Meeting and appointment reminders
- Payment and billing reminder automation
- Custom reminder rule configuration
Communication Templates
Template Management
- Notification template creation and management
- Multi-channel template support (email, SMS, push)
- Template versioning and approval workflows
- Dynamic content and personalization
- Template performance analytics and optimization
- Localization and multi-language support
Content Personalization
- Dynamic content insertion and customization
- User-specific personalization and targeting
- Contextual content based on user activity
- A/B testing for notification content
- Performance tracking and optimization
- Content compliance and approval processes
Service Methods & Functionality
Notification Services
getCount() - Notification count retrieval
- Retrieves notification counts by module and type
- Supports filtering by notification categories
- Includes unread count and priority notifications
- Provides real-time count updates and tracking
- Returns structured count data with categorization
readCommon() - Notification status management
- Marks notifications as read for specific users
- Handles bulk notification status updates
- Updates notification tracking and analytics
- Manages notification state synchronization
- Returns updated notification status information
getNotifications() - Notification retrieval
- Retrieves user notifications with filtering options
- Supports pagination and sorting by priority
- Includes notification metadata and context
- Provides notification history and tracking
- Returns notification list with status information
createNotification() - Notification creation
- Creates new notifications with validation
- Handles multi-channel notification setup
- Sets up notification delivery scheduling
- Configures notification priority and categorization
- Returns created notification with delivery details
Push Notification Services
sendFCM() - FCM push notification delivery
- Sends push notifications via Firebase Cloud Messaging
- Handles device token validation and management
- Supports targeted and broadcast notifications
- Manages notification payload and formatting
- Returns delivery status and tracking information
subscribeFCM() - FCM topic subscription
- Subscribes users to FCM notification topics
- Handles topic-based notification management
- Updates user subscription preferences
- Manages subscription synchronization across devices
- Returns subscription confirmation and status
unsubscribeFCM() - FCM topic unsubscription
- Unsubscribes users from FCM notification topics
- Handles topic preference updates and management
- Updates notification delivery preferences
- Manages unsubscription across multiple devices
- Returns unsubscription confirmation and status
Reminder Services
getReminders() - Reminder retrieval
- Retrieves user reminders with filtering options
- Supports due date and priority-based sorting
- Includes recurring reminder information
- Provides reminder status and completion tracking
- Returns reminder list with context and metadata
createReminder() - Reminder creation
- Creates new reminders with scheduling
- Handles recurring reminder setup and configuration
- Sets up reminder notifications and alerts
- Configures reminder priority and categorization
- Returns created reminder with scheduling details
updateReminder() - Reminder modification
- Updates reminder information and scheduling
- Handles recurring reminder pattern changes
- Modifies reminder notifications and alerts
- Updates reminder priority and status
- Returns updated reminder with change confirmation
deleteReminder() - Reminder removal
- Removes reminders with proper cleanup
- Handles recurring reminder series deletion
- Manages associated notification cleanup
- Updates reminder analytics and tracking
- Returns deletion confirmation and status
Template Services
getTemplates() - Template retrieval
- Retrieves notification templates with filtering
- Supports template categorization and versioning
- Includes template performance analytics
- Provides template usage and effectiveness data
- Returns template list with metadata and statistics
createTemplate() - Template creation
- Creates new notification templates with validation
- Handles multi-channel template configuration
- Sets up template personalization and dynamic content
- Configures template approval workflows
- Returns created template with configuration details
updateTemplate() - Template modification
- Updates template content and configuration
- Handles template versioning and approval processes
- Modifies template personalization settings
- Updates template performance optimization
- Returns updated template with version information
Analytics Services
getNotificationAnalytics() - Notification performance analytics
- Analyzes notification delivery and engagement metrics
- Provides channel-specific performance insights
- Tracks notification open rates and user interaction
- Returns notification analytics dashboards
- Includes comparative performance analysis
getDeliveryAnalytics() - Delivery performance analysis
- Analyzes notification delivery success rates
- Provides delivery timing and optimization insights
- Tracks delivery failures and retry mechanisms
- Returns delivery analytics and optimization recommendations
- Includes real-time delivery monitoring data
Technical Implementation Details
Notification Architecture
- Multi-channel Support: Email, SMS, push notification, and in-app notifications
- Real-time Delivery: WebSocket and FCM integration for real-time notifications
- Scalable Infrastructure: Queue-based notification processing and delivery
- Template System: Dynamic template rendering with personalization
- Analytics Integration: Comprehensive notification tracking and analytics
Push Notification Framework
- FCM Integration: Firebase Cloud Messaging for cross-platform push notifications
- Token Management: Device token registration and maintenance
- Topic Subscription: Group-based notification delivery and management
- Delivery Optimization: Intelligent notification batching and scheduling
- Cross-platform Support: iOS, Android, and web push notification support
Reminder Framework
- Scheduling Engine: Flexible reminder scheduling with recurring patterns
- Integration Points: Calendar, task, and CRM system integration
- Notification Triggers: Automated reminder notification delivery
- Priority Management: Reminder priority and urgency classification
- Completion Tracking: Reminder completion status and analytics
Business Logic Flow
Notification Delivery Flow
- Validate notification request and recipient information
- Determine appropriate delivery channels based on preferences
- Apply notification templates and personalization
- Queue notification for delivery with priority handling
- Execute delivery via appropriate channels (FCM, email, SMS)
- Track delivery status and update analytics
- Handle delivery failures with retry mechanisms and fallbacks
Reminder Management Flow
- Create or update reminder with scheduling information
- Set up recurring pattern if applicable
- Configure notification alerts and delivery preferences
- Schedule reminder notifications based on due dates
- Execute reminder notifications at appropriate times
- Track reminder completion and status updates
- Update reminder analytics and performance metrics
Template Processing Flow
- Retrieve appropriate notification template
- Apply dynamic content and personalization
- Validate template content and compliance
- Render final notification content
- Queue template-based notification for delivery
- Track template performance and effectiveness
- Update template analytics and optimization data
Key Features
Comprehensive Notification System
- Multi-channel Delivery: Support for push notifications, email, SMS, and in-app
- Real-time Processing: Instant notification delivery with status tracking
- Template System: Dynamic templates with personalization and localization
- Analytics Dashboard: Comprehensive notification performance analytics
Advanced Push Notifications
- FCM Integration: Firebase Cloud Messaging for reliable push delivery
- Topic Management: Group-based subscription and broadcast capabilities
- Device Management: Cross-device synchronization and token management
- Delivery Optimization: Intelligent batching and timing optimization
Intelligent Reminder System
- Flexible Scheduling: Support for one-time and recurring reminders
- Smart Notifications: Context-aware reminder delivery and timing
- Integration Support: Calendar, task, and CRM system integration
- Completion Tracking: Reminder effectiveness and completion analytics
Advanced Template System
- Dynamic Templates: Personalized content with variable substitution
- Multi-channel Templates: Templates for email, SMS, and push notifications
- Version Control: Template versioning with approval workflows
- Performance Analytics: Template effectiveness and optimization insights