Notification Rule Engine
Component Detail
Description
Central rule evaluation service that determines when, to whom, and through which channel notifications are sent. Runs as a scheduled job, iterates registered rules, evaluates conditions against database state, resolves recipients, checks opt-outs via notification settings, and enqueues delivery payloads to the push and email/SMS notification services. Designed for idempotent execution so re-runs within the same time window never produce duplicate sends.
notification-rule-engine
Responsibilities
- Evaluate trigger conditions for all registered notification rules against current database state
- Resolve recipient users from matched entities and filter by notification opt-out preferences
- Dispatch notification payloads to push, email, or SMS delivery channels with deduplication
- Enforce cooldown periods between repeated notifications for the same entity and rule
- Provide a declarative rule registration interface so new scenarios are configuration not code
Interfaces
evaluateAllRules(timeWindow: DateRange): Promise<NotificationBatch[]>
registerRule(rule: NotificationRule): void
unregisterRule(eventType: string): void
getRuleDefinitions(): NotificationRule[]
resolveRecipients(entity: Entity, rule: NotificationRule): Promise<UserId[]>
checkCooldown(userId: string, ruleId: string): Promise<boolean>
enqueueNotification(payload: NotificationPayload): Promise<void>
getExecutionLog(ruleId: string, since: Date): Promise<ExecutionLogEntry[]>
markDelivered(notificationId: string, status: DeliveryStatus): Promise<void>
isDuplicate(userId: string, ruleId: string, entityId: string, window: DateRange): Promise<boolean>
Relationships
Dependencies (2)
Components this component depends on
Sub-Components (2)
Evaluates rule predicates against database entities. Supports time-based conditions (e.g., 10 days without contact), threshold conditions (e.g., assignment count reached), and expiry conditions (e.g., certification expires in 30 days).
- Parse and evaluate temporal predicates against entity timestamps
- Evaluate threshold-based conditions against aggregate counts
- Evaluate expiry-based conditions against date fields
Maps matched entities to recipient user IDs based on the rule's recipient strategy. Handles direct user targets, coordinator lookups, and role-based resolution while filtering out users who have opted out of the relevant notification channel.
- Resolve entity-to-user mapping based on rule recipient strategy
- Filter recipients by notification opt-out preferences
- Support role-based recipient resolution for coordinator and admin scenarios
Related Data Entities (15)
Data entities managed by this component