How mail4hafij/notification_service works
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: SomethingHappenedHandler.cs Event handler · Startup.cs Startup · Router.cs Router · SenderFactory.cs Sender factory
Components 27
Runtime
Containerized .NET worker bootstrap and deployment
- Program · Application entry point and host startup
src/Program.cs - Startup · Wires configuration, services, and hosted components
src/Startup.cs - Compose · Local Docker orchestration for the service
docker-compose.yml - Dev compose · Local override settings for development runs
docker-compose.override.yml - Local image · Standalone local Docker image build
Dockerfile.local
Messaging
RabbitMQ ingestion and event routing boundary
- Rabbit endpoint · Connects to RabbitMQ and receives messages
src/RabbitEndpoint.cs - IRabbitEndpoint · Messaging boundary contract
src/IRabbitEndpoint.cs - Router · Dispatches incoming messages to handlers
src/Router.cs - IRouter · Router contract for message dispatch
src/IRouter.cs
Processing
Event validation and use-case handling
- Event · Typed inbound business event
src/events/SomethingHappened.cs - Validator · Validates inbound event payloads
src/events/SomethingHappenedValidator.cs - Event handler · Transforms the event into notification actions
src/events/handlers/SomethingHappenedHandler.cs - IHandler · Handler interface for the event
src/events/handlers/ISomethingHappenedHandler.cs
Domain
Notification message and settings model
- Message · Notification content abstraction
src/models/Message.cs - Notifier · Represents notification targeting or channel intent
src/models/Notifier.cs - Settings · Runtime configuration for delivery and routing
src/models/Settings.cs - Settings repo · Resolves environment-specific settings
src/models/SettingsRepository.cs
Delivery
Channel selection and external notification adapters
- Sender factory · Chooses the appropriate delivery adapter
src/sender/SenderFactory.cs - ISenderFactory · Factory abstraction for sender selection
src/sender/ISenderFactory.cs - ISender · Common sender abstraction
src/sender/ISender.cs - Email sender · SendGrid/email delivery integration
src/sender/Email/EmailSender.cs - ISlackSender · Slack delivery contract
src/sender/Slack/ISlackSender.cs - Slack sender · Slack channel delivery integration
src/sender/Slack/SlackSender.cs
External systems
Services this repository depends on at runtime
- RabbitMQ · Inbound event transport
- SendGrid · External email delivery service
- Slack · External chat notification service
- Event producer · Separate system that publishes business events
Connections 28
- 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