# lecarvalho/messenger-api architecture

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

- Interactive diagram: https://gitdiagram.com/lecarvalho/messenger-api
- Repository: https://github.com/lecarvalho/messenger-api

## Overview

1. **Overall shape**
   - This is a layered **.NET 5 REST API** called `MessengerApi`.
   - The code is split into four main runtime assemblies: **Web API**, **Services**, **DAL**, and **Business**.
   - The design centers on one responsibility: accept a message request and dispatch it through one or more external messaging channels.

2. **HTTP ingress**
   - `MessengerApi.Webapi` is the entrypoint exposed over HTTP.
   - `MessageController` is the main API surface and likely receives message submission requests.
   - `Program.cs` and `Startup.cs` bootstrap ASP.NET Core, register dependencies, and load configuration from `appsettings.json`.
   - Swagger is enabled for interactive API exploration, as noted in the README.

3. **Domain layer**
   - `MessengerApi.Business` contains the core models: `MessageModel`, `UserModel`, and a shared `ModelBase`.
   - This layer represents the message/customer data the API works with, independent of transport or storage.
   - It is the boundary where the API payload becomes a structured domain object.

4. **Dispatch orchestration**
   - `MessengerApi.Services` contains the core application logic.
   - `DispatcherService` appears to orchestrate how an incoming message is routed to one or more dispatchers.
   - `DispatchOptions`, `AppConfig`, `EmailConfig`, and `SlackConfig` indicate the dispatch behavior is driven by configuration rather than hardcoded logic.

5. **Channel-specific dispatchers**
   - The `Dispatchers` folder contains the channel implementations: `EmailDispatcher` and `SlackDispatcher`.
   - `DispatcherBase` suggests a common contract or shared behavior for messenger adapters.
   - `SlackStruct` indicates Slack needs a channel-specific payload shape before sending.
   - Architecturally, this is the main extensibility point for adding new messengers such as WhatsApp or other APIs.

6. **Outbound network boundary**
   - `Providers/NetworkProvider.cs` is the shared outbound communication layer.
   - This likely encapsulates HTTP calls or other network concerns used by the dispatchers.
   - The important boundary here is: business dispatch logic does not talk directly to external services; it goes through a provider abstraction.

7. **Persistence**
   - `MessengerApi.DAL` contains the data access layer.
   - `DataContext.cs`, `FirestoreConfig.cs`, `RepositoryBase.cs`, and `MessageRepository.cs` show that persistence is abstracted behind repositories.
   - Firestore is the named storage backend, so the app persists or retrieves message-related data through Google Firestore rather than local state.

8. **Dependency flow**
   - The expected flow is:
     - HTTP request enters `Webapi`
     - controller maps request into `Business` models
     - `Services.DispatcherService` decides which dispatchers to invoke
     - dispatcher implementations call external APIs through `NetworkProvider`
     - persistence, if needed, goes through `DAL` repositories backed by Firestore
   - This creates clear boundaries between transport, orchestration, messaging adapters, and storage.

9. **Configuration model**
   - The repository relies heavily on environment/configuration files.
   - `appsettings.json` in the Web API project is the primary deployment-time configuration source.
   - Separate config classes in `Services` and `DAL` indicate typed binding of settings for dispatch targets and Firestore.

10. **Deployment/runtime**
   - The repo is container-first: there is a root `Dockerfile`, a README example using `docker run`, and a script to build/push an image to a container registry.
   - The app is intended to run as a single web service container exposing HTTP on port 80 internally.
   - The README also shows `appsettings.json` is mounted into the container, so runtime configuration is expected to be externalized.

11. **Dev and CI tooling**
   - `.devcontainer` and `.vscode` support containerized development environments.
   - `azure-pipelines-ci.yml` indicates a CI pipeline, likely for build/test/container image publishing.
   - These tools do not change the app architecture, but they reinforce that the project is designed for portable containerized deployment.

12. **Architectural takeaway**
   - The key diagram should show a **thin API layer**, a **dispatch orchestration service**, **pluggable messenger adapters**, and a **Firestore-backed repository layer**.
   - The principal external boundaries are the **caller hitting the REST API**, **messaging platforms like Slack/email**, and **Firestore for persistence**.

Main entry points: [`MessengerApi.Services/DispatcherService.cs`](https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Services/DispatcherService.cs) (Dispatcher), [`MessengerApi.Webapi/Controllers/MessageController.cs`](https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Webapi/Controllers/MessageController.cs) (Message API), [`MessengerApi.Services/Dispatchers/SlackDispatcher.cs`](https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Services/Dispatchers/SlackDispatcher.cs) (Slack Sender), [`MessengerApi.Services/Dispatchers/EmailDispatcher.cs`](https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Services/Dispatchers/EmailDispatcher.cs) (Email Sender)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_webapi["Web API"]
  node_node_message_controller["Message API<br/>controller"]
  node_node_program_startup["Bootstrap<br/>aspnet host<br/>[Program.cs]"]
  node_node_appsettings["App Config<br/>json config<br/>[appsettings.json]"]
end

subgraph group_group_services["Services"]
  node_node_dispatcher_service["Dispatcher<br/>orchestrator"]
  node_node_dispatch_options["Dispatch Options<br/>config model<br/>[DispatchOptions.cs]"]
  node_node_app_config["Service Config<br/>config model<br/>[AppConfig.cs]"]
  node_node_email_dispatcher["Email Sender<br/>dispatcher<br/>[EmailDispatcher.cs]"]
  node_node_slack_dispatcher["Slack Sender<br/>dispatcher<br/>[SlackDispatcher.cs]"]
  node_node_dispatcher_base["Dispatcher Base<br/>base adapter<br/>[DispatcherBase.cs]"]
  node_node_network_provider["Network Provider<br/>outbound client<br/>[NetworkProvider.cs]"]
  node_node_slack_struct["Slack Payload<br/>payload model<br/>[SlackStruct.cs]"]
end

subgraph group_group_business["Business"]
  node_node_message_model["Message Model<br/>domain model<br/>[MessageModel.cs]"]
  node_node_user_model["User Model<br/>domain model<br/>[UserModel.cs]"]
  node_node_model_base["Model Base<br/>domain base<br/>[ModelBase.cs]"]
end

subgraph group_group_dal["DAL"]
  node_node_message_repo["Message Repo"]
  node_node_repository_base["Repository Base<br/>[RepositoryBase.cs]"]
  node_node_data_context["Data Context<br/>db context<br/>[DataContext.cs]"]
  node_node_firestore_config["Firestore Config<br/>config model<br/>[FirestoreConfig.cs]"]
end

subgraph group_group_ops["Runtime / Ops"]
  node_node_container_ops["Container Ops<br/>deployment"]
end

node_node_http_client(("Caller<br/>external client"))
node_node_firestore[("Firestore<br/>external datastore")]
node_node_messaging_platforms(("Channels<br/>external service"))

node_node_http_client -->|"HTTP request"| node_node_message_controller
node_node_message_controller -.->|"uses host"| node_node_program_startup
node_node_message_controller -->|"maps to"| node_node_message_model
node_node_message_controller -->|"invokes"| node_node_dispatcher_service
node_node_program_startup -->|"loads"| node_node_appsettings
node_node_dispatcher_service -->|"binds"| node_node_dispatch_options
node_node_dispatcher_service -->|"binds"| node_node_app_config
node_node_dispatcher_service -->|"routes to"| node_node_email_dispatcher
node_node_dispatcher_service -->|"routes to"| node_node_slack_dispatcher
node_node_email_dispatcher -.->|"extends"| node_node_dispatcher_base
node_node_slack_dispatcher -.->|"extends"| node_node_dispatcher_base
node_node_email_dispatcher -->|"sends via"| node_node_network_provider
node_node_slack_dispatcher -->|"sends via"| node_node_network_provider
node_node_slack_dispatcher -->|"formats"| node_node_slack_struct
node_node_dispatcher_service -->|"persists"| node_node_message_repo
node_node_message_repo -.->|"extends"| node_node_repository_base
node_node_message_repo -->|"uses"| node_node_data_context
node_node_data_context -->|"binds"| node_node_firestore_config
node_node_data_context -->|"stores in"| node_node_firestore
node_node_network_provider -->|"calls"| node_node_messaging_platforms
node_node_container_ops -.->|"packages"| node_node_program_startup

click node_node_message_controller "https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Webapi/Controllers/MessageController.cs"
click node_node_program_startup "https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Webapi/Program.cs"
click node_node_appsettings "https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Webapi/appsettings.json"
click node_node_dispatcher_service "https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Services/DispatcherService.cs"
click node_node_dispatch_options "https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Services/Configuration/DispatchOptions.cs"
click node_node_app_config "https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Services/Configuration/AppConfig.cs"
click node_node_email_dispatcher "https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Services/Dispatchers/EmailDispatcher.cs"
click node_node_slack_dispatcher "https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Services/Dispatchers/SlackDispatcher.cs"
click node_node_dispatcher_base "https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Services/Dispatchers/DispatcherBase.cs"
click node_node_network_provider "https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Services/Providers/NetworkProvider.cs"
click node_node_slack_struct "https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Services/Dispatchers/Structs/SlackStruct.cs"
click node_node_message_model "https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Business/Models/MessageModel.cs"
click node_node_user_model "https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Business/Models/UserModel.cs"
click node_node_model_base "https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Business/Models/ModelBase.cs"
click node_node_message_repo "https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.DAL/Repository/MessageRepository.cs"
click node_node_repository_base "https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.DAL/Repository/RepositoryBase.cs"
click node_node_data_context "https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.DAL/DataContext.cs"
click node_node_firestore_config "https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.DAL/Configuration/FirestoreConfig.cs"
click node_node_container_ops "https://github.com/lecarvalho/messenger-api/tree/master/Dockerfile"

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_message_controller,node_node_program_startup,node_node_appsettings toneBlue
class node_node_dispatcher_service,node_node_dispatch_options,node_node_app_config,node_node_email_dispatcher,node_node_slack_dispatcher,node_node_dispatcher_base,node_node_network_provider,node_node_slack_struct toneAmber
class node_node_message_model,node_node_user_model,node_node_model_base toneMint
class node_node_message_repo,node_node_repository_base,node_node_data_context,node_node_firestore_config toneRose
class node_node_container_ops toneIndigo
class node_node_http_client,node_node_firestore,node_node_messaging_platforms toneNeutral
```

## Components

### Web API

HTTP entrypoint and ASP.NET Core bootstrapping

- [Message API](https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Webapi/Controllers/MessageController.cs): controller · Main HTTP surface for message submission · `MessengerApi.Webapi/Controllers/MessageController.cs`
- [Bootstrap](https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Webapi/Program.cs): aspnet host · Program and Startup configure the web host and DI · `MessengerApi.Webapi/Program.cs`
- [App Config](https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Webapi/appsettings.json): json config · Deployment-time API configuration · `MessengerApi.Webapi/appsettings.json`

### Services

Dispatch orchestration, channel adapters, and outbound provider

- [Dispatcher](https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Services/DispatcherService.cs): orchestrator · Coordinates routing to one or more dispatchers · `MessengerApi.Services/DispatcherService.cs`
- [Dispatch Options](https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Services/Configuration/DispatchOptions.cs): config model · Typed settings controlling dispatch behavior · `MessengerApi.Services/Configuration/DispatchOptions.cs`
- [Service Config](https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Services/Configuration/AppConfig.cs): config model · Shared service configuration binding · `MessengerApi.Services/Configuration/AppConfig.cs`
- [Email Sender](https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Services/Dispatchers/EmailDispatcher.cs): dispatcher · Channel-specific email dispatch implementation · `MessengerApi.Services/Dispatchers/EmailDispatcher.cs`
- [Slack Sender](https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Services/Dispatchers/SlackDispatcher.cs): dispatcher · Channel-specific Slack dispatch implementation · `MessengerApi.Services/Dispatchers/SlackDispatcher.cs`
- [Dispatcher Base](https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Services/Dispatchers/DispatcherBase.cs): base adapter · Shared dispatcher contract and behavior · `MessengerApi.Services/Dispatchers/DispatcherBase.cs`
- [Network Provider](https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Services/Providers/NetworkProvider.cs): outbound client · Shared network boundary used by dispatchers · `MessengerApi.Services/Providers/NetworkProvider.cs`
- [Slack Payload](https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Services/Dispatchers/Structs/SlackStruct.cs): payload model · Slack-specific request shape · `MessengerApi.Services/Dispatchers/Structs/SlackStruct.cs`

### Business

Core message and user models

- [Message Model](https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Business/Models/MessageModel.cs): domain model · Core message object passed through the system · `MessengerApi.Business/Models/MessageModel.cs`
- [User Model](https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Business/Models/UserModel.cs): domain model · Represents the message sender or customer · `MessengerApi.Business/Models/UserModel.cs`
- [Model Base](https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.Business/Models/ModelBase.cs): domain base · Shared domain model fields · `MessengerApi.Business/Models/ModelBase.cs`

### DAL

Firestore-backed persistence layer

- [Message Repo](https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.DAL/Repository/MessageRepository.cs): repository · Persistence access for message records · `MessengerApi.DAL/Repository/MessageRepository.cs`
- [Repository Base](https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.DAL/Repository/RepositoryBase.cs): repository base · Common repository behavior · `MessengerApi.DAL/Repository/RepositoryBase.cs`
- [Data Context](https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.DAL/DataContext.cs): db context · Firestore-backed data access context · `MessengerApi.DAL/DataContext.cs`
- [Firestore Config](https://github.com/lecarvalho/messenger-api/blob/master/MessengerApi.DAL/Configuration/FirestoreConfig.cs): config model · Typed Firestore connection settings · `MessengerApi.DAL/Configuration/FirestoreConfig.cs`

### Runtime / Ops

Containerization and deployment support

- [Container Ops](https://github.com/lecarvalho/messenger-api/tree/master/Dockerfile): deployment · Docker and build/push scripts for runtime delivery · `Dockerfile`

### Other components

- **Caller**: external client · Sends message requests to the REST API
- **Firestore**: external datastore · Backing persistence store
- **Channels**: external service · Outbound email and Slack endpoints

## Connections

- Caller → Message API: HTTP request · Incoming message submission
- Message API → Bootstrap: uses host · Controller is activated through ASP.NET Core bootstrapping
- Message API → Message Model: maps to · Request payload becomes a domain message
- Message API → Dispatcher: invokes · Delegates dispatch decisions to application service
- Bootstrap → App Config: loads · Bootstrapping reads runtime configuration
- Dispatcher → Dispatch Options: binds · Uses typed dispatch settings
- Dispatcher → Service Config: binds · Consumes shared service configuration
- Dispatcher → Email Sender: routes to · Can invoke email channel
- Dispatcher → Slack Sender: routes to · Can invoke Slack channel
- Email Sender → Dispatcher Base: extends · Shares adapter behavior
- Slack Sender → Dispatcher Base: extends · Shares adapter behavior
- Email Sender → Network Provider: sends via · Uses shared outbound communication layer
- Slack Sender → Network Provider: sends via · Uses shared outbound communication layer
- Slack Sender → Slack Payload: formats · Builds Slack-specific payloads
- Dispatcher → Message Repo: persists · May store message state or history
- Message Repo → Repository Base: extends · Shares repository behavior
- Message Repo → Data Context: uses · Repository reads and writes through context
- Data Context → Firestore Config: binds · Uses Firestore settings
- Data Context → Firestore: stores in · Persists data in Firestore
- Network Provider → Channels: calls · Outbound integration to external messaging services
- Container Ops → Bootstrap: packages · Container image runs the web host
