Notifications Module Specification
1. Purpose & Overview
The module provides in-app operator notifications, unread count tracking, and system alert dispatches.
notifications2. Responsibilities
- Maintain domain model.
Notification - Provide unread counter APIs ().
GET /api/notifications/unread-count/ - Broadcast realtime alert updates via WebSockets.
3. Directory Structure
text
services/api/notifications/
├── admin.py
├── apps.py
├── migrations/
├── models.py
├── serializers.py
└── views.py
4. Models & Database Schemas
python
class Notification(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4)
tenant = models.ForeignKey('tenants.Tenant', on_delete=models.CASCADE)
user = models.ForeignKey('users.User', on_delete=models.CASCADE, null=True, blank=True)
title = models.CharField(max_length=255)
message = models.TextField()
is_read = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
5. Services & Business Logic
- : Creates record and updates unread badge counter.
NotificationService.create_notification(...)
6. Serializers & Data Transfer Objects
- : Serializes notification items and read flags.
NotificationSerializer
7. Views & API Endpoints
- : List user notifications.
GET /api/notifications/ - : Returns
GET /api/notifications/unread-count/.{ "unread_count": 11 } - : Marks notification as read.
POST /api/notifications/{id}/mark-read/
8. Permissions & Role Rules
- : Scoped to active tenant and current user.
IsAuthenticated
9. Signals & Event Listeners
- Triggered when campaigns complete, fail, or new system alerts occur.
10. Background Tasks & Celery Jobs
- Bulk notification cleanup executed periodically.
11. Data Flow & External Dependencies
- Integrates with module to publish realtime unread badge frames to agent WebSockets.
inbox
12. Business Rules & Validations
- Notifications belong to either a specific user or all operators within a tenant.
13. Sequence Diagram (Mermaid)
Rendering diagram...
14. Known Limitations & Technical Debt
- Local memory cache for unread counters in dev mode.
15. Future Improvements
- Add Push Notification support (Web Push / FCM) for mobile browser support.