# ehsanfaridi92/refitwithpolly architecture

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

- Interactive diagram: https://gitdiagram.com/ehsanfaridi92/refitwithpolly
- Repository: https://github.com/ehsanfaridi92/refitwithpolly

## Overview

##### Main Components
- Application Entry Point: Highlight Program.cs, which bootstraps the application.
- Configuration Layer: Include a component for configuration, drawing from files such as appsettings.json and the Configuration folder (with ApiResourceConfiguration.cs and WaitAndRetryConfig.cs) that set up API resources and retry settings.
- HTTP Client Component (Refit):
- “Refit” folder components — notably ICharactersService.cs which defines the interface for HTTP operations.
- CharactersDecorator.cs which suggests additional layers (like logging or wrapping of HTTP call logic).
- Role of Refit in abstracting HTTP communication.
- Resilience and Policy Component (Polly):
- Mechanism for retry and circuit breaker policies that govern the HTTP calls.
- Authentication Handler:
- A dedicated Authentication Handler component (e.g., ApiResourceAuthenticationHandler.cs) in the Refit/AuthenticationHandler folder which manages authorization aspects for API requests.

##### Relationships and Interactions
- How the configuration layer feeds into setting up both the Refit HTTP client and Polly policies.
- Authentication Handler as an intermediary that intercepts or enriches outgoing HTTP requests with necessary authorization tokens or headers.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Clearly distinguish between configuration, HTTP request generation (Refit), and resiliency logic (Polly).
- Middleware/Interceptor Pattern: Emphasize the use of the Authentication Handler and CharactersDecorator as middleware shaping the outgoing/incoming request flow.

##### Relevant Technologies and Frameworks
- .NET Core: The underlying framework.
- Refit: For simplicity in consuming REST APIs.
- Polly: For implementing resilience strategies like retries and circuit breakers.
- Configuration files (appsettings.json) and custom configuration classes for API resource and policy settings.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Nodes
    P("Program.cs"):::entry
    subgraph "Initialization & Configuration Layer"
        AS("appsettings.json"):::config
        ARC("ApiResourceConfiguration.cs"):::config
        WRC("WaitAndRetryConfig.cs"):::config
    end
    subgraph "HTTP Client (Refit)"
        IChars("ICharactersService"):::http
        Decl("CharactersDecorator"):::http
        AuthHandler("ApiResourceAuthenticationHandler"):::auth
    end
    ExtAPI("External API"):::external

    %% Edges for configuration initialization
    P -->|"loads"| AS
    P -->|"loads"| ARC
    P -->|"loads"| WRC

    %% Edge for HTTP Client setup
    P -->|"setsUp"| IChars
    ARC -->|"configures"| IChars

    %% HTTP Client Component flow
    IChars -->|"decoratedBy"| Decl
    Decl -->|"authenticatedBy"| AuthHandler

    %% Resilience policy integration
    WRC -->|"policyConfig"| AuthHandler

    %% Outgoing API call
    AuthHandler -->|"callsAPIwithPolly"| ExtAPI

    %% Click Events
    click P "https://github.com/ehsanfaridi92/refitwithpolly/blob/master/Code/src/RefitWithPolly/Program.cs"
    click AS "https://github.com/ehsanfaridi92/refitwithpolly/blob/master/Code/src/RefitWithPolly/appsettings.json"
    click ARC "https://github.com/ehsanfaridi92/refitwithpolly/blob/master/Code/src/RefitWithPolly/Configuration/ApiResourceConfiguration.cs"
    click WRC "https://github.com/ehsanfaridi92/refitwithpolly/blob/master/Code/src/RefitWithPolly/Configuration/WaitAndRetryConfig.cs"
    click IChars "https://github.com/ehsanfaridi92/refitwithpolly/blob/master/Code/src/RefitWithPolly/Refit/ICharactersService.cs"
    click Decl "https://github.com/ehsanfaridi92/refitwithpolly/blob/master/Code/src/RefitWithPolly/Refit/CharactersDecorator.cs"
    click AuthHandler "https://github.com/ehsanfaridi92/refitwithpolly/blob/master/Code/src/RefitWithPolly/Refit/AuthenticationHandler/ApiResourceAuthenticationHandler.cs"

    %% Styles
    classDef entry fill:#f9d5e5,stroke:#d9534f,stroke-width:2px;
    classDef config fill:#d9edf7,stroke:#31708f,stroke-width:2px;
    classDef http fill:#dff0d8,stroke:#3c763d,stroke-width:2px;
    classDef auth fill:#fcf8e3,stroke:#8a6d3b,stroke-width:2px;
    classDef external fill:#eeeeee,stroke:#888888,stroke-width:2px;
```
