# srrickgrimes/modularmonolith architecture

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

- Interactive diagram: https://gitdiagram.com/srrickgrimes/modularmonolith
- Repository: https://github.com/srrickgrimes/modularmonolith

## Overview

- Host (Monolith) Application:
- ASP.NET Core Web API – represents the main server (for instance, the “Server” project in “Monolith” or “MonolithTemplate”).
- CrossCuttingConcerns Library – containing common interfaces (like IModuleInstaller) and shared services.
- Module(s):
- Each module is composed of several layers:
 Application Layer – encapsulates business use case logic (e.g., IApplication, ServiceExtensions, and Validators).
 Contracts Layer – defines data transfer objects (DTOs) and query/command interfaces.
 Domain Layer – contains core business entities (e.g., Message entity).
 EndPoints Layer – defines the API endpoints (e.g., HelloWorld endpoint) that expose module functionality.
 Infrastructure Layer – includes integration handlers (e.g., GetMessageQueryHandler) and any persistence-related implementations.
 Module Installer – responsible for bootstrapping the module (registering services, etc.) into the host application.
- Shared or External Technologies:
- ASP.NET Core
- MediatR (for in-process messaging)
- FastEndpoints (for creating fast and minimal endpoints)
- FluentValidation (for validating requests and commands)
- Ardalis Result (for implementing the Result pattern)

##### Relationships and interactions
- Within each module, illustrate how the EndPoints layer calls the Application layer. Then show that the Application layer interacts with the Domain layer (for core business logic) and with the Infrastructure layer (for integrations or persistence).
- That the Contracts layer is used as a communication boundary between modules and possibly with external consumers. This layer defines DTOs and queries that flow between endpoints and application logic.
- Dependency from the Host’s CrossCuttingConcerns into the modules, showing how shared interfaces, such as IModuleInstaller, facilitate the integration.

##### Architectural patterns and design principles
- Clean Architecture: Demonstrate the layered separation (presentation, application, domain, and infrastructure) by grouping the module components by their function.
- Modular Monolith: Explicitly represent that the system is composed of independently installable modules plugged into the host application. Emphasize the role of the module installer in automatically wiring up the module’s services.
- Use Dependency Injection (DI): Indicate how the host automatically registers and loads module components via DI.
- Consistent naming conventions: As described in the README, show that namespaces and naming between Host and modules are maintained consistently.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Host Application
    subgraph "Host Application"
        A["Host Web API"]:::host
        B["Cross-Cutting Concerns"]:::host
    end

    %% Module: Module1
    subgraph "Module: Module1"
        C["Module – EndPoints"]:::module
        D["Module – Contracts"]:::module
        E["Module – Application"]:::module
        F["Module – Domain"]:::module
        G["Module – Infrastructure"]:::module
        H["Module Installer"]:::module
    end

    %% External Technologies (Annotations)
    I["ASP.NET Core<br>MediatR<br>FastEndpoints<br>FluentValidation<br>Ardalis Result"]:::external

    %% Connections between Host and Module
    A -->|"loads"| H
    B -->|"provides services"| H

    %% Module Internal Flow
    H -->|"bootstraps"| C
    H -->|"bootstraps"| E

    C -->|"calls"| D
    C -->|"calls"| E
    D -->|"defines-DTO-boundary"| E
    E -->|"executes-business-logic"| F
    E -->|"triggers integration"| G

    %% Link External Technologies to Host Application
    I --- A

    %% Click Events
    click A "https://github.com/srrickgrimes/modularmonolith/tree/main/Monolith/MonolithTemplate/Server"
    click B "https://github.com/srrickgrimes/modularmonolith/blob/main/Monolith/MonolithTemplate/Server.CrossCuttingConcerns/Interfaces/IModuleInstaller.cs"
    click C "https://github.com/srrickgrimes/modularmonolith/blob/main/Module/Content/Server.Module1.EndPoints"
    click D "https://github.com/srrickgrimes/modularmonolith/blob/main/Module/Content/Server.Module1.Contracts"
    click E "https://github.com/srrickgrimes/modularmonolith/blob/main/Module/Content/Server.Module1.Application"
    click F "https://github.com/srrickgrimes/modularmonolith/blob/main/Module/Content/Server.Module1.Domain"
    click G "https://github.com/srrickgrimes/modularmonolith/blob/main/Module/Content/Server.Module1.Infrastructure"
    click H "https://github.com/srrickgrimes/modularmonolith/blob/main/Module/Content/Server.Module1.Module/ModuleInstaller.cs"

    %% Styles
    classDef host fill:#ffcc99,stroke:#d35400,stroke-width:2px
    classDef module fill:#aed6f1,stroke:#2874a6,stroke-width:2px
    classDef external fill:#d5f5e3,stroke:#28b463,stroke-width:2px
```
