Overview
The MLM CMMS notification system provides real-time delivery through two channels:- In-App Notifications: Always-on notification center accessible from any page
- Push Notifications: Web Push API integration for native browser/OS notifications
Architecture
Event Generation
Ticket lifecycle triggers (create, assign, comment, status change) generate
notification_events via database triggers.Delivery Creation
Events create
notification_deliveries for each recipient, respecting user preferences and permission-based routing.Outbox Processing
Push-enabled deliveries enter
notification_outbox for async processing by the Edge Function worker.Database Setup
Prerequisites
- Supabase project with service role access
- SQL editor access for executing setup scripts
pg_netextension enabled (for immediate webhook dispatch)
Execute SQL Modules
Run the core CMMS SQL modules in order. The notifications module is included in the standard bootstrap:The
16_notifications.sql module includes:- Core notification tables (
notification_events,notification_deliveries,notification_preferences) - Push infrastructure (
push_subscriptions,notification_outbox) - Comments system (
ticket_comments) - Triggers for all ticket lifecycle events
- Admin test tools
- Concurrency-safe outbox claiming
- RLS policies and realtime configuration
Verify Realtime Configuration
Ensure these tables are published for realtime updates:VAPID Keys Generation
Generate a VAPID key pair for Web Push authentication:Store Keys Securely
- Supabase Edge Function Secrets
- Frontend Environment
Set secrets for the Edge Function:
Notification Categories
The system organizes notifications into five categories, each controllable via user preferences:| Category | Event Types | Default |
|---|---|---|
| assignments | ticket.assigned, ticket.unassigned | ✓ |
| comments | ticket.comment_added | ✓ |
| status_changes | ticket.status_changed, ticket.accepted, ticket.finalized, ticket.priority_changed, ticket.urgent_changed | ✓ |
| deadlines | ticket.deadline_set, ticket.deadline_changed, ticket.due_soon, ticket.overdue | ✓ |
| admin_system | All non-ticket events (e.g., system.test_notification) | ✓ |
/notificaciones settings.
Channel Mask System
Notifications support multiple delivery channels via bitmask:- Bit 0 (1): In-app notification center
- Bit 1 (2): Push notification
- Bit 2 (4+): Reserved for future channels (email, SMS, etc.)
src/services/notificationCenterService.ts:115 for category-based filtering.
Recipient Routing
Recipients are determined by ticket relationships and permissions:Ticket Creator
Always receives notifications for their own tickets (except when
notify_actor=false)Assigned Technicians
Users linked via
work_order_assignees → assignees.user_idAdmin Permissions
Users with
work_orders:full_access, work_orders:approve, or work_requests:full_accessActor Exclusion
Event actor is excluded unless
notify_actor=true or event type is ticket.createdsql/modules/core_cmms/16_notifications.sql:183 for the get_ticket_recipient_user_ids function.
Testing the Setup
Smoke Test Script
Run the automated smoke test to verify end-to-end flow:- Event creation
- Delivery generation
- Outbox entry creation
- Permission-based routing
- Category filtering
Manual UI Testing
Create Test Notification
Use the “Prueba Admin” button (requires
users:full_access or rbac:manage_permissions)Verify Database State
Next Steps
Deploy Edge Function
Set up the push notification worker for async delivery
Configure PWA
Enable service worker and configure push subscriptions