# kludex/uvicorn architecture

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

- Interactive diagram: https://gitdiagram.com/kludex/uvicorn
- Repository: https://github.com/kludex/uvicorn

## Overview

Uvicorn is a Python ASGI server. The principal workflow is CLI invocation, configuration and application loading, listener startup, protocol handling of HTTP or WebSocket traffic, and ASGI messages exchanged with the application. Separate runtime branches cover lifespan, middleware, logging, and reload/worker process management. The README documents HTTP/1.1, HTTP/2, and WebSocket support; source excerpts and the SOURCE INDEX support the implementation links shown. Some wiring is unsampled, so uncertain links are omitted.

Main entry points: [`uvicorn/server.py`](https://github.com/kludex/uvicorn/blob/main/uvicorn/server.py) (Server and listeners), [`uvicorn/config.py`](https://github.com/kludex/uvicorn/blob/main/uvicorn/config.py) (Configuration and app loading), [`uvicorn/main.py`](https://github.com/kludex/uvicorn/blob/main/uvicorn/main.py) (CLI and run API), [`uvicorn/protocols/http/h11_impl.py`](https://github.com/kludex/uvicorn/blob/main/uvicorn/protocols/http/h11_impl.py) (HTTP/1.1 h11)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry and configuration"]
  node_cli["CLI and run API<br/>[main.py]"]
  node_config["Configuration and app loading<br/>[config.py]"]
end

subgraph group_runtime["Server runtime"]
  node_server["Server and listeners<br/>[server.py]"]
  node_lifespan["Lifespan handling<br/>[on.py]"]
end

subgraph group_protocols["Connection protocols"]
  node_http1["HTTP/1.1 h11<br/>[h11_impl.py]"]
  node_httptools["HTTP httptools<br/>[httptools_impl.py]"]
  node_http2["HTTP/2<br/>[zttp_h2_impl.py]"]
  node_zhttph1["HTTP zttp<br/>[zttp_impl.py]"]
  node_wswebsockets["WebSocket websockets<br/>[websockets_impl.py]"]
  node_wssansio["WebSocket sans-I/O"]
  node_wsproto["WebSocket wsproto<br/>[wsproto_impl.py]"]
end

subgraph group_support["Runtime support"]
  node_types["ASGI types and messages<br/>[_types.py]"]
  node_flow["HTTP flow control<br/>[flow_control.py]"]
  node_middleware["ASGI middleware"]
  node_loops["Event loop selection<br/>[asyncio.py]"]
  node_logging["Logging and access logs<br/>[logging.py]"]
end

subgraph group_processes["Process management"]
  node_reload["Reload supervisors<br/>[basereload.py]"]
  node_workers["Worker processes<br/>[workers.py]"]
  node_subprocess["Subprocess support<br/>[_subprocess.py]"]
end

node_asgi(("ASGI application"))

node_cli -->|"builds"| node_config
node_cli -->|"starts"| node_server
node_config -->|"loads"| node_asgi
node_server -->|"uses settings"| node_config
node_server -->|"creates protocol"| node_http1
node_server -->|"creates protocol"| node_httptools
node_server -->|"creates protocol"| node_http2
node_server -->|"creates protocol"| node_zhttph1
node_server -->|"creates protocol"| node_wswebsockets
node_server -->|"creates protocol"| node_wssansio
node_server -->|"creates protocol"| node_wsproto
node_server -->|"runs lifecycle"| node_lifespan
node_http1 -->|"dispatches ASGI"| node_asgi
node_httptools -->|"dispatches ASGI"| node_asgi
node_http2 -->|"dispatches ASGI"| node_asgi
node_zhttph1 -->|"dispatches ASGI"| node_asgi
node_wswebsockets -->|"dispatches ASGI"| node_asgi
node_wssansio -->|"dispatches ASGI"| node_asgi
node_wsproto -->|"dispatches ASGI"| node_asgi
node_config -->|"configures"| node_middleware
node_http1 -->|"uses flow control"| node_flow
node_httptools -->|"uses flow control"| node_flow
node_zhttph1 -->|"uses flow control"| node_flow
node_http1 -->|"uses message types"| node_types
node_wssansio -->|"uses message types"| node_types
node_config -->|"selects loop"| node_loops
node_server -->|"logs runtime"| node_logging
node_cli -->|"selects supervisor"| node_reload
node_reload -->|"spawns process"| node_subprocess
node_cli -->|"selects workers"| node_workers
node_workers -->|"runs server"| node_server

click node_cli "https://github.com/kludex/uvicorn/blob/main/uvicorn/main.py"
click node_config "https://github.com/kludex/uvicorn/blob/main/uvicorn/config.py"
click node_server "https://github.com/kludex/uvicorn/blob/main/uvicorn/server.py"
click node_lifespan "https://github.com/kludex/uvicorn/blob/main/uvicorn/lifespan/on.py"
click node_http1 "https://github.com/kludex/uvicorn/blob/main/uvicorn/protocols/http/h11_impl.py"
click node_httptools "https://github.com/kludex/uvicorn/blob/main/uvicorn/protocols/http/httptools_impl.py"
click node_http2 "https://github.com/kludex/uvicorn/blob/main/uvicorn/protocols/http/zttp_h2_impl.py"
click node_zhttph1 "https://github.com/kludex/uvicorn/blob/main/uvicorn/protocols/http/zttp_impl.py"
click node_wswebsockets "https://github.com/kludex/uvicorn/blob/main/uvicorn/protocols/websockets/websockets_impl.py"
click node_wssansio "https://github.com/kludex/uvicorn/blob/main/uvicorn/protocols/websockets/websockets_sansio_impl.py"
click node_wsproto "https://github.com/kludex/uvicorn/blob/main/uvicorn/protocols/websockets/wsproto_impl.py"
click node_types "https://github.com/kludex/uvicorn/blob/main/uvicorn/_types.py"
click node_flow "https://github.com/kludex/uvicorn/blob/main/uvicorn/protocols/http/flow_control.py"
click node_middleware "https://github.com/kludex/uvicorn/tree/main/uvicorn/middleware"
click node_loops "https://github.com/kludex/uvicorn/blob/main/uvicorn/loops/asyncio.py"
click node_logging "https://github.com/kludex/uvicorn/blob/main/uvicorn/logging.py"
click node_reload "https://github.com/kludex/uvicorn/blob/main/uvicorn/supervisors/basereload.py"
click node_workers "https://github.com/kludex/uvicorn/blob/main/uvicorn/workers.py"
click node_subprocess "https://github.com/kludex/uvicorn/blob/main/uvicorn/_subprocess.py"

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_cli,node_config toneBlue
class node_server,node_lifespan toneAmber
class node_http1,node_httptools,node_http2,node_zhttph1,node_wswebsockets,node_wssansio,node_wsproto toneMint
class node_types,node_flow,node_middleware,node_loops,node_logging toneRose
class node_reload,node_workers,node_subprocess,node_asgi toneIndigo
```

## Components

### Entry and configuration

- [CLI and run API](https://github.com/kludex/uvicorn/blob/main/uvicorn/main.py): `uvicorn/main.py`
- [Configuration and app loading](https://github.com/kludex/uvicorn/blob/main/uvicorn/config.py): `uvicorn/config.py`

### Server runtime

- [Server and listeners](https://github.com/kludex/uvicorn/blob/main/uvicorn/server.py): `uvicorn/server.py`
- [Lifespan handling](https://github.com/kludex/uvicorn/blob/main/uvicorn/lifespan/on.py): `uvicorn/lifespan/on.py`

### Connection protocols

- [HTTP/1.1 h11](https://github.com/kludex/uvicorn/blob/main/uvicorn/protocols/http/h11_impl.py): `uvicorn/protocols/http/h11_impl.py`
- [HTTP httptools](https://github.com/kludex/uvicorn/blob/main/uvicorn/protocols/http/httptools_impl.py): `uvicorn/protocols/http/httptools_impl.py`
- [HTTP/2](https://github.com/kludex/uvicorn/blob/main/uvicorn/protocols/http/zttp_h2_impl.py): `uvicorn/protocols/http/zttp_h2_impl.py`
- [HTTP zttp](https://github.com/kludex/uvicorn/blob/main/uvicorn/protocols/http/zttp_impl.py): `uvicorn/protocols/http/zttp_impl.py`
- [WebSocket websockets](https://github.com/kludex/uvicorn/blob/main/uvicorn/protocols/websockets/websockets_impl.py): `uvicorn/protocols/websockets/websockets_impl.py`
- [WebSocket sans-I/O](https://github.com/kludex/uvicorn/blob/main/uvicorn/protocols/websockets/websockets_sansio_impl.py): `uvicorn/protocols/websockets/websockets_sansio_impl.py`
- [WebSocket wsproto](https://github.com/kludex/uvicorn/blob/main/uvicorn/protocols/websockets/wsproto_impl.py): `uvicorn/protocols/websockets/wsproto_impl.py`

### Runtime support

- [ASGI types and messages](https://github.com/kludex/uvicorn/blob/main/uvicorn/_types.py): `uvicorn/_types.py`
- [HTTP flow control](https://github.com/kludex/uvicorn/blob/main/uvicorn/protocols/http/flow_control.py): `uvicorn/protocols/http/flow_control.py`
- [ASGI middleware](https://github.com/kludex/uvicorn/tree/main/uvicorn/middleware): `uvicorn/middleware`
- [Event loop selection](https://github.com/kludex/uvicorn/blob/main/uvicorn/loops/asyncio.py): `uvicorn/loops/asyncio.py`
- [Logging and access logs](https://github.com/kludex/uvicorn/blob/main/uvicorn/logging.py): `uvicorn/logging.py`

### Process management

- [Reload supervisors](https://github.com/kludex/uvicorn/blob/main/uvicorn/supervisors/basereload.py): `uvicorn/supervisors/basereload.py`
- [Worker processes](https://github.com/kludex/uvicorn/blob/main/uvicorn/workers.py): `uvicorn/workers.py`
- [Subprocess support](https://github.com/kludex/uvicorn/blob/main/uvicorn/_subprocess.py): `uvicorn/_subprocess.py`

### Other components

- **ASGI application**

## Connections

- CLI and run API → Configuration and app loading: builds (evidence: `uvicorn/main.py`)
- CLI and run API → Server and listeners: starts (evidence: `uvicorn/main.py`)
- Configuration and app loading → ASGI application: loads (evidence: `uvicorn/config.py`)
- Server and listeners → Configuration and app loading: uses settings (evidence: `uvicorn/server.py`)
- Server and listeners → HTTP/1.1 h11: creates protocol (evidence: `uvicorn/server.py`)
- Server and listeners → HTTP httptools: creates protocol (evidence: `uvicorn/server.py`)
- Server and listeners → HTTP/2: creates protocol (evidence: `uvicorn/server.py`)
- Server and listeners → HTTP zttp: creates protocol (evidence: `uvicorn/server.py`)
- Server and listeners → WebSocket websockets: creates protocol (evidence: `uvicorn/server.py`)
- Server and listeners → WebSocket sans-I/O: creates protocol (evidence: `uvicorn/server.py`)
- Server and listeners → WebSocket wsproto: creates protocol (evidence: `uvicorn/server.py`)
- Server and listeners → Lifespan handling: runs lifecycle (evidence: `uvicorn/server.py`)
- HTTP/1.1 h11 → ASGI application: dispatches ASGI (evidence: `uvicorn/protocols/http/h11_impl.py`)
- HTTP httptools → ASGI application: dispatches ASGI (evidence: `uvicorn/protocols/http/httptools_impl.py`)
- HTTP/2 → ASGI application: dispatches ASGI (evidence: `uvicorn/protocols/http/zttp_h2_impl.py`)
- HTTP zttp → ASGI application: dispatches ASGI (evidence: `uvicorn/protocols/http/zttp_impl.py`)
- WebSocket websockets → ASGI application: dispatches ASGI (evidence: `uvicorn/protocols/websockets/websockets_impl.py`)
- WebSocket sans-I/O → ASGI application: dispatches ASGI (evidence: `uvicorn/protocols/websockets/websockets_sansio_impl.py`)
- WebSocket wsproto → ASGI application: dispatches ASGI (evidence: `uvicorn/protocols/websockets/wsproto_impl.py`)
- Configuration and app loading → ASGI middleware: configures (evidence: `uvicorn/config.py`)
- HTTP/1.1 h11 → HTTP flow control: uses flow control (evidence: `uvicorn/protocols/http/h11_impl.py`)
- HTTP httptools → HTTP flow control: uses flow control (evidence: `uvicorn/protocols/http/httptools_impl.py`)
- HTTP zttp → HTTP flow control: uses flow control (evidence: `uvicorn/protocols/http/zttp_impl.py`)
- HTTP/1.1 h11 → ASGI types and messages: uses message types (evidence: `uvicorn/protocols/http/h11_impl.py`)
- WebSocket sans-I/O → ASGI types and messages: uses message types (evidence: `uvicorn/protocols/websockets/websockets_sansio_impl.py`)
- Configuration and app loading → Event loop selection: selects loop (evidence: `uvicorn/config.py`)
- Server and listeners → Logging and access logs: logs runtime (evidence: `uvicorn/server.py`)
- CLI and run API → Reload supervisors: selects supervisor (evidence: `uvicorn/main.py`)
- Reload supervisors → Subprocess support: spawns process (evidence: `uvicorn/supervisors/basereload.py`)
- CLI and run API → Worker processes: selects workers (evidence: `uvicorn/main.py`)
- Worker processes → Server and listeners: runs server (evidence: `uvicorn/workers.py`)
