# valyala/fasthttp architecture

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

- Interactive diagram: https://gitdiagram.com/valyala/fasthttp
- Repository: https://github.com/valyala/fasthttp

## Overview

fasthttp is a high-performance Go HTTP implementation with server and client APIs. The principal server workflow accepts a connection, processes HTTP requests through a handler, and writes responses; the client workflow sends requests and receives responses. The repository also provides load balancing, proxy dialing, preforking, TCP listener options, net/http adaptation, and utility handlers. The sampled excerpts show only parts of the main runtime, so uncertain internal handoffs are omitted rather than inferred.

Main entry points: [`http.go`](https://github.com/valyala/fasthttp/blob/master/http.go) (HTTP Core), [`server.go`](https://github.com/valyala/fasthttp/blob/master/server.go) (HTTP Server), [`client.go`](https://github.com/valyala/fasthttp/blob/master/client.go) (HTTP Client), [`fasthttpadaptor/request.go`](https://github.com/valyala/fasthttp/blob/master/fasthttpadaptor/request.go) (net/http Adapter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_http_runtime["HTTP Runtime"]
  node_server["HTTP Server<br/>[server.go]"]
  node_http_core["HTTP Core<br/>[http.go]"]
  node_headers["Headers<br/>[header.go]"]
  node_uri["URI Parsing<br/>[uri.go]"]
  node_compression["Compression<br/>[compress.go]"]
end

subgraph group_client_network["Client Networking"]
  node_client["HTTP Client<br/>[client.go]"]
  node_load_balancer["Client Balancer<br/>[lbclient.go]"]
  node_proxy_dialer["Proxy Dialer<br/>[dialer.go]"]
end

subgraph group_server_network["Server Networking"]
  node_prefork["Prefork Server<br/>[prefork.go]"]
  node_reuseport["Reuseport Listener<br/>[reuseport.go]"]
  node_tcp_listener["TCP Listener<br/>[tcplisten.go]"]
end

subgraph group_integrations["Adapters and Handlers"]
  node_adaptor["net/http Adapter<br/>[request.go]"]
  node_pprof["Profiling Handler<br/>[pprof.go]"]
  node_expvar["Expvar Handler<br/>[expvar.go]"]
end

subgraph group_utilities["Utilities"]
  node_inmemory_listener["In-memory Listener"]
  node_pipe_connections["Pipe Connections<br/>[pipeconns.go]"]
  node_stackless_writer["Stackless Writer<br/>[writer.go]"]
end

node_caller(("Application"))

node_caller -.->|"serves requests"| node_server
node_caller -.->|"sends requests"| node_client
node_caller -.->|"balances requests"| node_load_balancer
node_prefork -->|"wraps server"| node_server
node_reuseport -->|"creates listener"| node_tcp_listener
node_pprof -->|"adapts handlers"| node_adaptor
node_adaptor -->|"converts requests"| node_http_core
node_client -.->|"uses dial function"| node_proxy_dialer
node_server -.->|"handles HTTP"| node_http_core
node_http_core -.->|"uses headers"| node_headers
node_http_core -.->|"parses targets"| node_uri
node_http_core -.->|"compresses bodies"| node_compression

click node_server "https://github.com/valyala/fasthttp/blob/master/server.go"
click node_http_core "https://github.com/valyala/fasthttp/blob/master/http.go"
click node_headers "https://github.com/valyala/fasthttp/blob/master/header.go"
click node_uri "https://github.com/valyala/fasthttp/blob/master/uri.go"
click node_compression "https://github.com/valyala/fasthttp/blob/master/compress.go"
click node_client "https://github.com/valyala/fasthttp/blob/master/client.go"
click node_load_balancer "https://github.com/valyala/fasthttp/blob/master/lbclient.go"
click node_proxy_dialer "https://github.com/valyala/fasthttp/blob/master/fasthttpproxy/dialer.go"
click node_prefork "https://github.com/valyala/fasthttp/blob/master/prefork/prefork.go"
click node_reuseport "https://github.com/valyala/fasthttp/blob/master/reuseport/reuseport.go"
click node_tcp_listener "https://github.com/valyala/fasthttp/blob/master/tcplisten/tcplisten.go"
click node_adaptor "https://github.com/valyala/fasthttp/blob/master/fasthttpadaptor/request.go"
click node_pprof "https://github.com/valyala/fasthttp/blob/master/pprofhandler/pprof.go"
click node_expvar "https://github.com/valyala/fasthttp/blob/master/expvarhandler/expvar.go"
click node_inmemory_listener "https://github.com/valyala/fasthttp/blob/master/fasthttputil/inmemory_listener.go"
click node_pipe_connections "https://github.com/valyala/fasthttp/blob/master/fasthttputil/pipeconns.go"
click node_stackless_writer "https://github.com/valyala/fasthttp/blob/master/stackless/writer.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_server,node_http_core,node_headers,node_uri,node_compression toneBlue
class node_client,node_load_balancer,node_proxy_dialer toneAmber
class node_prefork,node_reuseport,node_tcp_listener toneMint
class node_adaptor,node_pprof,node_expvar toneRose
class node_inmemory_listener,node_pipe_connections,node_stackless_writer,node_caller toneIndigo
```

## Components

### HTTP Runtime

- [HTTP Server](https://github.com/valyala/fasthttp/blob/master/server.go): `server.go`
- [HTTP Core](https://github.com/valyala/fasthttp/blob/master/http.go): `http.go`
- [Headers](https://github.com/valyala/fasthttp/blob/master/header.go): `header.go`
- [URI Parsing](https://github.com/valyala/fasthttp/blob/master/uri.go): `uri.go`
- [Compression](https://github.com/valyala/fasthttp/blob/master/compress.go): `compress.go`

### Client Networking

- [HTTP Client](https://github.com/valyala/fasthttp/blob/master/client.go): `client.go`
- [Client Balancer](https://github.com/valyala/fasthttp/blob/master/lbclient.go): `lbclient.go`
- [Proxy Dialer](https://github.com/valyala/fasthttp/blob/master/fasthttpproxy/dialer.go): `fasthttpproxy/dialer.go`

### Server Networking

- [Prefork Server](https://github.com/valyala/fasthttp/blob/master/prefork/prefork.go): `prefork/prefork.go`
- [Reuseport Listener](https://github.com/valyala/fasthttp/blob/master/reuseport/reuseport.go): `reuseport/reuseport.go`
- [TCP Listener](https://github.com/valyala/fasthttp/blob/master/tcplisten/tcplisten.go): `tcplisten/tcplisten.go`

### Adapters and Handlers

- [net/http Adapter](https://github.com/valyala/fasthttp/blob/master/fasthttpadaptor/request.go): `fasthttpadaptor/request.go`
- [Profiling Handler](https://github.com/valyala/fasthttp/blob/master/pprofhandler/pprof.go): `pprofhandler/pprof.go`
- [Expvar Handler](https://github.com/valyala/fasthttp/blob/master/expvarhandler/expvar.go): `expvarhandler/expvar.go`

### Utilities

- [In-memory Listener](https://github.com/valyala/fasthttp/blob/master/fasthttputil/inmemory_listener.go): `fasthttputil/inmemory_listener.go`
- [Pipe Connections](https://github.com/valyala/fasthttp/blob/master/fasthttputil/pipeconns.go): `fasthttputil/pipeconns.go`
- [Stackless Writer](https://github.com/valyala/fasthttp/blob/master/stackless/writer.go): `stackless/writer.go`

### Other components

- **Application**

## Connections

- Application → HTTP Server: serves requests
- Application → HTTP Client: sends requests
- Application → Client Balancer: balances requests (evidence: `lbclient.go`)
- Prefork Server → HTTP Server: wraps server (evidence: `prefork/prefork.go`)
- Reuseport Listener → TCP Listener: creates listener (evidence: `reuseport/reuseport.go`)
- Profiling Handler → net/http Adapter: adapts handlers (evidence: `pprofhandler/pprof.go`)
- net/http Adapter → HTTP Core: converts requests (evidence: `fasthttpadaptor/request.go`)
- HTTP Client → Proxy Dialer: uses dial function
- HTTP Server → HTTP Core: handles HTTP
- HTTP Core → Headers: uses headers
- HTTP Core → URI Parsing: parses targets
- HTTP Core → Compression: compresses bodies
