# yousuffx19/tinyhttp1 architecture

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

- Interactive diagram: https://gitdiagram.com/yousuffx19/tinyhttp1
- Repository: https://github.com/yousuffx19/tinyhttp1

## Overview

Tinyhttp1 is a small POSIX HTTP/1.1 server. A client connects to the listener; each accepted connection is handled on a detached thread, whose request parsing and routing lead to custom responses, static-file delivery, or directory listings. Internal layers cover method and MIME checks, response formatting, filesystem access, and directory HTML generation. The README documents supported content types and concurrent connections; implementation edges below are based on the sampled server and utility sources, so unsampled behavior is not inferred.

Main entry points: [`src/server.c`](https://github.com/yousuffx19/tinyhttp1/blob/v2/src/server.c) (Request router), [`src/dirutils.c`](https://github.com/yousuffx19/tinyhttp1/blob/v2/src/dirutils.c) (Directory listing), [`www`](https://github.com/yousuffx19/tinyhttp1/tree/v2/www) (Web content), [`src/httputils.c`](https://github.com/yousuffx19/tinyhttp1/blob/v2/src/httputils.c) (Method validation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Server runtime"]
  node_listener["Socket listener<br/>[server.c]"]
  node_connection["Connection worker<br/>[server.c]"]
end

subgraph group_http["HTTP handling"]
  node_request["Request parser<br/>[server.c]"]
  node_router["Request router<br/>[server.c]"]
  node_method["Method validation<br/>[httputils.c]"]
  node_routes["Custom routes<br/>[server.c]"]
  node_mime["MIME selection<br/>[httputils.c]"]
  node_responses["Response formatting<br/>[httputils.c]"]
end

subgraph group_content["Content serving"]
  node_static["Static file delivery<br/>[server.c]"]
  node_directory["Directory listing<br/>[dirutils.c]"]
  node_webroot["Web content"]
end

subgraph group_filesystem["Filesystem utilities"]
  node_fileaccess["File access<br/>[server.c]"]
  node_dircheck["Directory checks<br/>[dirutils.c]"]
end

node_client(("HTTP client"))

node_client -->|"opens connection"| node_listener
node_listener -->|"dispatches"| node_connection
node_connection -->|"parses request"| node_request
node_request -->|"routes request"| node_router
node_router -->|"checks method"| node_method
node_router -->|"matches paths"| node_routes
node_router -->|"selects type"| node_mime
node_router -->|"formats response"| node_responses
node_router -->|"serves files"| node_static
node_router -->|"generates listing"| node_directory
node_static -->|"reads file"| node_fileaccess
node_static -->|"serves content"| node_webroot
node_router -->|"checks directory"| node_dircheck
node_directory -.->|"lists entries"| node_webroot

click node_listener "https://github.com/yousuffx19/tinyhttp1/blob/v2/src/server.c"
click node_connection "https://github.com/yousuffx19/tinyhttp1/blob/v2/src/server.c"
click node_request "https://github.com/yousuffx19/tinyhttp1/blob/v2/src/server.c"
click node_router "https://github.com/yousuffx19/tinyhttp1/blob/v2/src/server.c"
click node_method "https://github.com/yousuffx19/tinyhttp1/blob/v2/src/httputils.c"
click node_routes "https://github.com/yousuffx19/tinyhttp1/blob/v2/src/server.c"
click node_mime "https://github.com/yousuffx19/tinyhttp1/blob/v2/src/httputils.c"
click node_responses "https://github.com/yousuffx19/tinyhttp1/blob/v2/src/httputils.c"
click node_static "https://github.com/yousuffx19/tinyhttp1/blob/v2/src/server.c"
click node_directory "https://github.com/yousuffx19/tinyhttp1/blob/v2/src/dirutils.c"
click node_webroot "https://github.com/yousuffx19/tinyhttp1/tree/v2/www"
click node_fileaccess "https://github.com/yousuffx19/tinyhttp1/blob/v2/src/server.c"
click node_dircheck "https://github.com/yousuffx19/tinyhttp1/blob/v2/src/dirutils.c"

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_listener,node_connection,node_client toneBlue
class node_request,node_router,node_method,node_routes,node_mime,node_responses toneAmber
class node_static,node_directory,node_webroot toneMint
class node_fileaccess,node_dircheck toneRose
```

## Components

### Server runtime

- [Socket listener](https://github.com/yousuffx19/tinyhttp1/blob/v2/src/server.c): `src/server.c`
- [Connection worker](https://github.com/yousuffx19/tinyhttp1/blob/v2/src/server.c): `src/server.c`

### HTTP handling

- [Request parser](https://github.com/yousuffx19/tinyhttp1/blob/v2/src/server.c): `src/server.c`
- [Request router](https://github.com/yousuffx19/tinyhttp1/blob/v2/src/server.c): `src/server.c`
- [Method validation](https://github.com/yousuffx19/tinyhttp1/blob/v2/src/httputils.c): `src/httputils.c`
- [Custom routes](https://github.com/yousuffx19/tinyhttp1/blob/v2/src/server.c): `src/server.c`
- [MIME selection](https://github.com/yousuffx19/tinyhttp1/blob/v2/src/httputils.c): `src/httputils.c`
- [Response formatting](https://github.com/yousuffx19/tinyhttp1/blob/v2/src/httputils.c): `src/httputils.c`

### Content serving

- [Static file delivery](https://github.com/yousuffx19/tinyhttp1/blob/v2/src/server.c): `src/server.c`
- [Directory listing](https://github.com/yousuffx19/tinyhttp1/blob/v2/src/dirutils.c): `src/dirutils.c`
- [Web content](https://github.com/yousuffx19/tinyhttp1/tree/v2/www): `www`

### Filesystem utilities

- [File access](https://github.com/yousuffx19/tinyhttp1/blob/v2/src/server.c): `src/server.c`
- [Directory checks](https://github.com/yousuffx19/tinyhttp1/blob/v2/src/dirutils.c): `src/dirutils.c`

### Other components

- **HTTP client**

## Connections

- HTTP client → Socket listener: opens connection (evidence: `src/server.c`)
- Socket listener → Connection worker: dispatches (evidence: `src/server.c`)
- Connection worker → Request parser: parses request (evidence: `src/server.c`)
- Request parser → Request router: routes request (evidence: `src/server.c`)
- Request router → Method validation: checks method (evidence: `src/server.c`)
- Request router → Custom routes: matches paths (evidence: `src/server.c`)
- Request router → MIME selection: selects type (evidence: `src/server.c`)
- Request router → Response formatting: formats response (evidence: `src/server.c`)
- Request router → Static file delivery: serves files (evidence: `src/server.c`)
- Request router → Directory listing: generates listing (evidence: `src/server.c`)
- Static file delivery → File access: reads file (evidence: `src/server.c`)
- Static file delivery → Web content: serves content (evidence: `src/server.c`)
- Request router → Directory checks: checks directory (evidence: `src/server.c`)
- Directory listing → Web content: lists entries
