# lawrence-laz/generic-pipeline architecture

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

- Interactive diagram: https://gitdiagram.com/lawrence-laz/generic-pipeline
- Repository: https://github.com/lawrence-laz/generic-pipeline

## Overview

##### Project Type and Purpose
- This is a .NET class‐library (NuGet package) called “GenericPipeline” that implements a high-performance, dependency-free pipeline (chain of responsibility) builder supporting both sync and async execution.
- It provides interfaces (IRequest, IRequestHandler, IRequestHandlerAsync), a Pipeline builder, a set of built-in Behaviors (e.g., MediatorBehavior, SingleHandlerBehavior, UnhandledThrowingBehavior), extension methods for configuration and DI integration, plus examples, benchmarks, and tests.

##### File Structure Analysis
- **src/GenericPipeline**: Core library project
- Behaviors/…: Sync and async behaviors and their handler implementations
- Internal/…: low-level pipeline wiring & DI support (ServiceProviderExtensions, RequestHandlers)
- Pipeline.cs / PipelineAsync.cs: builder types for sync/async pipelines
- PipelineBehavior(Async).cs: behavior delegate definitions
- PipelineExtensions(Async).cs: fluent configuration APIs
- GenericPipeline.csproj, IRequest*.cs, Unit.cs, Exceptions.cs, Usings.cs
- **examples/**: Consumer applications demonstrating how to wire up and use the library (ExceptionHandling, FluentValidation, Mediator, Polly, Serilog)
- **test/**:
- GenericPipeline.Tests: unit tests covering behaviors, pipeline functionality
- GenericPipeline.Benchmarks: BenchmarkDotNet scenarios comparing performance vs. other libraries
- **.github/workflows/**: CI build and publish pipelines
- **readme.md, LICENSE.md, images/**: project description and assets

##### README Insights
- Emphasizes zero external dependencies, high performance (no allocations), support for DI and non-DI modes, sync/async behaviors, runtime behavior/handler changes.
- Benchmarks quantify per-invocation overhead vs. MediatR, PipelineNet, etc.

1. Core Interfaces
- IRequest<TResponse>
- IRequestHandler<TRequest,TResponse> / IRequestHandlerAsync
2. Pipeline Builder
- Pipeline<TRequest,TResponse> / PipelineAsync<TRequest,TResponse>
3. Behaviors (Chain Links)
- PipelineBehavior<TRequest,TResponse> / PipelineBehaviorAsync
- MediatorBehavior / MediatorBehaviorAsync
- SingleHandlerBehavior / …Async
- UnhandledThrowingBehavior / …Async
4. Internal Wiring
- RequestHandlers (method discovery/invocation)
- ServiceProviderExtensions (DI integration)
5. Extension Methods
- PipelineExtensions / PipelineExtensionsAsync for “UseBehavior”, “UseHandler”, “Send”
6. Consumer Layer
- Example applications or host project
- Dependency Injection container (optional)
7. CI/CD & Packaging
- GitHub Actions (Build, Publish)
- NuGet packaging

- Consumer invokes PipelineBuilder (Pipeline.Create or via DI)
- Builder assembles a linked list (chain) of Behavior delegates
- Send(request) flows through Behavior chain → eventually invokes IRequestHandler
- Behaviors call next() to propagate through chain
- Internal RequestHandlers resolve and invoke the correct handler(s)
- If DI is used, ServiceProviderExtensions integrate pipeline builder into Microsoft.Extensions.DependencyInjection
- CI/CD pipelines pick up src and push package to NuGet

c. Architectural Patterns
- Chain of Responsibility (pipeline of behaviors)
- Builder / Fluent API (PipelineExtensions)
- Strategy (handler lookup & invocation)
- Zero-allocation, high-performance focus

d. Key Technologies & Frameworks
- .NET 6+ / .NET Standard
- C# interfaces/generics/delegates
- BenchmarkDotNet (in test/benchmarks)
- xUnit or NUnit (unit tests)
- GitHub Actions for CI & CD

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Consumer Layer
    subgraph "Consumer Layer" 
        direction TB
        Ex1["ExceptionHandlingExample"]:::consumer
        Ex2["FluentValidationExample"]:::consumer
        Ex3["MediatorIntegrationExample"]:::consumer
        Ex4["RetryPolicyExample"]:::consumer
        Ex5["SerilogExamples"]:::consumer
    end

    %% Pipeline Builder
    subgraph "Pipeline Builder"
        direction TB
        Pipeline["Pipeline<TRequest,TResponse>"]:::builder
        PipelineAsync["PipelineAsync<TRequest,TResponse>"]:::builder
    end

    %% Behaviors Chain
    subgraph "Behaviors Chain"
        direction TB
        PB["PipelineBehavior<TRequest,TResponse>"]:::behaviors
        PBA["PipelineBehaviorAsync<TRequest,TResponse>"]:::behaviors
        MB["MediatorBehavior"]:::behaviors
        MBH["MediatorBehavior.Handlers"]:::behaviors
        MBA["MediatorBehaviorAsync"]:::behaviors
        MBAH["MediatorBehaviorAsync.Handlers"]:::behaviors
        SB["SingleHandlerBehavior"]:::behaviors
        SBA["SingleHandlerBehaviorAsync"]:::behaviors
        UB["UnhandledThrowingBehavior"]:::behaviors
        UBA["UnhandledThrowingBehaviorAsync"]:::behaviors
    end

    %% Internal & DI Integration
    subgraph "Internal & DI Integration"
        direction TB
        RH["RequestHandlers"]:::internal
        SPE["ServiceProviderExtensions"]:::internal
    end

    %% Extension Methods
    subgraph "Extension Methods"
        direction TB
        Ext["PipelineExtensions"]:::extensions
        ExtA["PipelineExtensionsAsync"]:::extensions
    end

    %% Core Interfaces & Supporting Types
    subgraph "Core Interfaces & Supporting Types"
        direction TB
        IRequest["IRequest<TResponse>"]:::coreInterfaces
        IRequestH["IRequestHandler<TRequest,TResponse>"]:::coreInterfaces
        IRequestHA["IRequestHandlerAsync<TRequest,TResponse>"]:::coreInterfaces
        Unit["Unit"]:::supporting
        Exceptions["Exceptions"]:::supporting
        Usings["Usings"]:::supporting
    end

    %% CI/CD & Packaging
    subgraph "CI/CD & Packaging"
        direction TB
        Build["GitHub Actions Build"]:::cicd
        Pub1["Publish GenericPipeline"]:::cicd
        Pub2["Publish DI Extensions"]:::cicd
        CSP["GenericPipeline.csproj"]:::cicd
    end

    %% Connections
    Ex1 -->|uses| Ext
    Ex2 -->|uses| ExtA
    Ex3 -->|invokes| SPE
    Ex4 -->|invokes| SPE
    Ex5 -->|invokes| SPE

    SPE -->|integrates| Ext
    SPE -->|integrates| ExtA

    Ext -->|builds| Pipeline
    ExtA -->|builds| PipelineAsync

    Pipeline -->|assembles| PB
    PipelineAsync -->|assembles| PBA

    PB --> MB --> MBH --> SB --> UB --> IRequestH
    PBA --> MBA --> MBAH --> SBA --> UBA --> IRequestHA

    UB -->|invokes| RH
    UBA -->|invokes| RH

    IRequestH -->|implements| IRequest
    IRequestHA -->|implements| IRequest

    PB -->|may throw| Exceptions
    PBA -->|may throw| Exceptions

    CSP -->|packaged by| Build
    Build -->|publishes| Pub1
    Build -->|publishes| Pub2

    %% Click Events
    click IRequest "https://github.com/lawrence-laz/generic-pipeline/blob/main/src/GenericPipeline/IRequest.cs"
    click IRequestH "https://github.com/lawrence-laz/generic-pipeline/blob/main/src/GenericPipeline/IRequestHandler.cs"
    click IRequestHA "https://github.com/lawrence-laz/generic-pipeline/blob/main/src/GenericPipeline/IRequestHandlerAsync.cs"
    click Pipeline "https://github.com/lawrence-laz/generic-pipeline/blob/main/src/GenericPipeline/Pipeline.cs"
    click PipelineAsync "https://github.com/lawrence-laz/generic-pipeline/blob/main/src/GenericPipeline/PipelineAsync.cs"
    click PB "https://github.com/lawrence-laz/generic-pipeline/blob/main/src/GenericPipeline/PipelineBehavior.cs"
    click PBA "https://github.com/lawrence-laz/generic-pipeline/blob/main/src/GenericPipeline/PipelineBehaviorAsync.cs"
    click MB "https://github.com/lawrence-laz/generic-pipeline/blob/main/src/GenericPipeline/Behaviors/MediatorBehavior.cs"
    click MBH "https://github.com/lawrence-laz/generic-pipeline/blob/main/src/GenericPipeline/Behaviors/MediatorBehavior.Handlers.cs"
    click MBA "https://github.com/lawrence-laz/generic-pipeline/blob/main/src/GenericPipeline/Behaviors/MediatorBehaviorAsync.cs"
    click MBAH "https://github.com/lawrence-laz/generic-pipeline/blob/main/src/GenericPipeline/Behaviors/MediatorBehaviorAsync.Handlers.cs"
    click SB "https://github.com/lawrence-laz/generic-pipeline/blob/main/src/GenericPipeline/Behaviors/SingleHandlerBehavior.cs"
    click SBA "https://github.com/lawrence-laz/generic-pipeline/blob/main/src/GenericPipeline/Behaviors/SingleHandlerBehaviorAsync.cs"
    click UB "https://github.com/lawrence-laz/generic-pipeline/blob/main/src/GenericPipeline/Behaviors/UnhandledThrowingBehavior.cs"
    click UBA "https://github.com/lawrence-laz/generic-pipeline/blob/main/src/GenericPipeline/Behaviors/UnhandledThrowingBehaviorAsync.cs"
    click RH "https://github.com/lawrence-laz/generic-pipeline/blob/main/src/GenericPipeline/Internal/RequestHandlers.cs"
    click SPE "https://github.com/lawrence-laz/generic-pipeline/blob/main/src/GenericPipeline/Internal/ServiceProviderExtensions.cs"
    click Ext "https://github.com/lawrence-laz/generic-pipeline/blob/main/src/GenericPipeline/PipelineExtensions.cs"
    click ExtA "https://github.com/lawrence-laz/generic-pipeline/blob/main/src/GenericPipeline/PipelineExtensionsAsync.cs"
    click Unit "https://github.com/lawrence-laz/generic-pipeline/blob/main/src/GenericPipeline/Unit.cs"
    click Exceptions "https://github.com/lawrence-laz/generic-pipeline/blob/main/src/GenericPipeline/Exceptions.cs"
    click Usings "https://github.com/lawrence-laz/generic-pipeline/blob/main/src/GenericPipeline/Usings.cs"
    click Ex1 "https://github.com/lawrence-laz/generic-pipeline/blob/main/examples/ExceptionHandlingExamples/ExceptionHandlingExample.cs"
    click Ex2 "https://github.com/lawrence-laz/generic-pipeline/blob/main/examples/FluentValidationExamples/FluentValidationExample.cs"
    click Ex3 "https://github.com/lawrence-laz/generic-pipeline/blob/main/examples/Mediator/Program.cs"
    click Ex4 "https://github.com/lawrence-laz/generic-pipeline/blob/main/examples/PollyExamples/RetryPolicyExample.cs"
    click Ex5 "https://github.com/lawrence-laz/generic-pipeline/blob/main/examples/SerilogExamples/SerilogExamples.cs"

    %% Styles
    classDef coreInterfaces fill:#D0E6FF,stroke:#024770,color:#024770;
    classDef builder fill:#DFF2D8,stroke:#236128,color:#236128;
    classDef behaviors fill:#E8EFFF,stroke:#1B3A57,color:#1B3A57;
    classDef internal fill:#FFE8CC,stroke:#7A4A00,color:#7A4A00;
    classDef extensions fill:#FFF4E5,stroke:#996E00,color:#996E00;
    classDef supporting fill:#F0F0F0,stroke:#888888,color:#555555;
    classDef consumer fill:#E2E2E2,stroke:#666666,color:#333333;
    classDef cicd fill:#EFEFEF,stroke:#AAAAAA,color:#444444;
```
