# hyperium/hyper architecture

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

- Interactive diagram: https://gitdiagram.com/hyperium/hyper
- Repository: https://github.com/hyperium/hyper

## Overview

##### Main Components

a. Client Component:
- HTTP/1 Connection Handler
- HTTP/2 Connection Handler
- Dispatch System

b. Server Component:
- HTTP/1 Connection Handler
- HTTP/2 Connection Handler
- Connection Management

c. Protocol Layer:
- H1 Protocol Implementation
- H2 Protocol Implementation
- Shared Protocol Traits

d. Body Management:
- "Body" component handling:
- Incoming Data
- Length Management
- Streaming Capabilities

e. Runtime & I/O:
- "RT" (Runtime) component managing:
- I/O Operations
- Timer Services
- Runtime Bounds

##### Component Relationships

- Client/Server → Protocol Layer (implementation dependency)
- Protocol Layer → Body Management (data flow)
- All Components → Runtime (runtime services usage)
- Service Layer → Client/Server (service implementation)

##### Data Flow

Primary data flows:
- External Client → Client Component → Protocol Layer → Body Management
- External Request → Server Component → Protocol Layer → Service Handler

##### Architectural Patterns

Following patterns:
- Asynchronous Design Pattern
- Protocol Abstraction Layer
- Connection Pooling
- Service Trait Implementation

##### Notes

Annotations for:
- Async Runtime Requirements
- HTTP/1 vs HTTP/2 Handling
- FFI Boundary Details
- Extension Points

This architecture should reflect Hyper's position as a foundational library that other HTTP clients and servers can build upon, showing clear integration points and extension mechanisms.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        C[Client Module]:::client
        CH1[HTTP/1 Handler]:::client
        CH2[HTTP/2 Handler]:::client
        CD[Dispatch System]:::client
        
        C --> CH1
        C --> CH2
        C --> CD
    end

    subgraph Server
        S[Server Module]:::server
        SH1[HTTP/1 Handler]:::server
        SH2[HTTP/2 Handler]:::server
        CM[Connection Management]:::server
        
        S --> SH1
        S --> SH2
        S --> CM
    end

    subgraph Protocol
        P[Protocol Layer]:::protocol
        H1[H1 Implementation]:::protocol
        H2[H2 Implementation]:::protocol
        PT[Protocol Traits]:::protocol
        
        P --> H1
        P --> H2
        P --> PT
    end

    subgraph Body
        B[Body Management]:::body
        BI[Incoming Data]:::body
        BL[Length Management]:::body
        BS[Streaming]:::body
        
        B --> BI
        B --> BL
        B --> BS
    end

    subgraph Runtime
        RT[Runtime Services]:::runtime
        IO[I/O Operations]:::runtime
        TS[Timer Services]:::runtime
        RB[Runtime Bounds]:::runtime
        
        RT --> IO
        RT --> TS
        RT --> RB
    end

    subgraph Service
        SL[Service Layer]:::service
        ST[Service Traits]:::service
        HS[HTTP Service]:::service
        
        SL --> ST
        SL --> HS
    end

    subgraph FFI
        F[FFI Interface]:::ffi
        FC[Client FFI]:::ffi
        FB[Body FFI]:::ffi
        FT[HTTP Types FFI]:::ffi
        
        F --> FC
        F --> FB
        F --> FT
    end

    subgraph Common
        U[Common Utilities]:::util
        UD[Date Utils]:::util
        UT[Task Utils]:::util
        UW[Watch Utils]:::util
        
        U --> UD
        U --> UT
        U --> UW
    end

    %% Main relationships
    Client --> Protocol
    Server --> Protocol
    Protocol --> Body
    Client --> Service
    Server --> Service
    
    %% Runtime dependencies
    RT -.-> Client
    RT -.-> Server
    RT -.-> Protocol
    RT -.-> Body
    
    %% FFI connections
    F -.-> Client
    F -.-> Body
    
    %% Common utility usage
    U -.-> Client
    U -.-> Server
    U -.-> Protocol

    %% Component click events
    click C "https://github.com/hyperium/hyper/blob/master/src/client/mod.rs"
    click CH1 "https://github.com/hyperium/hyper/blob/master/src/client/conn/http1.rs"
    click CH2 "https://github.com/hyperium/hyper/blob/master/src/client/conn/http2.rs"
    click CD "https://github.com/hyperium/hyper/blob/master/src/client/dispatch.rs"
    click S "https://github.com/hyperium/hyper/blob/master/src/server/mod.rs"
    click SH1 "https://github.com/hyperium/hyper/blob/master/src/server/conn/http1.rs"
    click SH2 "https://github.com/hyperium/hyper/blob/master/src/server/conn/http2.rs"
    click CM "https://github.com/hyperium/hyper/blob/master/src/server/conn/mod.rs"
    click H1 "https://github.com/hyperium/hyper/blob/master/src/proto/h1/mod.rs"
    click H2 "https://github.com/hyperium/hyper/blob/master/src/proto/h2/mod.rs"
    click PT "https://github.com/hyperium/hyper/blob/master/src/proto/mod.rs"
    click B "https://github.com/hyperium/hyper/blob/master/src/body/mod.rs"
    click BI "https://github.com/hyperium/hyper/blob/master/src/body/incoming.rs"
    click BL "https://github.com/hyperium/hyper/blob/master/src/body/length.rs"
    click RT "https://github.com/hyperium/hyper/blob/master/src/rt/mod.rs"
    click IO "https://github.com/hyperium/hyper/blob/master/src/rt/io.rs"
    click TS "https://github.com/hyperium/hyper/blob/master/src/rt/timer.rs"
    click RB "https://github.com/hyperium/hyper/blob/master/src/rt/bounds.rs"
    click F "https://github.com/hyperium/hyper/blob/master/src/ffi/mod.rs"
    click FC "https://github.com/hyperium/hyper/blob/master/src/ffi/client.rs"
    click FB "https://github.com/hyperium/hyper/blob/master/src/ffi/body.rs"
    click FT "https://github.com/hyperium/hyper/blob/master/src/ffi/http_types.rs"
    click UD "https://github.com/hyperium/hyper/blob/master/src/common/date.rs"
    click UT "https://github.com/hyperium/hyper/blob/master/src/common/task.rs"
    click UW "https://github.com/hyperium/hyper/blob/master/src/common/watch.rs"
    click SL "https://github.com/hyperium/hyper/blob/master/src/service/mod.rs"
    click HS "https://github.com/hyperium/hyper/blob/master/src/service/http.rs"
    click ST "https://github.com/hyperium/hyper/blob/master/src/service/service.rs"

    %% Styling
    classDef client fill:#2374ab
    classDef server fill:#2374ab
    classDef protocol fill:#57a773
    classDef body fill:#57a773
    classDef runtime fill:#ffc857
    classDef service fill:#2374ab
    classDef ffi fill:#7b4b94
    classDef util fill:#939393

    %% Legend
    subgraph Legend
        L1[Core HTTP Components]:::client
        L2[Protocol Components]:::protocol
        L3[Runtime Services]:::runtime
        L4[FFI Interface]:::ffi
        L5[Utilities]:::util
    end
```
