Deep DivesNotification

Introduction

An overview of the RawStack Notification component.

The Notification service is a serverless AWS Lambda application responsible for sending email and SMS notifications. It is event-driven: events published to EventBridge are routed to the Lambda, which then maps them to the appropriate notification strategy and delivery channel.

The codebase is best understood as a small event-processing service. It receives domain events, decides which notification workflow applies, renders the required content, and delivers it through external providers such as Resend and Twilio.

Tech specification

The Notification service currently uses:

  • TypeScript
  • AWS Lambda on Node.js
  • Amazon EventBridge
  • Resend
  • Twilio
  • React Email
  • @react-email/components
  • React and React DOM
  • dotenv

Architecture

The service is organised around strategies, channels, and providers.

Each supported event type is mapped to a notification strategy. The strategy decides which channels to use and what content should be sent. Channels abstract the delivery mechanism, while providers wrap the underlying third-party APIs.

The main flow looks like this:

EventBridge event

Lambda handler

Notification registry

Notification strategy

Channel (email / SMS)

Provider (Resend / Twilio)

Supported event types

The current service supports event-driven notifications such as:

  • UserWasCreated
  • AuthTokenWasCreated

New event types are added by implementing a new NotificationStrategy and registering it in NotificationRegistry.

Directory structure

The main project structure looks like this:

services/notification/
  src/
    index.ts
    channel/
    provider/
      email/
      sms/
    strategy/
      NotificationStrategy.ts
      NotificationRegistry.ts
      notifications/
    content/
    validation/
    exception/
  .env.example
  package.json
  • src/index.ts: Lambda handler entry point
  • src/channel: channel interfaces and implementations
  • src/provider: provider implementations for delivery services
  • src/strategy: notification registry and per-event strategies
  • src/content: email templates and content builders
  • src/validation: input validation helpers
  • src/exception: custom error types

Email templates

Email templates are built with React Email and @react-email/components. Templates are rendered to HTML inside the Lambda at runtime, so there is no separate email rendering service.