# petarivanov01/odin-http-from-scratch architecture

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

- Interactive diagram: https://gitdiagram.com/petarivanov01/odin-http-from-scratch
- Repository: https://github.com/petarivanov01/odin-http-from-scratch

## Overview

This is a small HTTP/1.1 server whose main workflow accepts a connection, receives and parses one request, dispatches by method and path, runs a handler, builds a response, sends it, and closes the connection. The README documents worker-pool execution for parsing through response building, while socket I/O stays on the I/O thread. Source excerpts were unavailable, so relationships below rely on the README; module responsibilities are inferred only where the file tree and documented capabilities support them.

Main entry points: [`main.odin`](https://github.com/petarivanov01/odin-http-from-scratch/blob/main/main.odin) (Worker pool), [`http/read.odin`](https://github.com/petarivanov01/odin-http-from-scratch/blob/main/http/read.odin) (Connection I/O), [`http/parse.odin`](https://github.com/petarivanov01/odin-http-from-scratch/blob/main/http/parse.odin) (Request parser), [`http/router.odin`](https://github.com/petarivanov01/odin-http-from-scratch/blob/main/http/router.odin) (Method-path router)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Server runtime"]
  node_server["Server entry<br/>[main.odin]"]
  node_connection_io["Connection I/O<br/>[read.odin]"]
  node_worker_pool["Worker pool<br/>[main.odin]"]
end

subgraph group_http["HTTP processing"]
  node_request_parser["Request parser<br/>[parse.odin]"]
  node_http_types["HTTP types<br/>[types.odin]"]
  node_router["Method-path router<br/>[router.odin]"]
  node_response_builder["Response builder<br/>[response.odin]"]
  node_http_errors["HTTP errors<br/>[errors.odin]"]
end

subgraph group_routes["Route handlers"]
  node_ping_routes["Ping routes<br/>[ping.odin]"]
end

node_client(("HTTP client"))
node_nbio["Nonblocking I/O"]

node_client -->|"sends request"| node_server
node_server -->|"uses I/O"| node_nbio
node_server -->|"accepts connections"| node_connection_io
node_connection_io -->|"receives bytes"| node_client
node_connection_io -->|"sends bytes"| node_client
node_server -->|"dispatches work"| node_worker_pool
node_worker_pool -->|"parses request"| node_request_parser
node_worker_pool -->|"finds route"| node_router
node_worker_pool -->|"runs handler"| node_ping_routes
node_worker_pool -->|"builds response"| node_response_builder
node_request_parser -->|"produces request"| node_http_types
node_router -->|"dispatches by method and path"| node_ping_routes
node_response_builder -->|"sets response fields"| node_http_types
node_http_errors -->|"reports failure status"| node_client

click node_server "https://github.com/petarivanov01/odin-http-from-scratch/blob/main/main.odin"
click node_connection_io "https://github.com/petarivanov01/odin-http-from-scratch/blob/main/http/read.odin"
click node_worker_pool "https://github.com/petarivanov01/odin-http-from-scratch/blob/main/main.odin"
click node_request_parser "https://github.com/petarivanov01/odin-http-from-scratch/blob/main/http/parse.odin"
click node_http_types "https://github.com/petarivanov01/odin-http-from-scratch/blob/main/http/types.odin"
click node_router "https://github.com/petarivanov01/odin-http-from-scratch/blob/main/http/router.odin"
click node_response_builder "https://github.com/petarivanov01/odin-http-from-scratch/blob/main/http/response.odin"
click node_http_errors "https://github.com/petarivanov01/odin-http-from-scratch/blob/main/http/errors.odin"
click node_ping_routes "https://github.com/petarivanov01/odin-http-from-scratch/blob/main/routes/ping.odin"

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_connection_io,node_worker_pool,node_client toneBlue
class node_request_parser,node_http_types,node_router,node_response_builder,node_http_errors toneAmber
class node_ping_routes toneMint
class node_nbio toneIndigo
```

## Components

### Server runtime

- [Server entry](https://github.com/petarivanov01/odin-http-from-scratch/blob/main/main.odin): `main.odin`
- [Connection I/O](https://github.com/petarivanov01/odin-http-from-scratch/blob/main/http/read.odin): `http/read.odin`
- [Worker pool](https://github.com/petarivanov01/odin-http-from-scratch/blob/main/main.odin): `main.odin`

### HTTP processing

- [Request parser](https://github.com/petarivanov01/odin-http-from-scratch/blob/main/http/parse.odin): `http/parse.odin`
- [HTTP types](https://github.com/petarivanov01/odin-http-from-scratch/blob/main/http/types.odin): `http/types.odin`
- [Method-path router](https://github.com/petarivanov01/odin-http-from-scratch/blob/main/http/router.odin): `http/router.odin`
- [Response builder](https://github.com/petarivanov01/odin-http-from-scratch/blob/main/http/response.odin): `http/response.odin`
- [HTTP errors](https://github.com/petarivanov01/odin-http-from-scratch/blob/main/http/errors.odin): `http/errors.odin`

### Route handlers

- [Ping routes](https://github.com/petarivanov01/odin-http-from-scratch/blob/main/routes/ping.odin): `routes/ping.odin`

### Other components

- **HTTP client**
- **Nonblocking I/O**

## Connections

- HTTP client → Server entry: sends request (evidence: `README.md`)
- Server entry → Nonblocking I/O: uses I/O (evidence: `README.md`)
- Server entry → Connection I/O: accepts connections (evidence: `README.md`)
- Connection I/O → HTTP client: receives bytes (evidence: `README.md`)
- Connection I/O → HTTP client: sends bytes (evidence: `README.md`)
- Server entry → Worker pool: dispatches work (evidence: `README.md`)
- Worker pool → Request parser: parses request (evidence: `README.md`)
- Worker pool → Method-path router: finds route (evidence: `README.md`)
- Worker pool → Ping routes: runs handler (evidence: `README.md`)
- Worker pool → Response builder: builds response (evidence: `README.md`)
- Request parser → HTTP types: produces request (evidence: `README.md`)
- Method-path router → Ping routes: dispatches by method and path (evidence: `README.md`)
- Response builder → HTTP types: sets response fields (evidence: `README.md`)
- HTTP errors → HTTP client: reports failure status (evidence: `README.md`)
