# go-resty/resty architecture

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

- Interactive diagram: https://gitdiagram.com/go-resty/resty
- Repository: https://github.com/go-resty/resty

## Overview

##### Main Components

a. Core Components:
- Client Component (represented by client.go)
- Request Handler (request.go)
- Response Handler (response.go)
- Transport Layer (transport.go and variants)
- Middleware System (middleware.go)
- Retry Mechanism (retry.go)
- Redirect Handler (redirect.go)

b. Supporting Components:
- Authentication System
- Cookie Management
- Certificate Management
- Proxy Management
- Debug/Trace System

**┌─────────────────────────────────────────────────────────────┐**
- Application Layer                        │
- (Where applications integrate with Resty Client)           │
- ┘
- ↕
**┌─────────────────────────────────────────────────────────────┐**
- Resty Client Layer                       │
- ┬─────────────────────┬────────────────────┤
- Request Builder│   Response Handler   │  Middleware Chain  │

- ┴─────────────────────┴────────────────────┘
- ↕
**┌─────────────────────────────────────────────────────────────┐**
- Transport Layer                           │
- ┬────────────────────┬──────────────────────┤
- HTTP Transport │  Retry Mechanism   │   Redirect Policy    │
- ┴────────────────────┴──────────────────────┘
- ↕
**┌─────────────────────────────────────────────────────────────┐**
- External Systems                          │
- (HTTP/HTTPS Servers, REST APIs, etc.)                │
- ┘

##### Special Features

- TLS/Certificate handling
- Authentication methods
- Retry policies
- Middleware hooks
- Debug/Trace capabilities

##### Technical Details to Highlight

- HTTP/HTTPS support
- Multiple client instances
- Middleware chain flow
- Error handling paths
- Retry mechanisms
- Request/Response transformation

##### Integration Points

Connections to:
- Standard Go http.Client
- TLS configuration
- External authentication systems
- Proxy servers

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and classes
    classDef core fill:#2374f7,stroke:#000,stroke-width:2px,color:white
    classDef support fill:#4CAF50,stroke:#000,stroke-width:2px,color:white
    classDef external fill:#9E9E9E,stroke:#000,stroke-width:2px,color:white
    classDef security fill:#f44336,stroke:#000,stroke-width:2px,color:white

    %% Application Layer
    subgraph AppLayer["Application Layer"]
        APP[User Application]:::external
    end

    %% Resty Client Layer
    subgraph RestyLayer["Resty Client Layer"]
        Client["Client Component"]:::core
        MainEntry["Main Entry Point"]:::core
        ReqHandler["Request Builder"]:::core
        RespHandler["Response Handler"]:::core
        Middleware["Middleware Chain"]:::core
    end

    %% Transport Layer
    subgraph TransportLayer["Transport Layer"]
        Transport["Transport Manager"]:::core
        Retry["Retry Mechanism"]:::core
        Redirect["Redirect Handler"]:::core
    end

    %% Supporting Features
    subgraph SupportLayer["Supporting Features"]
        Auth["Authentication System"]:::security
        Debug["Debug/Trace System"]:::support
        Utils["Utility Components"]:::support
        ShellEscape["Shell Escaping"]:::support
    end

    %% External Systems
    subgraph ExternalSystems["External Systems"]
        HTTP["HTTP/HTTPS Servers"]:::external
        REST["REST APIs"]:::external
    end

    %% Connections
    APP --> Client
    Client --> MainEntry
    MainEntry --> ReqHandler
    MainEntry --> RespHandler
    ReqHandler --> Middleware
    Middleware --> Transport
    Transport --> Retry
    Transport --> Redirect
    Transport --> HTTP
    Transport --> REST
    Transport --> Auth
    Transport -.-> Debug
    Utils --> ReqHandler
    Utils --> RespHandler
    ShellEscape --> Utils

    %% Click events
    click Client "https://github.com/go-resty/resty/blob/v2/client.go"
    click ReqHandler "https://github.com/go-resty/resty/blob/v2/request.go"
    click RespHandler "https://github.com/go-resty/resty/blob/v2/response.go"
    click Transport "https://github.com/go-resty/resty/blob/v2/transport.go"
    click Middleware "https://github.com/go-resty/resty/blob/v2/middleware.go"
    click Retry "https://github.com/go-resty/resty/blob/v2/retry.go"
    click Redirect "https://github.com/go-resty/resty/blob/v2/redirect.go"
    click Auth "https://github.com/go-resty/resty/blob/v2/digest.go"
    click Debug "https://github.com/go-resty/resty/blob/v2/trace.go"
    click MainEntry "https://github.com/go-resty/resty/blob/v2/resty.go"
    click Utils "https://github.com/go-resty/resty/blob/v2/util.go"
    click ShellEscape "https://github.com/go-resty/resty/blob/v2/shellescape/shellescape.go"

    %% Legend
    subgraph Legend
        CoreComp["Core Component"]:::core
        SupportComp["Supporting Feature"]:::support
        SecurityComp["Security Component"]:::security
        ExternalComp["External System"]:::external
    end
```
