Skip to content

feat(alerts): event-driven pipeline with delivery guarantees#21

Merged
memplethee-lab merged 1 commit into
SourceXXL:mainfrom
demilade18-git:feat/alerts-event-driven-pipeline
Jun 20, 2026
Merged

feat(alerts): event-driven pipeline with delivery guarantees#21
memplethee-lab merged 1 commit into
SourceXXL:mainfrom
demilade18-git:feat/alerts-event-driven-pipeline

Conversation

@demilade18-git

Copy link
Copy Markdown

Summary

Closes #12 — Align growth/alerts Module: Event-Driven Alert Pipeline with Delivery Guarantees.

  • AlertPreference entity (alert_preferences table) with channels, quietHoursStart, quietHoursEnd, and rateLimit columns
  • AlertDispatcherService with in-memory fingerprint deduplication (5-minute window), per-user rate limiting (default 10/hour), quiet-hours suppression, and exponential backoff retry (up to 3 attempts, base 200 ms)
  • RiskAlertListener subscribing to risk.threshold.breached events via @OnEvent
  • PortfolioAlertListener subscribing to portfolio.rebalanced events via @OnEvent
  • Dual-channel delivery: in-app (persisted to AlertTriggerLog) + email (logged, ready for SendGrid/SES integration)
  • Subscribe/Unsubscribe endpoints with full Swagger @ApiOperation and @ApiResponse documentation behind JwtAuthGuard
  • EventEmitterModule.forRoot() registered in AlertsModule
  • AlertPreference registered in global TypeORM entities list in app.module.ts
  • 8 unit tests in alert-dispatcher.service.spec.ts covering all acceptance criteria

Acceptance Criteria Met

  • RiskAlertListener creates alerts when risk.threshold.breached events are emitted
  • AlertDispatcher delivers through at least 2 channels (in-app + email)
  • Duplicate alerts within a 5-minute window are deduplicated
  • Failed deliveries retry up to 3 times with exponential backoff (200ms, 400ms)
  • AlertPreference entity with channel and quiet-hours configuration
  • POST /api/alerts/subscribe and DELETE /api/alerts/unsubscribe/:userId documented in Swagger
  • Rate limiting prevents more than 10 alerts per user per hour (configurable)
  • npm run build succeeds

Test Plan

  • npx jest --testPathPattern="alert-dispatcher" --no-coverage — 8 tests pass
  • Verify POST /api/alerts/subscribe with { userId, channels: ["in-app","email"] } returns 201
  • Verify DELETE /api/alerts/unsubscribe/:userId removes preference
  • Emit risk.threshold.breached event and confirm AlertTriggerLog entry is created
  • Send 11 alerts for same user in 1 hour — confirm 11th is rate-limited
  • Send same alert payload twice within 5 minutes — confirm second is deduplicated

…rantees

Closes SourceXXL#12. Implements the growth/alerts module with:
- AlertPreference entity for per-user channel and quiet-hours config
- AlertDispatcherService with in-memory dedup (5-min window), rate limiting
  (10 alerts/hour default), quiet-hours suppression, and exponential backoff
  retry (up to 3 attempts, 200ms base)
- RiskAlertListener subscribing to 'risk.threshold.breached' events
- PortfolioAlertListener subscribing to 'portfolio.rebalanced' events
- Delivery to in-app (logged to AlertTriggerLog) and email channels
- POST /api/alerts/subscribe and DELETE /api/alerts/unsubscribe/:userId
  endpoints with full Swagger @apioperation documentation
- 8-test unit suite covering dedup, rate limiting, channel delivery, retries
- AlertPreference registered in TypeORM entities list in app.module.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Align growth/alerts Module — Event-Driven Alert Pipeline with Delivery Guarantees

3 participants