# klzgrad/forwardproxy architecture

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

- Interactive diagram: https://gitdiagram.com/klzgrad/forwardproxy
- Repository: https://github.com/klzgrad/forwardproxy

## Overview

##### Main Components

a) Core Components:
- Caddy Web Server (as the host platform)
- Forward Proxy Module (main handler)
- Authentication System
- ACL (Access Control List) Manager
- Probe Resistance System
- PAC File Generator
- HTTP Client Handler

b) External Interfaces:
- Client Connections (HTTP/1.1 and HTTP/2)
- Upstream Proxy Connection (optional)
- Target Websites/Services

**┌─ Client Layer ─────────────────────────┐**
- Web Browsers                         │
- Operating Systems                    │
- Mobile Devices                       │
- ┬────────────────────┘
- ↓
**┌─ Proxy Entry Layer ──────────────────────────────────┐**
- ┌─ Probe Resistance Layer ─┐                         │
- Secret Link Handler    │                         │
- Mimicry System        │                         │
- ┘                         │
- ┌─ Authentication Layer ──┐                         │
- Basic Auth Handler    │                         │
- ┘                         │
- ┬────────────────────────────────┘
- ↓
**┌─ Core Processing Layer ────────────────────────────┐**
- ┌─ ACL Manager ─────┐  ┌─ Privacy Controls ──────┐ │
- IP Rules        │  │ - IP Hiding            │ │
- Domain Rules    │  │ - Via Header Hiding    │ │
- Subnet Rules    │  └──────────────────────┘ │
- ┘                           │
- ┌─ PAC File Server ─┐  ┌─ HTTP Client ────────┐ │
- Auto-Config     │  │ - Connection Pool    │ │
- Dynamic Gen     │  │ - Timeout Handler    │ │
- ┘  └──────────────────────┘ │
- ┬────────────────────────────┘
- ↓
**┌─ Output Layer ──────────────────────────────────┐**
- ┌─ Direct Connection ┐  ┌─ Upstream Proxy ────┐ │
- Target Websites  │  │ - Optional Chain    │ │
- ┘  └──────────────────────┘ │
- ┘

##### Important Flows to Highlight

a) Primary Request Flow:
- Client → Probe Resistance → Auth → ACL → HTTP Client → Target

b) PAC File Flow:
- Client → PAC Request → Dynamic Generation → Response

c) Upstream Proxy Flow:
- HTTP Client → Upstream Proxy → Target

##### Additional Elements

- Configuration endpoints
- Monitoring/logging points
- Security boundaries

##### Technical Details

- Supported protocols (HTTP/1.1, HTTP/2)
- Port specifications
- Authentication methods
- ACL rule types
- Timeout configurations

Remember to maintain a balance between detail and clarity, focusing on the key architectural components while providing enough technical detail to understand the system's operation.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph CL[Client Layer]
        WB[Web Browsers]
        OS[Operating Systems]
        MD[Mobile Devices]
    end

    %% Proxy Entry Layer
    subgraph PEL[Proxy Entry Layer]
        subgraph PRL[Probe Resistance Layer]
            SLH[Secret Link Handler]
            MS[Mimicry System]
        end
        
        subgraph AL[Authentication Layer]
            BAH[Basic Auth Handler]
        end
    end

    %% Core Processing Layer
    subgraph CPL[Core Processing Layer]
        subgraph ACLM[ACL Manager]
            IPR[IP Rules]
            DR[Domain Rules]
            SR[Subnet Rules]
        end
        
        subgraph PC[Privacy Controls]
            IPH[IP Hiding]
            VHH[Via Header Hiding]
        end
        
        subgraph PFS[PAC File Server]
            AC[Auto-Config]
            DG[Dynamic Generation]
        end
        
        subgraph HC[HTTP Client]
            CP[Connection Pool]
            TH[Timeout Handler]
        end

        FPM[Forward Proxy Module]
    end

    %% Output Layer
    subgraph OL[Output Layer]
        DC[Direct Connection]
        UP[Upstream Proxy]
    end

    %% Connections
    WB & OS & MD --> SLH
    SLH --> BAH
    BAH --> FPM
    FPM --> ACLM
    ACLM --> PC
    PC --> HC
    HC --> DC
    HC --> UP
    DC & UP --> TW[Target Websites]

    %% Click Events
    click FPM "https://github.com/klzgrad/forwardproxy/blob/naive/forwardproxy.go"
    click ACLM "https://github.com/klzgrad/forwardproxy/blob/naive/acl.go"
    click HC "https://github.com/klzgrad/forwardproxy/blob/naive/httpclient/httpclient.go"

    %% Styling
    classDef client fill:#a8d1ff
    classDef security fill:#90EE90
    classDef processing fill:#FFE5B4
    classDef critical fill:#FFB6C1
    classDef optional fill:#D3D3D3

    class WB,OS,MD client
    class SLH,BAH,ACLM security
    class FPM,PC,PFS,HC processing
    class DC,CP,TH critical
    class UP,AC,DG optional

    %% Legend
    subgraph Legend
        C1[Client Components]:::client
        S1[Security Components]:::security
        P1[Processing Components]:::processing
        CR1[Critical Components]:::critical
        O1[Optional Components]:::optional
    end
```
