# martinothamar/mediator architecture

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

- Interactive diagram: https://gitdiagram.com/martinothamar/mediator
- Repository: https://github.com/martinothamar/mediator

## Overview

##### Main Components

a. Core Components:
- Mediator Implementation (Generated)
- Message Types System
- Handler System
- Pipeline System
- Publisher System
- Source Generator

b. Supporting Components:
- Dependency Injection Integration
- Diagnostics System
- Configuration System

**┌─ Application Layer ─────────────────────────────────────┐**
- Client Code (Controllers/Services)                      │

- Mediator Interface Layer ──────────────────────────────┤
- IMediator                ISender              IPublisher│

- Message Layer ──────────────────────────────────────┐ │
- ┌─────────────┐ ┌──────────────┐ ┌───────────────┐  │ │
- Requests  │ │  Commands    │ │  Notifications │  │ │
- IRequest<T> │ │ ICommand<T>  │ │ INotification │  │ │
- ┘ └──────────────┘ └───────────────┘  │ │

- Handler Layer ─────────────────────────────────────┤ │
- ┌─────────────┐ ┌──────────────┐ ┌───────────────┐ │ │
- Request      │ │Command       │ │Notification   │ │ │
- Handlers     │ │Handlers      │ │Handlers       │ │ │
- ┘ └──────────────┘ └───────────────┘ │ │

- Pipeline Layer ────────────────────────────────────┤ │
- ┌─────────────┐ ┌──────────────┐ ┌───────────────┐ │ │
- Pre-         │ │Pipeline      │ │Post-          │ │ │
- Processors   │ │Behaviors     │ │Processors     │ │ │
- ┘ └──────────────┘ └───────────────┘ │ │

- ┘ │

- Source Generator Layer ───────────────────────────────┤
- ┌─────────────┐ ┌──────────────┐ ┌───────────────┐   │
- Code         │ │Diagnostic    │ │DI             │   │
- Generation   │ │Analysis      │ │Registration   │   │
- ┘ └──────────────┘ └───────────────┘   │
- ┘

##### Flow Indicators

- Message flow from client through mediator to handlers
- Pipeline behavior execution chain
- Source generator output flow
- Dependency injection registration flow

##### Additional Details

Callouts for:
- Default configurations
- Performance characteristics
- AOT compatibility points
- Build-time vs runtime components

##### Notes Section

Notes about:
- Source generator implementation details
- Performance considerations
- Configuration options
- Diagnostic capabilities

Remember to emphasize the high-performance aspects and build-time validation capabilities that make this implementation unique compared to traditional mediator pattern implementations.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Application
        Client[Client Code]
    end

    subgraph Interface
        Mediator["IMediator"]:::interface
        Sender["ISender"]:::interface
        Publisher["IPublisher"]:::interface
    end

    subgraph Messages
        Message["IMessage"]:::message
        Request["IRequest"]:::message
        Command["ICommand"]:::message
        Query["IQuery"]:::message
        Notification["INotification"]:::message
        StreamMsg["IStreamMessage"]:::message
    end

    subgraph Handlers
        ReqHandler["IRequestHandler"]:::handler
        CmdHandler["ICommandHandler"]:::handler
        QueryHandler["IQueryHandler"]:::handler
        NotifHandler["INotificationHandler"]:::handler
        StreamHandler["IStreamRequestHandler"]:::handler
    end

    subgraph Pipeline
        PipeBehavior["IPipelineBehavior"]:::pipeline
        PreProcessor["MessagePreProcessor"]:::pipeline
        PostProcessor["MessagePostProcessor"]:::pipeline
        ExceptionHandler["MessageExceptionHandler"]:::pipeline
        StreamPipe["IStreamPipelineBehavior"]:::pipeline
    end

    subgraph Publishers
        ForeachPub["ForeachAwaitPublisher"]:::publisher
        TaskPub["TaskWhenAllPublisher"]:::publisher
    end

    %% Relationships
    Client --> Mediator
    Mediator --> Sender
    Mediator --> Publisher

    Message --> Request
    Message --> Command
    Message --> Query
    Message --> Notification
    Message --> StreamMsg

    Request --> ReqHandler
    Command --> CmdHandler
    Query --> QueryHandler
    Notification --> NotifHandler
    StreamMsg --> StreamHandler

    ReqHandler --> PipeBehavior
    CmdHandler --> PipeBehavior
    QueryHandler --> PipeBehavior
    NotifHandler --> PipeBehavior
    StreamHandler --> StreamPipe

    PipeBehavior --> PreProcessor
    PipeBehavior --> PostProcessor
    PipeBehavior --> ExceptionHandler

    Publisher --> ForeachPub
    Publisher --> TaskPub

    %% Styles
    classDef interface fill:#a8d1ff
    classDef message fill:#90EE90
    classDef handler fill:#FFB6C1
    classDef pipeline fill:#FFE4B5
    classDef publisher fill:#DDA0DD

    %% Click Events
    click Mediator "https://github.com/martinothamar/Mediator/blob/main/src/Mediator/IMediator.cs"
    click Message "https://github.com/martinothamar/Mediator/blob/main/src/Mediator/Messages/IMessage.cs"
    click Request "https://github.com/martinothamar/Mediator/blob/main/src/Mediator/Messages/IRequest.cs"
    click Command "https://github.com/martinothamar/Mediator/blob/main/src/Mediator/Messages/ICommand.cs"
    click Query "https://github.com/martinothamar/Mediator/blob/main/src/Mediator/Messages/IQuery.cs"
    click Notification "https://github.com/martinothamar/Mediator/blob/main/src/Mediator/Messages/INotification.cs"
    click ReqHandler "https://github.com/martinothamar/Mediator/blob/main/src/Mediator/Handlers/IRequestHandler.cs"
    click CmdHandler "https://github.com/martinothamar/Mediator/blob/main/src/Mediator/Handlers/ICommandHandler.cs"
    click QueryHandler "https://github.com/martinothamar/Mediator/blob/main/src/Mediator/Handlers/IQueryHandler.cs"
    click NotifHandler "https://github.com/martinothamar/Mediator/blob/main/src/Mediator/Handlers/INotificationHandler.cs"
    click PipeBehavior "https://github.com/martinothamar/Mediator/blob/main/src/Mediator/Pipeline/IPipelineBehavior.cs"
    click PreProcessor "https://github.com/martinothamar/Mediator/blob/main/src/Mediator/Pipeline/MessagePreProcessor.cs"
    click PostProcessor "https://github.com/martinothamar/Mediator/blob/main/src/Mediator/Pipeline/MessagePostProcessor.cs"
    click ExceptionHandler "https://github.com/martinothamar/Mediator/blob/main/src/Mediator/Pipeline/MessageExceptionHandler.cs"
    click ForeachPub "https://github.com/martinothamar/Mediator/blob/main/src/Mediator/Publishers/ForeachAwaitPublisher.cs"
    click TaskPub "https://github.com/martinothamar/Mediator/blob/main/src/Mediator/Publishers/TaskWhenAllPublisher.cs"
    click StreamMsg "https://github.com/martinothamar/Mediator/blob/main/src/Mediator/Messages/IStreamMessage.cs"
    click StreamHandler "https://github.com/martinothamar/Mediator/blob/main/src/Mediator/Handlers/IStreamRequestHandler.cs"
    click StreamPipe "https://github.com/martinothamar/Mediator/blob/main/src/Mediator/Pipeline/IStreamPipelineBehavior.cs"
```
