# respawnsive/apizr architecture

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

- Interactive diagram: https://gitdiagram.com/respawnsive/apizr
- Repository: https://github.com/respawnsive/apizr

## Overview

##### Main Building Blocks and External Dependencies
a. API Interface Layer – at the top layer, the user defines their API contracts (using attributes like [Get], [Post], etc.). These interfaces will later be implemented dynamically via Refit.
b. Apizr Manager / Facade – the central piece that clients interact with. It exposes methods (e.g., ExecuteAsync) to process API calls.
c. Core Handlers – chained components that process the API request. This chain includes:
- Caching Handlers (with integrations for Akavache, MonkeyCache, or MS Extensions Caching)
- Resilience / Retry Handler – built using Polly (and optionally Microsoft Resilience) that provides retries, circuit breakers, and other error handling mechanisms.
- Logging Handler – that logs http traffic (via Microsoft.Extensions.Logging) and traces requests.
- Connectivity Handler – optionally checking the network connectivity before executing the API call.
- Mapping Handler – which uses tools like AutoMapper or Mapster to map data transfer objects to domain models and vice versa.
- (Optionally) Additional handlers for file transfers or priority management (using Fusillade, MediatR, etc.)
d. Apizr Builder – the “static” or “extended” registration components that configure and compose the above pieces either via static builder methods or by using the DI container extension (AddApizrManagerFor<T>, etc.).
e. External Libraries – key dependencies such as Refit, Polly, Microsoft.Extensions.Logging, and other integration packages.

##### Relationships & Flow
- The consumer calls the Apizr Manager.
- The manager (configured via ApizrBuilder) processes the call: first the request goes through the resilience pipeline which applies retry/cancellation/error handling policies.
- Next, the caching handler determines whether to serve a cached result or fetch a new one.
- Concurrently, logging and connectivity handlers are engaged, wrapping the actual HTTP call.
- The actual HTTP request is dispatched via the Refit-generated implementation.
- On response receipt, the mapping handler may perform any necessary transformations, and the result is returned back up the chain.
– Use annotations to show how the DI container (IServiceCollection) registers and composes the various integration pieces.

##### Details
– Make sure key patterns such as “decorator” or “chain-of-responsibility” are highlighted in the design.
– Explicitly annotate integration points (logging, caching, resilience) with the names of external packages (Polly, Akavache, MediatR, Fusillade, etc.).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Header Label
    title("High-Level Architecture for Apizr")

    %% Top Layer: Client/Presentation
    Client("Client/Consumer"):::client

    %% DI Container / Configuration Layer
    subgraph "DI Container/Configuration"
        Builder("Apizr Builder"):::builder
    end

    %% Facade/Manager Layer
    subgraph "Facade/Manager Layer"
        Manager("Apizr Manager / Facade"):::facade
    end

    %% Handler Pipeline Layer
    subgraph "Handler Pipeline"
        Resilience("Resilience_(Polly/Microsoft_Resilience)"):::resilience

        subgraph "Caching Handlers"
            NodeAkavache("Akavache Cache Handler"):::caching
            NodeMonkey("MonkeyCache Handler"):::caching
            NodeDistributed("Distributed Cache Handler"):::caching
            NodeInMemory("InMemory Cache Handler"):::caching
        end

        subgraph "Logging Handlers"
            LogTracer("Extended HTTP Tracer Handler"):::logging
            LogBuilder("Extended HTTP Handler Builder"):::logging
        end

        Connectivity("Connectivity Handler"):::connectivity
        Optional("File Transfer Manager_/_Optional Handlers"):::optional

        subgraph "Mapping Handlers"
            VoidMapping("Void Mapping Handler"):::mapping
            AutoMapping("AutoMapper Mapping Handler"):::mapping
            MapsterMapping("Mapster Mapping Handler"):::mapping
        end
    end

    %% External API Implementation Layer
    subgraph "External API Implementation"
        Refit("API Interface (Refit)"):::api
    end

    %% Connections / Flow
    Client -->|"calls"| Manager
    Builder -->|"configure"| Manager
    Manager -->|"execute_async"| Resilience
    Resilience -->|"cache_chain"| NodeAkavache
    NodeAkavache -->|"cache_chain"| NodeMonkey
    NodeMonkey -->|"cache_chain"| NodeDistributed
    NodeDistributed -->|"cache_chain"| NodeInMemory
    NodeInMemory -->|"to_logging"| LogTracer
    LogTracer -->|"to_logging"| LogBuilder
    LogBuilder -->|"to_connectivity"| Connectivity
    Connectivity -->|"to_optional"| Optional
    Optional -->|"to_mapping"| VoidMapping
    VoidMapping -->|"to_mapping"| AutoMapping
    AutoMapping -->|"to_mapping"| MapsterMapping
    MapsterMapping -->|"http_call"| Refit
    Refit -->|"response"| Manager
    Refit -->|"cache_update"| NodeInMemory

    %% Styles
    classDef client fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef facade fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef resilience fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef caching fill:#FFFFE0,stroke:#000,stroke-width:2px;
    classDef logging fill:#E0FFFF,stroke:#000,stroke-width:2px;
    classDef connectivity fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef optional fill:#FFDAB9,stroke:#000,stroke-width:2px;
    classDef mapping fill:#E6E6FA,stroke:#000,stroke-width:2px;
    classDef api fill:#F5DEB3,stroke:#000,stroke-width:2px;
    classDef builder fill:#DDA0DD,stroke:#000,stroke-width:2px;

    %% Click Events
    click Refit "https://github.com/respawnsive/apizr/tree/master/Apizr/Tests/Apizr.Tests/Apis/"
    click Manager "https://github.com/respawnsive/apizr/blob/master/Apizr/Src/Apizr/ApizrManager.cs"
    click NodeAkavache "https://github.com/respawnsive/apizr/blob/master/Apizr/Src/Caching/Apizr.Integrations.Akavache/AkavacheCacheHandler.cs"
    click NodeMonkey "https://github.com/respawnsive/apizr/blob/master/Apizr/Src/Caching/Apizr.Integrations.MonkeyCache/MonkeyCacheHandler.cs"
    click NodeDistributed "https://github.com/respawnsive/apizr/blob/master/Apizr/Src/Caching/Apizr.Extensions.Microsoft.Caching/DistributedCacheHandler.cs"
    click NodeInMemory "https://github.com/respawnsive/apizr/blob/master/Apizr/Src/Caching/Apizr.Extensions.Microsoft.Caching/InMemoryCacheHandler.cs"
    click Resilience "https://github.com/respawnsive/apizr/blob/master/Apizr/Src/Apizr/Resiliencing/ResilienceHttpMessageHandler.cs"
    click LogTracer "https://github.com/respawnsive/apizr/blob/master/Apizr/Src/Apizr/Logging/ExtendedHttpTracerHandler.cs"
    click LogBuilder "https://github.com/respawnsive/apizr/blob/master/Apizr/Src/Apizr/Logging/ExtendedHttpHandlerBuilder.cs"
    click Connectivity "https://github.com/respawnsive/apizr/blob/master/Apizr/Src/Apizr/Connecting/DefaultConnectivityHandler.cs"
    click VoidMapping "https://github.com/respawnsive/apizr/blob/master/Apizr/Src/Apizr/Mapping/VoidMappingHandler.cs"
    click AutoMapping "https://github.com/respawnsive/apizr/blob/master/Apizr/Src/Apizr/Mapping/Apizr.Integrations.AutoMapper/AutoMapperMappingHandler.cs"
    click MapsterMapping "https://github.com/respawnsive/apizr/blob/master/Apizr/Src/Apizr/Mapping/Apizr.Integrations.Mapster/MapsterMappingHandler.cs"
    click Optional "https://github.com/respawnsive/apizr/blob/master/Apizr/Src/Transferring/Apizr.Integrations.FileTransfer/Transferring/Managing/ApizrTransferManager.cs"
    click Builder "https://github.com/respawnsive/apizr/blob/master/Apizr/Src/Apizr/ApizrBuilder.cs"
```
