Archicise
Exercise

Design a Notification System with Hexagonal Architecture

Apply Hexagonal Architecture (Ports & Adapters) to design a multi-channel notification system that is fully decoupled from infrastructure.

Functional Requirements

  • Send notifications via email, SMS, push, and in-app channels
  • Support templates with variable substitution
  • Apply per-user channel preferences
  • Retry failed deliveries with backoff
  • Track delivery status and open rates

Design Challenges

  • Define clear primary (driving) and secondary (driven) ports
  • Keep the domain completely ignorant of infrastructure
  • Allow channel implementations to be swapped without touching business logic

Questions to Consider

  • What are the input and output ports of the notification domain?
  • How do you test the domain core without real email/SMS providers?
  • How do you handle a user who has disabled all channels?
Your Solution

Domain Core & Ports

Define the domain core: Notification, Template, UserPreferences, DeliveryAttempt. Specify the primary port (NotificationUseCase interface called by API/workers) and secondary ports (NotificationChannel, TemplateRepository, PreferenceRepository). No infrastructure types should appear in the domain.