# mtcp-stack/mtcp architecture

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

- Interactive diagram: https://gitdiagram.com/mtcp-stack/mtcp
- Repository: https://github.com/mtcp-stack/mtcp

## Overview

mTCP is a user-level TCP stack for multicore systems, with packet-I/O backends and ported applications. The main workflow is an application using the mTCP socket/event API; the stack processes TCP and packet I/O, then returns data or events to the application. The README documents DPDK, PSIO, and netmap as I/O choices and describes a ported lighttpd and Apache benchmark. Some subsystem paths and relationships below rely on README statements or SOURCE INDEX references; unsampled implementation details are not inferred.

Main entry points: [`mtcp/src/core.c`](https://github.com/mtcp-stack/mtcp/blob/master/mtcp/src/core.c) (Stack core), [`apps/lighttpd-1.4.32/src/server.c`](https://github.com/mtcp-stack/mtcp/blob/master/apps/lighttpd-1.4.32/src/server.c) (Ported lighttpd), [`mtcp/src/api.c`](https://github.com/mtcp-stack/mtcp/blob/master/mtcp/src/api.c) (mTCP API), [`apps/perf/client.c`](https://github.com/mtcp-stack/mtcp/blob/master/apps/perf/client.c) (Perf client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_apps["Applications"]
  node_lighttpd["Ported lighttpd<br/>[server.c]"]
  node_auth["HTTP authentication<br/>[http_auth.c]"]
  node_ssi["SSI expression parser"]
  node_ab["Apache benchmark"]
  node_perf["Perf client<br/>[client.c]"]
end

subgraph group_stack["TCP stack"]
  node_api["mTCP API<br/>[api.c]"]
  node_core["Stack core<br/>[core.c]"]
  node_tcpin["TCP input<br/>[tcp_in.c]"]
  node_tcpout["TCP output<br/>[tcp_out.c]"]
  node_frags["Fragment queue"]
  node_ring["TCP ring buffer<br/>[tcp_ring_buffer.h]"]
end

subgraph group_io["Packet I/O"]
  node_psio["PSIO library<br/>[pslib.c]"]
  node_ixgbe["PSIO NIC driver<br/>[ixgbe_main.c]"]
  node_backend["Other I/O backends"]
end

subgraph group_support["Runtime support"]
  node_util["Network utilities<br/>[netlib.c]"]
end

node_user(("Application user"))

node_user -->|"configures"| node_lighttpd
node_user -->|"runs benchmark"| node_ab
node_user -->|"runs client"| node_perf
node_lighttpd -->|"uses sockets"| node_api
node_ab -.->|"uses TCP"| node_api
node_perf -->|"calls API"| node_api
node_lighttpd -->|"delegates auth"| node_auth
node_lighttpd -.->|"parses SSI"| node_ssi
node_api -->|"dispatches"| node_core
node_core -->|"processes input"| node_tcpin
node_core -->|"processes output"| node_tcpout
node_tcpin -->|"buffers data"| node_ring
node_tcpin -.->|"queues fragments"| node_frags
node_core -->|"receives packets"| node_psio
node_psio -->|"accesses driver"| node_ixgbe
node_core -.->|"selects backend"| node_backend
node_perf -->|"uses helpers"| node_util

click node_api "https://github.com/mtcp-stack/mtcp/blob/master/mtcp/src/api.c"
click node_core "https://github.com/mtcp-stack/mtcp/blob/master/mtcp/src/core.c"
click node_tcpin "https://github.com/mtcp-stack/mtcp/blob/master/mtcp/src/tcp_in.c"
click node_tcpout "https://github.com/mtcp-stack/mtcp/blob/master/mtcp/src/tcp_out.c"
click node_frags "https://github.com/mtcp-stack/mtcp/blob/master/mtcp/src/tcp_rb_frag_queue.c"
click node_ring "https://github.com/mtcp-stack/mtcp/blob/master/mtcp/src/include/tcp_ring_buffer.h"
click node_psio "https://github.com/mtcp-stack/mtcp/blob/master/io_engine/lib/pslib.c"
click node_ixgbe "https://github.com/mtcp-stack/mtcp/blob/master/io_engine/driver/ixgbe_main.c"
click node_backend "https://github.com/mtcp-stack/mtcp/tree/master/mtcp/src"
click node_lighttpd "https://github.com/mtcp-stack/mtcp/blob/master/apps/lighttpd-1.4.32/src/server.c"
click node_auth "https://github.com/mtcp-stack/mtcp/blob/master/apps/lighttpd-1.4.32/src/http_auth.c"
click node_ssi "https://github.com/mtcp-stack/mtcp/blob/master/apps/lighttpd-1.4.32/src/mod_ssi_exprparser.c"
click node_ab "https://github.com/mtcp-stack/mtcp/blob/master/apps/apache_benchmark/support/ab-multiple-files.c"
click node_perf "https://github.com/mtcp-stack/mtcp/blob/master/apps/perf/client.c"
click node_util "https://github.com/mtcp-stack/mtcp/blob/master/util/netlib.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_lighttpd,node_auth,node_ssi,node_ab,node_perf,node_user toneBlue
class node_api,node_core,node_tcpin,node_tcpout,node_frags,node_ring toneAmber
class node_psio,node_ixgbe,node_backend toneMint
class node_util toneRose
```

## Components

### Applications

- [Ported lighttpd](https://github.com/mtcp-stack/mtcp/blob/master/apps/lighttpd-1.4.32/src/server.c): `apps/lighttpd-1.4.32/src/server.c`
- [HTTP authentication](https://github.com/mtcp-stack/mtcp/blob/master/apps/lighttpd-1.4.32/src/http_auth.c): `apps/lighttpd-1.4.32/src/http_auth.c`
- [SSI expression parser](https://github.com/mtcp-stack/mtcp/blob/master/apps/lighttpd-1.4.32/src/mod_ssi_exprparser.c): `apps/lighttpd-1.4.32/src/mod_ssi_exprparser.c`
- [Apache benchmark](https://github.com/mtcp-stack/mtcp/blob/master/apps/apache_benchmark/support/ab-multiple-files.c): `apps/apache_benchmark/support/ab-multiple-files.c`
- [Perf client](https://github.com/mtcp-stack/mtcp/blob/master/apps/perf/client.c): `apps/perf/client.c`

### TCP stack

- [mTCP API](https://github.com/mtcp-stack/mtcp/blob/master/mtcp/src/api.c): `mtcp/src/api.c`
- [Stack core](https://github.com/mtcp-stack/mtcp/blob/master/mtcp/src/core.c): `mtcp/src/core.c`
- [TCP input](https://github.com/mtcp-stack/mtcp/blob/master/mtcp/src/tcp_in.c): `mtcp/src/tcp_in.c`
- [TCP output](https://github.com/mtcp-stack/mtcp/blob/master/mtcp/src/tcp_out.c): `mtcp/src/tcp_out.c`
- [Fragment queue](https://github.com/mtcp-stack/mtcp/blob/master/mtcp/src/tcp_rb_frag_queue.c): `mtcp/src/tcp_rb_frag_queue.c`
- [TCP ring buffer](https://github.com/mtcp-stack/mtcp/blob/master/mtcp/src/include/tcp_ring_buffer.h): `mtcp/src/include/tcp_ring_buffer.h`

### Packet I/O

- [PSIO library](https://github.com/mtcp-stack/mtcp/blob/master/io_engine/lib/pslib.c): `io_engine/lib/pslib.c`
- [PSIO NIC driver](https://github.com/mtcp-stack/mtcp/blob/master/io_engine/driver/ixgbe_main.c): `io_engine/driver/ixgbe_main.c`
- [Other I/O backends](https://github.com/mtcp-stack/mtcp/tree/master/mtcp/src): `mtcp/src`

### Runtime support

- [Network utilities](https://github.com/mtcp-stack/mtcp/blob/master/util/netlib.c): `util/netlib.c`

### Other components

- **Application user**

## Connections

- Application user → Ported lighttpd: configures (evidence: `README`)
- Application user → Apache benchmark: runs benchmark (evidence: `README`)
- Application user → Perf client: runs client (evidence: `apps/perf/client.c`)
- Ported lighttpd → mTCP API: uses sockets (evidence: `apps/lighttpd-1.4.32/src/server.c`)
- Apache benchmark → mTCP API: uses TCP
- Perf client → mTCP API: calls API (evidence: `apps/perf/client.c`)
- Ported lighttpd → HTTP authentication: delegates auth (evidence: `apps/lighttpd-1.4.32/src/http_auth.c`)
- Ported lighttpd → SSI expression parser: parses SSI
- mTCP API → Stack core: dispatches (evidence: `mtcp/src/core.c`)
- Stack core → TCP input: processes input (evidence: `mtcp/src/core.c`)
- Stack core → TCP output: processes output (evidence: `mtcp/src/core.c`)
- TCP input → TCP ring buffer: buffers data
- TCP input → Fragment queue: queues fragments
- Stack core → PSIO library: receives packets (evidence: `mtcp/src/core.c`)
- PSIO library → PSIO NIC driver: accesses driver (evidence: `io_engine/driver/ixgbe_main.c`)
- Stack core → Other I/O backends: selects backend (evidence: `README`)
- Perf client → Network utilities: uses helpers (evidence: `apps/perf/client.c`)
