# altmann/fluentresults architecture

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

- Interactive diagram: https://gitdiagram.com/altmann/fluentresults
- Repository: https://github.com/altmann/fluentresults

## Overview

##### Project Type and Purpose
- This is an open‑source .NET library (FluentResults) plus several sample applications and test projects.
- The core library implements a Result container pattern for success/failure.
- There are two official extensions (ASP.NET Core integration and FluentAssertions integration), example apps (MediatR, WebHost, Domain‑Driven Design, Hangfire, WebController) and unit/integration tests.

##### Directory‑Level Architecture Analysis
- **Core Library ("FluentResults")**
- src/FluentResults: core types (Result, Result<T>, Reasons, Factories, Logging, Settings, Extensions).
- **Extensions**
- src/FluentResults.Extensions.AspNetCore: maps Result to ASP.NET Core IActionResult.
- src/FluentResults.Extensions.FluentAssertions: Assertion helpers for FluentAssertions.
- **Sample Applications**
- src/FluentResults.Samples.MediatR: Razor Pages + MediatR pipeline + validation behavior + handlers.
- src/FluentResults.Samples.WebHost: ASP.NET Core controllers demonstrating custom EndpointProfile.
- src/FluentResults.Samples/DomainDrivenDesign: DDD command/handler sample.
- src/FluentResults.Samples/HangfireJobs: background job using Result.
- src/FluentResults.Samples/WebController: Web API controller + Result→DTO mapping.
- **Tests**
- src/FluentResults.Test: core library unit tests.
- src/FluentResults.Extensions.FluentAssertions.Test: tests for the FluentAssertions extension.

##### Key Components
a. **FluentResults Core**
- Packages: FluentResults.dll targeting .NET Standard.
- Modules: ResultBase, Result<T>, IReason/IError/ISuccess, factories, settings, logging interfaces.
b. **Extension Modules**
- AspNetCore extension: Result→ActionResult transformer, endpoint profiles.
- FluentAssertions extension: custom assertion operators.
c. **Sample Apps**
- MediatR sample:
- Pages/UI layer (Razor Pages)
- MediatR pipeline behaviors (validation)
- Command & Query handlers
- Uses FluentResults core and returns Result from handlers
- WebHost sample:
- ASP.NET Core Controllers
- Custom EndpointProfile injection
- DDD, Hangfire, WebController: simple domain handlers or controllers returning Results.
d. **External Services & Frameworks**
- ASP.NET Core WebHost
- MediatR library
- Hangfire
- FluentAssertions
e. **Test Projects**
- Core library tests
- Extension tests

##### Relationships and Data Flows
- All sample apps & tests → FluentResults.Core
- AspNetCore sample → FluentResults.Extensions.AspNetCore → FluentResults.Core
- Tests → corresponding projects (core or extension)
- FluentAssertions tests → FluentAssertions extension → FluentResults.Core
- **Runtime Flow (e.g. ASP.NET Core sample)**:
HTTP Request → Controller → calls domain/service → returns Result → AspNetCoreResultTransformer → IActionResult → HTTP Response
- **MediatR Flow**:
UI Page → MediatR Request → ValidationPipelineBehavior → Handler returns Result → Razor Page displays Result

##### Architectural Patterns & Principles
- **Separation of Concerns**: Core library is independent of hosting technology.
- **Extensibility via Extensions**: ASP.NET Core and FluentAssertions support added by separate NuGet packages.
- **Sample‑driven documentation**: Multiple small apps demonstrate integration points.
- **Dependency Injection**: Extension profiles and loggers injected via Result.Setup or ASP.NET Core DI.
- **Fluent Interface**: chaining of methods (Ok, Fail, WithError, Map, Bind, Try, Log, etc.).

##### Checklist
- [ ] Core library module with sub‑packages (Results, Reasons, Logging, Settings).
- [ ] External frameworks (ASP.NET Core, MediatR, Hangfire, FluentAssertions).
- [ ] Optional zoom‑in callouts for critical flows (e.g., HTTP request → Result transformation).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Core Library
    subgraph "Core Library"
        direction TB
        FluentResultsCore["FluentResults Core\r\n(Result, Reasons, Factories,\r\nLogging, Settings, Extensions)"]:::core
    end

    %% Extensions
    subgraph "Extensions"
        direction TB
        AspNetCoreExt["ASP.NET Core Extension\r\n(Result→IActionResult)"]:::ext
        FluentAssertionsExt["FluentAssertions Extension\r\n(Assertion Helpers)"]:::ext
    end

    %% Sample Applications
    subgraph "Sample Applications"
        direction TB
        subgraph "MediatR Sample"
            direction TB
            MedPages["Razor Pages UI"]:::sample
            MedPipeline["ValidationPipelineBehavior"]:::sample
            MedHandlers["Command & Query Handlers"]:::sample
        end
        WebHostSample["WebHost Sample\r\nControllers & EndpointProfile"]:::sample
        DDDSample["Domain‑Driven Design Sample"]:::sample
        HangfireSample["Hangfire Jobs Sample"]:::sample
        WebControllerSample["WebController Sample"]:::sample
    end

    %% Tests
    subgraph "Tests"
        direction TB
        CoreTests["Core Library Tests"]:::test
        FAExtTests["FluentAssertions Extension Tests"]:::test
    end

    %% External Frameworks
    subgraph "External Frameworks"
        direction TB
        ASPNETCore["ASP.NET Core"]:::external
        MediatRLib["MediatR"]:::external
        HangfireLib["Hangfire"]:::external
        FluentAssertionsLib["FluentAssertions"]:::external
    end

    %% Dependencies
    %% References
    AspNetCoreExt -->|references| FluentResultsCore
    FluentAssertionsExt -->|references| FluentResultsCore

    MedPages -->|uses| MediatRLib
    MedPipeline -->|uses| MediatRLib
    MedHandlers -->|uses| FluentResultsCore
    MedPages -->|returns Result→| FluentResultsCore

    WebHostSample -->|references| ASPNETCore
    WebHostSample -->|transforms via| AspNetCoreExt

    DDDSample -->|uses| FluentResultsCore
    HangfireSample -->|uses| HangfireLib
    HangfireSample -->|returns| FluentResultsCore
    WebControllerSample -->|uses| FluentResultsCore
    WebControllerSample -->|transforms via| AspNetCoreExt

    CoreTests -->|tests| FluentResultsCore
    FAExtTests -->|tests| FluentAssertionsExt

    %% Runtime Flow Example for WebHost Sample
    ASPNETCore -->|HTTP Request| WebHostSample
    WebHostSample -->|calls domain/service| FluentResultsCore
    FluentResultsCore -->|Result| AspNetCoreExt
    AspNetCoreExt -.->|IActionResult| ASPNETCore

    %% Runtime Flow Example for MediatR Sample
    MedPages -->|renders UI| MedPipeline
    MedPipeline -->|invokes| MedHandlers
    MedHandlers -->|returns Result| MedPages

    %% Legend
    subgraph "Legend"
        direction TB
        Core["Core Library"]:::core
        Ext["Extensions"]:::ext
        Sample["Sample Apps"]:::sample
        Test["Test Projects"]:::test
        External["External Frameworks"]:::external
        style Core fill:#D0E8FF,stroke:#000
        style Ext fill:#DFFFD0,stroke:#000
        style Sample fill:#FFE8B0,stroke:#000
        style Test fill:#E0E0E0,stroke:#000
        style External fill:#F0D0FF,stroke:#000
    end

    %% Click Events
    click FluentResultsCore "https://github.com/altmann/fluentresults/tree/master/src/FluentResults"
    click AspNetCoreExt "https://github.com/altmann/fluentresults/blob/master/src/FluentResults.Extensions.AspNetCore/FluentResults.Extensions.AspNetCore.csproj"
    click FluentAssertionsExt "https://github.com/altmann/fluentresults/blob/master/src/FluentResults.Extensions.FluentAssertions/FluentResults.Extensions.FluentAssertions.csproj"
    click MedPages "https://github.com/altmann/fluentresults/blob/master/src/FluentResults.Samples.MediatR/Pages/Index.cshtml"
    click MedPipeline "https://github.com/altmann/fluentresults/blob/master/src/FluentResults.Samples.MediatR/MediatRLogic/PipelineBehaviors/ValidationPipelineBehavior.cs"
    click MedHandlers "https://github.com/altmann/fluentresults/blob/master/src/FluentResults.Samples.MediatR/MediatRLogic/Handlers/CommandWithResultHandler.cs"
    click WebHostSample "https://github.com/altmann/fluentresults/blob/master/src/FluentResults.Samples.WebHost/FluentResults.Samples.WebHost.csproj"
    click DDDSample "https://github.com/altmann/fluentresults/blob/master/src/FluentResults.Samples/DomainDrivenDesign/FluentResults.Samples.csproj"
    click HangfireSample "https://github.com/altmann/fluentresults/blob/master/src/FluentResults.Samples/HangfireJobs/CustomerJob.cs"
    click WebControllerSample "https://github.com/altmann/fluentresults/blob/master/src/FluentResults.Samples/WebController/CustomerController.cs"
    click CoreTests "https://github.com/altmann/fluentresults/blob/master/src/FluentResults.Test/FluentResults.Test.csproj"
    click FAExtTests "https://github.com/altmann/fluentresults/blob/master/src/FluentResults.Extensions.FluentAssertions.Test/FluentResults.Extensions.FluentAssertions.Test.csproj"

    %% Styles
    classDef core fill:#D0E8FF,stroke:#036,stroke-width:1px
    classDef ext fill:#DFFFD0,stroke:#292,stroke-width:1px
    classDef sample fill:#FFE8B0,stroke:#963,stroke-width:1px
    classDef test fill:#E0E0E0,stroke:#666,stroke-width:1px
    classDef external fill:#F0D0FF,stroke:#609,stroke-width:1px
```
