This is a trivial example of an architecture decision record (ADR) entry, using ASCII diagrams (from Monodraw).
Date: 2024-01-01
Accepted
Use proper segregated architecture for email sending, allowing easy future vendor changes
We will likely need to change email provider soon to choose a more EU-centric privacy focused provider, so building new email functionality should be layered correctly to allow this swap and to allow for easy testing too.
This is the rough architecture:
BACKGROUND TASK FOR BATCH SENDING CONFIRMATION EMAILS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
║ BACKGROUND TASK ║ ORCHESTRATION SERVICE ║ COMMAND HANDLER
┌─────────────────────────────┐ ┌───────────────────────────────┐ ┏━━━━━━━━━━━━━━━━━━━━━━━━━┓
│ │ │ │ ┃ Send ┃
│ MessageSendingTask │──▶│ CustomerMessageSendingService │──▶┃ ConfirmationEmail ┃
│ │ │ │ ┃ CommandHandler ┃
└─────────────────────────────┘ └───────────────────────────────┘ ┗━━━━━━━━━━━━━━━━━━━━━━━━━┛
│ │
TRIGGERS: ▼ ▼
- Every 5 mins ┌───────────────────────────────┐ ┏━━┳━━━━━━━━━┓
- NewMessageQueuedEvent │ CustomerMessageQueueService │ ┃DB┃ Orders ┃
└───────────────────────────────┘ ┗━━┻━━━━━━━━━┛
│
▼
┏━━┳━━━━━━━━━━━━━━┓
┃DB┃ Orders ┃
┗━━┻━━━━━━━━━━━━━━┛
COMMAND HANDLER FOR SENDING CONFIRMATION EMAILS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
│
BUSINESS LOGIC BUSINESS LOGIC INFRASTRUCTURE Either in-house or
Load order, mark as Convert model to fields etc.│ Email sending, retry logic official Nuget
sending, mark as failed
etc. ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ │ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐
IEmailService IEmailDeliveryService
└ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ │ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┌─────────────────────────┐ ┌───────────────────────────────────┐ ┌──────────────────────────┐
┃ Send ┃ │ │ │ │ │ │ │
┃ ConfirmationEmail ┃──▶│ TemplatedEmailService │──▶│ VendorSpecificEmailDeliveryService│──▶│ VendorApiClient │
┃ CommandHandler ┃ │ │ │ │ │ │ │
┗━━━━━━━━━━━━━━━━━━━━━━━━━┛ └─────────────────────────┘ └───────────────────────────────────┘ └──────────────────────────┘
│ │ ┌───────────────────────────────────┐ │
▼ │ │ ▼
┏━━┳━━━━━━━━━┓ │ │ NoopEmailDeliveryService │ ╔════════════════════╗
┃DB┃ Orders ┃ │ │ ║ External Vendor ║
┗━━┻━━━━━━━━━┛ │ └───────────────────────────────────┘ ║ API ║
╚════════════════════╝
│ VENDOR SPECIFIC