# ivanpaulovich/fluentmediator architecture

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

- Interactive diagram: https://gitdiagram.com/ivanpaulovich/fluentmediator
- Repository: https://github.com/ivanpaulovich/fluentmediator

## Overview

This project is a mediator pattern library for .NET – FluentMediator – which aims to provide loosely coupled communication between components, particularly used in CQRS or event-driven applications. Based on the file tree and README, the project is composed of multiple layers and components, including the core library (the mediator implementations and pipelines), integration components (Microsoft dependency injection extensions), sample applications that demonstrate its usage, and tests verifying the functionality.

##### Main components
- Core Mediator Library: Represented by the files in the “src/FluentMediator” folder. This includes key interfaces (like IMediator, IPipelineProvider, etc.) and concrete implementations (e.g., Mediator, PipelineProvider, PipelineBuilder). In the pipelines folder, you have both synchronous and asynchronous pipeline implementations, as well as variants for cancellable pipelines.
- Pipeline Components: These include various pipeline types (Pipeline, PipelineAsync, CancellablePipelineAsync) along with their supporting interfaces, behaviors, and collections. These components implement the execution flow once a mediator request is issued.
- Integration Extensions: Found in “src/FluentMediator.Microsoft.Extensions.DependencyInjection”. These files link the mediator’s functionality with .NET Core’s dependency injection system, thus enabling easy setup in an ASP.NET Core application.
- Sample Applications: Under the “samples” directory, you see sample projects – one for an ASP.NET Core based Web API and another for a Simple Console App. These provide usage examples through different application types, illustrating how the mediator is injected and used.
- Tests: Both unit tests and integration samples are provided in “test” and “samples”, verifying the mediator’s behavior (like sending and publishing requests, executing pipelines, etc.).

##### Relationships and interactions
- The Mediator (IMediator interface and its implementation) is the central hub through which requests are sent and published. It routes these to the appropriate pipeline.
- Pipelines break down the handling of a request into steps (calls to handlers) and they are built using specific pipeline builders (PipelineBuilder.cs, etc.). The control flow is designed to execute a series of method calls.
- Consumers (such as controllers in the ASP.NET Core sample or the console application handlers) inject and call into the mediator.
- The Integration Extensions enable the mediator to be integrated into the dependency injection framework. This illustrates the dependency inversion and improves testability.
- Unit tests ensure that each of these layers and their interactions (including the registration of pipelines and handlers) work as expected.

##### Architectural patterns and design principles
- Mediator Pattern: This is the core design pattern behind FluentMediator, decoupling sender and receiver.
- Pipeline/Chain of Responsibility: The library encapsulates business logic into pipelines where each step in the handling process can be chained together.
- Dependency Injection: Especially with the integration extension package, the design shows strong adherence to inversion of control principles, easing integration in .NET Core projects.
- Modularity: The project is modularized into core functionality, pipeline implementations, and integration-specific code, which promotes separation of concerns.

##### Relevant technologies and libraries
- .NET Framework / .NET Core (as it shows integration samples for ASP.NET Core).
- Microsoft.Extensions.DependencyInjection: Used for DI integration.
- Unit testing frameworks in the “test” folder (likely xUnit, NUnit, or MSTest).
- Azure Pipelines configuration files indicate continuous integration setup.

- Clear labels for every component, such as “Mediator Core”, “Pipeline (Sync/Async/Cancellable)”, “Integration Extensions”, “ASP.NET Core WebAPI”, “Console App Sample”, “Unit Tests”.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Applications Subgraph
    subgraph "Client Applications"
        Sample1("ASP.NET Core WebAPI Sample"):::sample
        Sample2("Console App Sample"):::sample
        Test("Unit Tests"):::test
    end

    %% Mediator Core Component
    Mediator("Mediator Core (Mediator Pattern)"):::core

    %% Pipeline Components
    Sync("Synchronous Pipeline"):::pipeline
    Async("Asynchronous Pipeline"):::pipeline
    Cancellable("Cancellable Async Pipeline"):::pipeline
    Behaviors("Pipeline Behaviors (Chain-of-Responsibility)"):::pipeline

    %% Integration Extensions
    Integration("Integration Extensions (DI)"):::integration

    %% Connections from Clients to Mediator
    Sample1 -->|"calls"| Mediator
    Sample2 -->|"calls"| Mediator
    Test -->|"tests"| Mediator

    %% Integration registers Mediator
    Integration -->|"registers"| Mediator

    %% Mediator builds Pipelines and applies Behaviors
    Mediator -->|"builds_sync"| Sync
    Mediator -->|"builds_async"| Async
    Mediator -->|"builds_cancellable"| Cancellable
    Mediator -->|"chains"| Behaviors

    %% Click Events
    click Mediator "https://github.com/ivanpaulovich/fluentmediator/tree/master/src/FluentMediator"
    click Sync "https://github.com/ivanpaulovich/fluentmediator/tree/master/src/FluentMediator/Pipelines/Pipeline"
    click Async "https://github.com/ivanpaulovich/fluentmediator/tree/master/src/FluentMediator/Pipelines/PipelineAsync"
    click Cancellable "https://github.com/ivanpaulovich/fluentmediator/tree/master/src/FluentMediator/Pipelines/CancellablePipelineAsync"
    click Behaviors "https://github.com/ivanpaulovich/fluentmediator/tree/master/src/FluentMediator/Pipelines"
    click Integration "https://github.com/ivanpaulovich/fluentmediator/blob/master/src/FluentMediator.Microsoft.Extensions.DependencyInjection"
    click Sample1 "https://github.com/ivanpaulovich/fluentmediator/tree/master/samples/AspNetCore"
    click Sample2 "https://github.com/ivanpaulovich/fluentmediator/tree/master/samples/SimpleConsoleApp"
    click Test "https://github.com/ivanpaulovich/fluentmediator/tree/master/test/UnitTests"

    %% Styles
    classDef core fill:#B3E5FC,stroke:#0288D1,stroke-width:2px;
    classDef pipeline fill:#C8E6C9,stroke:#388E3C,stroke-width:2px;
    classDef integration fill:#FFECB3,stroke:#FFA000,stroke-width:2px;
    classDef sample fill:#D1C4E9,stroke:#7E57C2,stroke-width:2px;
    classDef test fill:#FFCDD2,stroke:#C62828,stroke-width:2px;
```
