Skip to main content

Architecture Overview

Packages involved: server/src/notification/, server/src/instantdb/, server/src/bullmq/, server/src/moderation/, server/src/templates/

1. Push Notification Type Definitions

File: server/src/notification/enums/push.enum.ts 42 push notification types across 6 categories:

2. Core Workflow Registration & Factory

File: server/src/notification/workflows.service.ts

Factory Pattern (workflows.service.ts:120-131)

Returns Novu’s workflow() function. All workflows follow:

Workflow Registration (workflows.service.ts:1422-1449)

getWorkFlows() returns an array of 23 workflow instances:

3. Push Notification Workflow (Single Channel)

File: server/src/notification/workflows.service.ts:132-163

Invocation Path

Step Flow

Typical Caller Pattern

Triggered mostly via triggerWithCircuitBreaker() which wraps the trigger in:
  • CircuitBreakerStrategy: 60% error threshold, 8 req volume, 15s sleep, 90s window
  • RetryStrategy: 3 max retries, 15s max delay, exponential backoff (1.5s base)

4. Chat Message Push Notification Flow

Message Creation & Queuing

BullMQ Notification Processor

File: server/src/notification/processors/notification.processor.ts

Chat Notification Workflow Definition

File: server/src/notification/workflows.service.ts:1381-1420

Message Formatting

File: server/src/notification/services/message-formatter.service.ts Digest windows:
  • PRIVATE rooms: CHAT_NOTIFICATION_DIGEST_WINDOW_DM (1s)
  • GROUP rooms: CHAT_NOTIFICATION_DIGEST_WINDOW_GROUP (10s)
  • CATEGORY rooms: CHAT_NOTIFICATION_DIGEST_WINDOW_CATEGORY (10s)

5. Event-Driven Push Notification Flow

File: server/src/notification/listeners/notification.listener.ts

Trigger Pattern

All event handlers follow:

Events → Workflow Mapping (with push)

The SPACE_SESSION_LIVE handler (notification.listener.ts:419-450) is the only event-driven path that triggers push notifications:

6. Multistep Workflow (Multi-Channel)

File: server/src/notification/workflows.service.ts:294-457 Single trigger → up to 4 channel steps, each with conditional skip:
Payload schema:

7. Consultation Reminder Push

Scheduling (BullMQ → ReminderProcessor)

File: server/src/bullmq/processors/reminder.processor.ts

Reminder Workflow Definition

File: server/src/notification/workflows.service.ts:490-590

8. Device Token Registration & Novu Sync

File: server/src/notification/notification.service.ts

Client → Server Flow

Device Token Entity

File: server/src/notification/entities/device-tokens.entity.ts

9. Topic-Based Group Push

Topic Lifecycle

Room Creation (instantdb.service.ts:365-419):
Topic Initialization (notification.service.ts:338-359):
Participant Subscription (instantdb.service.ts:137-188):
Participant Unsubscription (instantdb.service.ts:310-332):

Topic Notification Delivery

From Chat Processor (notification.processor.ts:287-296):
Generic Topic Notification (notification.service.ts:271-286):

10. Resilience & Error Handling

File: server/src/notification/workflows.service.ts:1293-1379

Circuit Breaker + Retry

isRetryableError() classifies errors: timeouts, network errors, template processing errors, user lookup errors, Novu validation errors, rate limiting (429), service unavailable (502/503/504).

Chat Notification Failure Isolation

In NotificationProcessor (notification.processor.ts:136-142):
  • Errors are logged but NOT thrown (prevents job retry)
  • Chat message creation is decoupled from notification delivery
  • “Chat notification failed, but chat message creation succeeded”

11. Test Trigger Endpoint

File: server/src/notification/notification.controller.ts:99-138 POST /notification/test-trigger with { channel: 'push' | 'email' | 'inapp' | 'sms' | 'multistep' }:

12. Novu Subscriber Management

File: server/src/notification/notification.service.ts

Topic Management


13. Key Enums & Constants

File: server/src/notification/enums/

14. Data Flow Diagrams

Push Notification (Single Channel)

Chat Message Push

Device Token Registration

Event-Driven Push (Space Session Live)


15. File Index