How lecarvalho/messenger-api works
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: DispatcherService.cs Dispatcher · MessageController.cs Message API · SlackDispatcher.cs Slack Sender · EmailDispatcher.cs Email Sender
Components 22
Web API
HTTP entrypoint and ASP.NET Core bootstrapping
- Message API · Main HTTP surface for message submission
MessengerApi.Webapi/Controllers/MessageController.cs - Bootstrap · Program and Startup configure the web host and DI
MessengerApi.Webapi/Program.cs - App Config · Deployment-time API configuration
MessengerApi.Webapi/appsettings.json
Services
Dispatch orchestration, channel adapters, and outbound provider
- Dispatcher · Coordinates routing to one or more dispatchers
MessengerApi.Services/DispatcherService.cs - Dispatch Options · Typed settings controlling dispatch behavior
MessengerApi.Services/Configuration/DispatchOptions.cs - Service Config · Shared service configuration binding
MessengerApi.Services/Configuration/AppConfig.cs - Email Sender · Channel-specific email dispatch implementation
MessengerApi.Services/Dispatchers/EmailDispatcher.cs - Slack Sender · Channel-specific Slack dispatch implementation
MessengerApi.Services/Dispatchers/SlackDispatcher.cs - Dispatcher Base · Shared dispatcher contract and behavior
MessengerApi.Services/Dispatchers/DispatcherBase.cs - Network Provider · Shared network boundary used by dispatchers
MessengerApi.Services/Providers/NetworkProvider.cs - Slack Payload · Slack-specific request shape
MessengerApi.Services/Dispatchers/Structs/SlackStruct.cs
Business
Core message and user models
- Message Model · Core message object passed through the system
MessengerApi.Business/Models/MessageModel.cs - User Model · Represents the message sender or customer
MessengerApi.Business/Models/UserModel.cs - Model Base · Shared domain model fields
MessengerApi.Business/Models/ModelBase.cs
DAL
Firestore-backed persistence layer
- Message Repo · Persistence access for message records
MessengerApi.DAL/Repository/MessageRepository.cs - Repository Base · Common repository behavior
MessengerApi.DAL/Repository/RepositoryBase.cs - Data Context · Firestore-backed data access context
MessengerApi.DAL/DataContext.cs - Firestore Config · Typed Firestore connection settings
MessengerApi.DAL/Configuration/FirestoreConfig.cs
Runtime / Ops
Containerization and deployment support
- Container Ops · Docker and build/push scripts for runtime delivery
Dockerfile
Other components
- Caller · Sends message requests to the REST API
- Firestore · Backing persistence store
- Channels · Outbound email and Slack endpoints
Connections 21
- 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