# mail4hafij/notification_service architecture

> Architecture diagram of the GitHub repository mail4hafij/notification_service, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mail4hafij/notification_service
- Repository: https://github.com/mail4hafij/notification_service

## Overview

This repository is a single .NET Core worker-style service whose job is to consume events from RabbitMQ and turn them into notifications, primarily email via SendGrid and Slack channel messages.

1. **Top-level role**
   The service sits downstream of another system that publishes business events to RabbitMQ. It does not expose a user-facing web API; its main runtime behavior is message consumption and notification dispatch.

2. **Runtime and deployment shape**
   The app is containerized with Docker and is designed to run alongside the RabbitMQ-producing system on the same Docker network. `docker-compose` is the main local orchestration mechanism, with separate dev/prod settings files and a local Dockerfile for standalone runs.

3. **Composition root**
   `Program.cs` and `Startup.cs` are the application bootstrap points. They likely wire configuration, dependency injection, and hosted services together so the consumer can start processing messages as the container boots.

4. **RabbitMQ integration boundary**
   `IRabbitEndpoint` / `RabbitEndpoint` and `IRouter` / `Router` form the messaging boundary. This layer is responsible for connecting to RabbitMQ, receiving incoming messages, and directing them to the correct internal handler based on event type.

5. **Event contract and validation**
   The `src/events` folder contains the event-specific contract `SomethingHappened` plus `SomethingHappenedValidator`. This indicates the service treats inbound messages as typed events and validates payloads before processing them further.

6. **Event handling layer**
   `ISomethingHappenedHandler` / `SomethingHappenedHandler` are the business-use-case entry point for that event. This is where the message is translated from an external event into one or more notification actions.

7. **Notification domain model**
   The `models` folder contains shared abstractions such as `IMessage`, `Message`, `Notifier`, `ISettings`, `Settings`, and `ISettingsRepository` / `SettingsRepository`. These types likely hold notification content, recipient/channel configuration, and environment-specific settings that drive delivery behavior.

8. **Sender abstraction**
   Notification delivery is split behind `ISender`, `ISenderFactory`, and `SenderFactory`. This is the key internal boundary that lets the handler choose a delivery channel without coupling itself to email or Slack specifics.

9. **Channel-specific adapters**
   `sender/Email` and `sender/Slack` contain the concrete transport adapters: `EmailSender` with `IEmailSender`, and `SlackSender` with `ISlackSender`. These are the external service integration points for SendGrid/email and Slack.

10. **Configuration and environment split**
    `settings.dev.json` and `settings.prod.json` indicate the app switches behavior by environment. That configuration likely includes RabbitMQ connection details, sender credentials, and channel-specific routing settings.

11. **External systems**
    The architecture depends on three outside systems: RabbitMQ for inbound event transport, SendGrid for email delivery, and Slack for chat notifications. The README also points to a separate repository that produces the RabbitMQ events this service consumes.

12. **Overall data flow**
    The main flow is: external business event → RabbitMQ → `RabbitEndpoint`/`Router` → event validator and handler → message/settings resolution → `SenderFactory` → email or Slack adapter → external notification service.

13. **Diagram boundaries to preserve**
    For an architecture diagram, the most important separations are: transport ingestion, event processing, notification channel selection, and external delivery. The service is essentially a message-driven notification pipeline, not a request/response application.

Main entry points: [`src/events/handlers/SomethingHappenedHandler.cs`](https://github.com/mail4hafij/notification_service/blob/master/src/events/handlers/SomethingHappenedHandler.cs) (Event handler), [`src/Startup.cs`](https://github.com/mail4hafij/notification_service/blob/master/src/Startup.cs) (Startup), [`src/Router.cs`](https://github.com/mail4hafij/notification_service/blob/master/src/Router.cs) (Router), [`src/sender/SenderFactory.cs`](https://github.com/mail4hafij/notification_service/blob/master/src/sender/SenderFactory.cs) (Sender factory)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_runtime["Runtime"]
  node_node_program["Program<br/>bootstrap<br/>[Program.cs]"]
  node_node_startup["Startup<br/>composition root<br/>[Startup.cs]"]
  node_node_compose["Compose<br/>deploy config<br/>[docker-compose.yml]"]
  node_node_compose_override["Dev compose<br/>deploy config"]
  node_node_dockerfile_local["Local image<br/>container build<br/>[Dockerfile.local]"]
end

subgraph group_group_messaging["Messaging"]
  node_node_rabbit_endpoint["Rabbit endpoint<br/>mq ingress<br/>[RabbitEndpoint.cs]"]
  node_node_irabbit_endpoint["IRabbitEndpoint<br/>mq port<br/>[IRabbitEndpoint.cs]"]
  node_node_router["Router<br/>[Router.cs]"]
  node_node_irouter["IRouter<br/>routing port<br/>[IRouter.cs]"]
end

subgraph group_group_processing["Processing"]
  node_node_event["Event<br/>contract"]
  node_node_validator["Validator<br/>validation"]
  node_node_handler["Event handler<br/>use case"]
  node_node_ihandler["IHandler<br/>use case port"]
end

subgraph group_group_domain["Domain"]
  node_node_message["Message<br/>notification model<br/>[Message.cs]"]
  node_node_notifier["Notifier<br/>notification model<br/>[Notifier.cs]"]
  node_node_settings["Settings<br/>config model<br/>[Settings.cs]"]
  node_node_settings_repo["Settings repo<br/>settings access"]
end

subgraph group_group_delivery["Delivery"]
  node_node_sender_factory["Sender factory<br/>channel selector<br/>[SenderFactory.cs]"]
  node_node_isender_factory["ISenderFactory<br/>channel port<br/>[ISenderFactory.cs]"]
  node_node_isender["ISender<br/>delivery port<br/>[ISender.cs]"]
  node_node_email_sender["Email sender<br/>email adapter<br/>[EmailSender.cs]"]
  node_node_islack_sender["ISlackSender<br/>slack port<br/>[ISlackSender.cs]"]
  node_node_slack_sender["Slack sender<br/>slack adapter<br/>[SlackSender.cs]"]
end

subgraph group_group_external["External systems"]
  node_node_rabbitmq(("RabbitMQ<br/>broker"))
  node_node_sendgrid(("SendGrid<br/>email service"))
  node_node_slack(("Slack<br/>chat service"))
  node_node_publisher(("Event producer<br/>upstream system"))
end

node_node_program -->|"boots"| node_node_startup
node_node_program -->|"starts"| node_node_rabbit_endpoint
node_node_startup -->|"registers"| node_node_irabbit_endpoint
node_node_startup -->|"registers"| node_node_irouter
node_node_startup -->|"registers"| node_node_isender_factory
node_node_startup -->|"registers"| node_node_settings_repo
node_node_publisher -->|"publishes"| node_node_rabbitmq
node_node_rabbitmq -->|"delivers"| node_node_rabbit_endpoint
node_node_rabbit_endpoint -->|"routes"| node_node_router
node_node_irouter -.->|"implements"| node_node_router
node_node_irabbit_endpoint -.->|"implements"| node_node_rabbit_endpoint
node_node_router -->|"binds"| node_node_event
node_node_router -->|"validates"| node_node_validator
node_node_router -->|"dispatches"| node_node_handler
node_node_ihandler -.->|"implements"| node_node_handler
node_node_handler -->|"reads"| node_node_settings_repo
node_node_handler -->|"creates"| node_node_message
node_node_handler -->|"uses"| node_node_notifier
node_node_handler -->|"selects"| node_node_sender_factory
node_node_isender_factory -.->|"implements"| node_node_sender_factory
node_node_sender_factory -->|"returns"| node_node_isender
node_node_sender_factory -->|"creates"| node_node_email_sender
node_node_sender_factory -->|"creates"| node_node_slack_sender
node_node_email_sender -->|"delivers to"| node_node_sendgrid
node_node_slack_sender -->|"delivers to"| node_node_slack
node_node_islack_sender -.->|"implements"| node_node_slack_sender
node_node_isender -.->|"abstraction for"| node_node_email_sender
node_node_isender -.->|"abstraction for"| node_node_slack_sender

click node_node_program "https://github.com/mail4hafij/notification_service/blob/master/src/Program.cs"
click node_node_startup "https://github.com/mail4hafij/notification_service/blob/master/src/Startup.cs"
click node_node_compose "https://github.com/mail4hafij/notification_service/blob/master/docker-compose.yml"
click node_node_compose_override "https://github.com/mail4hafij/notification_service/blob/master/docker-compose.override.yml"
click node_node_dockerfile_local "https://github.com/mail4hafij/notification_service/blob/master/Dockerfile.local"
click node_node_rabbit_endpoint "https://github.com/mail4hafij/notification_service/blob/master/src/RabbitEndpoint.cs"
click node_node_irabbit_endpoint "https://github.com/mail4hafij/notification_service/blob/master/src/IRabbitEndpoint.cs"
click node_node_router "https://github.com/mail4hafij/notification_service/blob/master/src/Router.cs"
click node_node_irouter "https://github.com/mail4hafij/notification_service/blob/master/src/IRouter.cs"
click node_node_event "https://github.com/mail4hafij/notification_service/blob/master/src/events/SomethingHappened.cs"
click node_node_validator "https://github.com/mail4hafij/notification_service/blob/master/src/events/SomethingHappenedValidator.cs"
click node_node_handler "https://github.com/mail4hafij/notification_service/blob/master/src/events/handlers/SomethingHappenedHandler.cs"
click node_node_ihandler "https://github.com/mail4hafij/notification_service/blob/master/src/events/handlers/ISomethingHappenedHandler.cs"
click node_node_message "https://github.com/mail4hafij/notification_service/blob/master/src/models/Message.cs"
click node_node_notifier "https://github.com/mail4hafij/notification_service/blob/master/src/models/Notifier.cs"
click node_node_settings "https://github.com/mail4hafij/notification_service/blob/master/src/models/Settings.cs"
click node_node_settings_repo "https://github.com/mail4hafij/notification_service/blob/master/src/models/SettingsRepository.cs"
click node_node_sender_factory "https://github.com/mail4hafij/notification_service/blob/master/src/sender/SenderFactory.cs"
click node_node_isender_factory "https://github.com/mail4hafij/notification_service/blob/master/src/sender/ISenderFactory.cs"
click node_node_isender "https://github.com/mail4hafij/notification_service/blob/master/src/sender/ISender.cs"
click node_node_email_sender "https://github.com/mail4hafij/notification_service/blob/master/src/sender/Email/EmailSender.cs"
click node_node_islack_sender "https://github.com/mail4hafij/notification_service/blob/master/src/sender/Slack/ISlackSender.cs"
click node_node_slack_sender "https://github.com/mail4hafij/notification_service/blob/master/src/sender/Slack/SlackSender.cs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_node_program,node_node_startup,node_node_compose,node_node_compose_override,node_node_dockerfile_local toneBlue
class node_node_rabbit_endpoint,node_node_irabbit_endpoint,node_node_router,node_node_irouter toneAmber
class node_node_event,node_node_validator,node_node_handler,node_node_ihandler toneMint
class node_node_message,node_node_notifier,node_node_settings,node_node_settings_repo toneRose
class node_node_sender_factory,node_node_isender_factory,node_node_isender,node_node_email_sender,node_node_islack_sender,node_node_slack_sender toneIndigo
class node_node_rabbitmq,node_node_sendgrid,node_node_slack,node_node_publisher toneTeal
```

## Components

### Runtime

Containerized .NET worker bootstrap and deployment

- [Program](https://github.com/mail4hafij/notification_service/blob/master/src/Program.cs): bootstrap · Application entry point and host startup · `src/Program.cs`
- [Startup](https://github.com/mail4hafij/notification_service/blob/master/src/Startup.cs): composition root · Wires configuration, services, and hosted components · `src/Startup.cs`
- [Compose](https://github.com/mail4hafij/notification_service/blob/master/docker-compose.yml): deploy config · Local Docker orchestration for the service · `docker-compose.yml`
- [Dev compose](https://github.com/mail4hafij/notification_service/blob/master/docker-compose.override.yml): deploy config · Local override settings for development runs · `docker-compose.override.yml`
- [Local image](https://github.com/mail4hafij/notification_service/blob/master/Dockerfile.local): container build · Standalone local Docker image build · `Dockerfile.local`

### Messaging

RabbitMQ ingestion and event routing boundary

- [Rabbit endpoint](https://github.com/mail4hafij/notification_service/blob/master/src/RabbitEndpoint.cs): mq ingress · Connects to RabbitMQ and receives messages · `src/RabbitEndpoint.cs`
- [IRabbitEndpoint](https://github.com/mail4hafij/notification_service/blob/master/src/IRabbitEndpoint.cs): mq port · Messaging boundary contract · `src/IRabbitEndpoint.cs`
- [Router](https://github.com/mail4hafij/notification_service/blob/master/src/Router.cs): event router · Dispatches incoming messages to handlers · `src/Router.cs`
- [IRouter](https://github.com/mail4hafij/notification_service/blob/master/src/IRouter.cs): routing port · Router contract for message dispatch · `src/IRouter.cs`

### Processing

Event validation and use-case handling

- [Event](https://github.com/mail4hafij/notification_service/blob/master/src/events/SomethingHappened.cs): contract · Typed inbound business event · `src/events/SomethingHappened.cs`
- [Validator](https://github.com/mail4hafij/notification_service/blob/master/src/events/SomethingHappenedValidator.cs): validation · Validates inbound event payloads · `src/events/SomethingHappenedValidator.cs`
- [Event handler](https://github.com/mail4hafij/notification_service/blob/master/src/events/handlers/SomethingHappenedHandler.cs): use case · Transforms the event into notification actions · `src/events/handlers/SomethingHappenedHandler.cs`
- [IHandler](https://github.com/mail4hafij/notification_service/blob/master/src/events/handlers/ISomethingHappenedHandler.cs): use case port · Handler interface for the event · `src/events/handlers/ISomethingHappenedHandler.cs`

### Domain

Notification message and settings model

- [Message](https://github.com/mail4hafij/notification_service/blob/master/src/models/Message.cs): notification model · Notification content abstraction · `src/models/Message.cs`
- [Notifier](https://github.com/mail4hafij/notification_service/blob/master/src/models/Notifier.cs): notification model · Represents notification targeting or channel intent · `src/models/Notifier.cs`
- [Settings](https://github.com/mail4hafij/notification_service/blob/master/src/models/Settings.cs): config model · Runtime configuration for delivery and routing · `src/models/Settings.cs`
- [Settings repo](https://github.com/mail4hafij/notification_service/blob/master/src/models/SettingsRepository.cs): settings access · Resolves environment-specific settings · `src/models/SettingsRepository.cs`

### Delivery

Channel selection and external notification adapters

- [Sender factory](https://github.com/mail4hafij/notification_service/blob/master/src/sender/SenderFactory.cs): channel selector · Chooses the appropriate delivery adapter · `src/sender/SenderFactory.cs`
- [ISenderFactory](https://github.com/mail4hafij/notification_service/blob/master/src/sender/ISenderFactory.cs): channel port · Factory abstraction for sender selection · `src/sender/ISenderFactory.cs`
- [ISender](https://github.com/mail4hafij/notification_service/blob/master/src/sender/ISender.cs): delivery port · Common sender abstraction · `src/sender/ISender.cs`
- [Email sender](https://github.com/mail4hafij/notification_service/blob/master/src/sender/Email/EmailSender.cs): email adapter · SendGrid/email delivery integration · `src/sender/Email/EmailSender.cs`
- [ISlackSender](https://github.com/mail4hafij/notification_service/blob/master/src/sender/Slack/ISlackSender.cs): slack port · Slack delivery contract · `src/sender/Slack/ISlackSender.cs`
- [Slack sender](https://github.com/mail4hafij/notification_service/blob/master/src/sender/Slack/SlackSender.cs): slack adapter · Slack channel delivery integration · `src/sender/Slack/SlackSender.cs`

### External systems

Services this repository depends on at runtime

- **RabbitMQ**: broker · Inbound event transport
- **SendGrid**: email service · External email delivery service
- **Slack**: chat service · External chat notification service
- **Event producer**: upstream system · Separate system that publishes business events

## Connections

- Program → Startup: boots · Host starts with composition root
- Program → Rabbit endpoint: starts · Hosted runtime begins consuming messages
- Startup → IRabbitEndpoint: registers · Dependency injection wiring for messaging boundary
- Startup → IRouter: registers · Dependency injection wiring for routing
- Startup → ISenderFactory: registers · Dependency injection wiring for channel selection
- Startup → Settings repo: registers · Dependency injection wiring for settings access
- Event producer → RabbitMQ: publishes · Upstream system emits business events
- RabbitMQ → Rabbit endpoint: delivers · Broker feeds incoming messages to the consumer
- Rabbit endpoint → Router: routes · Endpoint hands messages to the router
- IRouter → Router: implements · Router is the concrete dispatcher
- IRabbitEndpoint → Rabbit endpoint: implements · RabbitEndpoint is the concrete broker adapter
- Router → Event: binds · Selects the typed event contract
- Router → Validator: validates · Applies event payload validation
- Router → Event handler: dispatches · Hands validated events to the handler
- IHandler → Event handler: implements · Concrete event use-case handler
- Event handler → Settings repo: reads · Resolves runtime settings for delivery
- Event handler → Message: creates · Builds notification payloads
- Event handler → Notifier: uses · Applies notification targeting metadata
- Event handler → Sender factory: selects · Chooses a delivery channel through the factory
- ISenderFactory → Sender factory: implements · Concrete factory implementation
- Sender factory → ISender: returns · Produces a sender abstraction
- Sender factory → Email sender: creates · Selects email transport when needed
- Sender factory → Slack sender: creates · Selects Slack transport when needed
- Email sender → SendGrid: delivers to · Email transport targets SendGrid
- Slack sender → Slack: delivers to · Slack transport targets Slack
- ISlackSender → Slack sender: implements · Slack sender concrete adapter
- ISender → Email sender: abstraction for · Email sender conforms to sender contract
- ISender → Slack sender: abstraction for · Slack sender conforms to sender contract
