# kludex/zttp architecture

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

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

## Overview

zttp is a sans-IO HTTP parser for Python backed by a Zig engine. An integrator supplies bytes (or HTTP/3 datagrams), pulls parsed events, and requests serialized output; zttp does not own sockets or perform I/O. The Python API exposes the native connection and event types, while protocol engines handle HTTP/1.1, HTTP/2, and HTTP/3; HTTP/3 also depends on the QUIC transport. The QUIC endpoint routes datagrams to HTTP/3 connections. Several core implementation files were not excerpted, so their internal call relationships are omitted; documented relationships use the README as evidence.

Main entry points: [`src/python/connection_obj.zig`](https://github.com/kludex/zttp/blob/main/src/python/connection_obj.zig) (Native Connection), [`src/core/h3`](https://github.com/kludex/zttp/tree/main/src/core/h3) (HTTP/3 Engine), [`zttp/__init__.py`](https://github.com/kludex/zttp/blob/main/zttp/__init__.py) (Public API), [`zttp/endpoint.py`](https://github.com/kludex/zttp/blob/main/zttp/endpoint.py) (QUIC Endpoint)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_python_api["Python API"]
  node_public_api["Public API<br/>[__init__.py]"]
  node_h3_endpoint["QUIC Endpoint<br/>[endpoint.py]"]
  node_endpoint_tokens["Address Tokens<br/>[_tokens.py]"]
  node_h3_config["TLS and QUIC Config<br/>[config.py]"]
  node_native_connection["Native Connection<br/>[connection_obj.zig]"]
  node_python_module["Python Extension<br/>[module.zig]"]
end

subgraph group_http_engines["HTTP Engines"]
  node_h1_engine["HTTP/1.1 Engine"]
  node_h2_engine["HTTP/2 Engine"]
  node_h3_engine["HTTP/3 Engine"]
end

subgraph group_quic_transport["QUIC Transport"]
  node_quic_connection["QUIC Connection<br/>[connection.zig]"]
  node_quic_tls["QUIC TLS"]
  node_quic_recovery["Loss Recovery<br/>[recovery.zig]"]
end

subgraph group_shared_core["Shared Core"]
  node_event_types["Events and Errors<br/>[events.zig]"]
  node_header_fields["Header Fields<br/>[fields.zig]"]
end

node_integrator(("I/O Integrator"))

node_integrator -->|"feeds bytes"| node_public_api
node_public_api -.->|"exposes connections"| node_native_connection
node_native_connection -.->|"uses extension"| node_python_module
node_public_api -->|"exposes endpoint"| node_h3_endpoint
node_h3_endpoint -->|"validates tokens"| node_endpoint_tokens
node_h3_endpoint -->|"accepts configuration"| node_h3_config
node_h3_endpoint -->|"creates connections"| node_h3_engine
node_native_connection -.->|"dispatches protocol"| node_h1_engine
node_native_connection -.->|"dispatches protocol"| node_h2_engine
node_native_connection -.->|"dispatches protocol"| node_h3_engine
node_h1_engine -.->|"emits events"| node_event_types
node_h2_engine -.->|"emits events"| node_event_types
node_h3_engine -.->|"emits events"| node_event_types
node_h3_engine -->|"uses transport"| node_quic_connection
node_quic_connection -.->|"performs handshake"| node_quic_tls
node_quic_connection -.->|"recovers loss"| node_quic_recovery
node_h1_engine -.->|"parses fields"| node_header_fields
node_h2_engine -.->|"parses fields"| node_header_fields
node_h3_engine -.->|"parses fields"| node_header_fields
node_public_api -->|"returns events and bytes"| node_integrator

click node_public_api "https://github.com/kludex/zttp/blob/main/zttp/__init__.py"
click node_h3_endpoint "https://github.com/kludex/zttp/blob/main/zttp/endpoint.py"
click node_endpoint_tokens "https://github.com/kludex/zttp/blob/main/zttp/_tokens.py"
click node_h3_config "https://github.com/kludex/zttp/blob/main/zttp/config.py"
click node_native_connection "https://github.com/kludex/zttp/blob/main/src/python/connection_obj.zig"
click node_python_module "https://github.com/kludex/zttp/blob/main/src/python/module.zig"
click node_h1_engine "https://github.com/kludex/zttp/tree/main/src/core/h1"
click node_h2_engine "https://github.com/kludex/zttp/tree/main/src/core/h2"
click node_h3_engine "https://github.com/kludex/zttp/tree/main/src/core/h3"
click node_quic_connection "https://github.com/kludex/zttp/blob/main/src/core/quic/connection.zig"
click node_quic_tls "https://github.com/kludex/zttp/tree/main/src/core/quic/tls"
click node_quic_recovery "https://github.com/kludex/zttp/blob/main/src/core/quic/recovery.zig"
click node_event_types "https://github.com/kludex/zttp/blob/main/src/core/events.zig"
click node_header_fields "https://github.com/kludex/zttp/blob/main/src/core/fields.zig"

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_public_api,node_h3_endpoint,node_endpoint_tokens,node_h3_config,node_native_connection,node_python_module toneBlue
class node_h1_engine,node_h2_engine,node_h3_engine toneAmber
class node_quic_connection,node_quic_tls,node_quic_recovery toneMint
class node_event_types,node_header_fields toneRose
class node_integrator toneIndigo
```

## Components

### Python API

- [Public API](https://github.com/kludex/zttp/blob/main/zttp/__init__.py): `zttp/__init__.py`
- [QUIC Endpoint](https://github.com/kludex/zttp/blob/main/zttp/endpoint.py): `zttp/endpoint.py`
- [Address Tokens](https://github.com/kludex/zttp/blob/main/zttp/_tokens.py): `zttp/_tokens.py`
- [TLS and QUIC Config](https://github.com/kludex/zttp/blob/main/zttp/config.py): `zttp/config.py`
- [Native Connection](https://github.com/kludex/zttp/blob/main/src/python/connection_obj.zig): `src/python/connection_obj.zig`
- [Python Extension](https://github.com/kludex/zttp/blob/main/src/python/module.zig): `src/python/module.zig`

### HTTP Engines

- [HTTP/1.1 Engine](https://github.com/kludex/zttp/tree/main/src/core/h1): `src/core/h1`
- [HTTP/2 Engine](https://github.com/kludex/zttp/tree/main/src/core/h2): `src/core/h2`
- [HTTP/3 Engine](https://github.com/kludex/zttp/tree/main/src/core/h3): `src/core/h3`

### QUIC Transport

- [QUIC Connection](https://github.com/kludex/zttp/blob/main/src/core/quic/connection.zig): `src/core/quic/connection.zig`
- [QUIC TLS](https://github.com/kludex/zttp/tree/main/src/core/quic/tls): `src/core/quic/tls`
- [Loss Recovery](https://github.com/kludex/zttp/blob/main/src/core/quic/recovery.zig): `src/core/quic/recovery.zig`

### Shared Core

- [Events and Errors](https://github.com/kludex/zttp/blob/main/src/core/events.zig): `src/core/events.zig`
- [Header Fields](https://github.com/kludex/zttp/blob/main/src/core/fields.zig): `src/core/fields.zig`

### Other components

- **I/O Integrator**

## Connections

- I/O Integrator → Public API: feeds bytes (evidence: `README.md`)
- Public API → Native Connection: exposes connections
- Native Connection → Python Extension: uses extension
- Public API → QUIC Endpoint: exposes endpoint (evidence: `zttp/__init__.py`)
- QUIC Endpoint → Address Tokens: validates tokens (evidence: `zttp/endpoint.py`)
- QUIC Endpoint → TLS and QUIC Config: accepts configuration (evidence: `zttp/endpoint.py`)
- QUIC Endpoint → HTTP/3 Engine: creates connections (evidence: `zttp/endpoint.py`)
- Native Connection → HTTP/1.1 Engine: dispatches protocol
- Native Connection → HTTP/2 Engine: dispatches protocol
- Native Connection → HTTP/3 Engine: dispatches protocol
- HTTP/1.1 Engine → Events and Errors: emits events
- HTTP/2 Engine → Events and Errors: emits events
- HTTP/3 Engine → Events and Errors: emits events
- HTTP/3 Engine → QUIC Connection: uses transport (evidence: `README.md`)
- QUIC Connection → QUIC TLS: performs handshake
- QUIC Connection → Loss Recovery: recovers loss
- HTTP/1.1 Engine → Header Fields: parses fields
- HTTP/2 Engine → Header Fields: parses fields
- HTTP/3 Engine → Header Fields: parses fields
- Public API → I/O Integrator: returns events and bytes (evidence: `README.md`)
