Notification Template Processor
A template processing pipeline that transforms incoming events into rendered notifications. Watch how messages flow through validation, strategy selection, template resolution, and rendering.
SNS Message
Incoming notification event
Validation
Validate user & determine destinations
Strategy
Domain-specific token preparation
Template
Resolve & retrieve from S3
Render
Interpolate tokens into template
SQS Delivery
Ready for notification delivery
{
"actionType": "PAYMENT_SCHEDULED",
"tokens": {
"PAYMENT_AMOUNT": "100.00",
"PAYMENT_DATE": "2025-12-15",
"ACCOUNT_LAST_4": "1234"
},
"userId": "550e8400...",
"accountId": "acct_12345"
}Processing Stages
1. Event Ingestion
- •SNS message arrives with action type and raw tokens
- •Contains user/account identifiers for routing
- •Optional brand identifier for multi-tenant support
2. Validation & Routing
- •Validates user access and permissions
- •Determines notification destinations (Email, SMS, Push)
- •Creates internal notification DTO
3. Token Preparation
- •Strategy pattern for domain-specific token preparation
- •14 strategies (Payment, Account, Dispute, etc.) each handle their action types
- •Makes the flow easier to read, evolve, and test independently
4. Template Resolution
- •Maps (ActionType, DestinationType) → templateId via registry
- •Retrieves HTML template from S3 storage
- •Path: s3://{bucket}/{brand}/templates/{action}.html
5. Rendering
- •Extracts title/body from HTML (meta tags, divs, or fallbacks)
- •Interpolates tokens using {{TOKEN_NAME}} syntax
- •HTML-escapes values for security
6. Delivery
- •Complete notification ready for delivery
- •Includes title, body, rendered HTML, destinations
- •Queued to SQS for downstream notification service
Hexagonal Architecture
Framework-agnostic core
- →Strategy interfaces
- →Domain-specific contracts
- →Metadata annotations
- →Actions & domain models
Use cases & orchestration
- →Port interfaces
- →Use case orchestration
- →Strategy composition
- →Service contracts
Framework-specific adapters
- →Strategy implementations
- →Port adapters
- →External services (S3, etc.)
- →Framework integrations
Key Patterns
Hexagonal Architecture
Clean separation of Domain, Application, and Infrastructure layers with ports and adapters for flexibility.
Strategy Pattern
Domain-specific token preparation for each action type. Makes the flow readable, evolvable, and testable.
Registry-Based Resolution
YAML registry maps (ActionType + Destination) → templateId. Runtime changes without deployment.
S3-Based Templates
Templates stored in S3 organized by brand and action type. Marketing updates independently.
HTML Template Processing
Extracts title/body from HTML meta tags or divs. Token interpolation with {{PLACEHOLDER}} syntax.
Multi-Channel Delivery
Single event triggers Email, SMS, and Push via SNS/SQS decoupled async processing.