# amazy2596/cs144 architecture

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

- Interactive diagram: https://gitdiagram.com/amazy2596/cs144
- Repository: https://github.com/amazy2596/cs144

## Overview

NetworkDIY is a CS144 Minnow networking-stack starter project, rather than a network service. Its principal runtime workflow lets an application exchange a byte stream over TCP/IP, with a TUN device connecting packets to the host network; the stack also includes Ethernet/ARP interface handling and IPv4 routing. The graph follows the documented send/receive flow and sampled implementations. Some integration links rely on repository architecture notes because the corresponding source excerpts are incomplete.

Main entry points: [`util/tcp_peer.hh`](https://github.com/amazy2596/cs144/blob/main/util/tcp_peer.hh) (TCP peer), [`apps/tcp_ipv4.cc`](https://github.com/amazy2596/cs144/blob/main/apps/tcp_ipv4.cc) (TCP IPv4 app), [`src/tcp_sender.cc`](https://github.com/amazy2596/cs144/blob/main/src/tcp_sender.cc) (TCP sender), [`src/tcp_receiver.cc`](https://github.com/amazy2596/cs144/blob/main/src/tcp_receiver.cc) (TCP receiver)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Applications"]
  node_tcp_app["TCP IPv4 app<br/>[tcp_ipv4.cc]"]
  node_stream_copy["Stream copier"]
end

subgraph group_tcp["TCP transport"]
  node_socket["Minnow socket"]
  node_peer["TCP peer<br/>[tcp_peer.hh]"]
  node_sender["TCP sender<br/>[tcp_sender.cc]"]
  node_receiver["TCP receiver<br/>[tcp_receiver.cc]"]
  node_reassembler["Stream reassembler<br/>[reassembler.cc]"]
  node_byte_stream["Byte stream<br/>[byte_stream.cc]"]
  node_seq_numbers["Sequence numbers"]
end

subgraph group_ip["IP and routing"]
  node_tcp_adapter["TCP over IP<br/>[tcp_over_ip.cc]"]
  node_tun_adapter["TUN adapter<br/>[tuntap_adapter.cc]"]
  node_tun["TUN device<br/>[tun.cc]"]
  node_router["IPv4 router<br/>[router.cc]"]
end

subgraph group_link["Link and runtime"]
  node_interface["Network interface"]
  node_arp["ARP messages<br/>[arp_message.cc]"]
  node_eventloop["Event loop<br/>[eventloop.cc]"]
end

node_user(("Application user"))
node_host_network(("Host network"))

node_user -->|"starts"| node_tcp_app
node_tcp_app -->|"connects or listens"| node_socket
node_tcp_app -->|"copies bytes"| node_stream_copy
node_stream_copy -->|"reads and writes"| node_socket
node_socket -->|"drives TCP"| node_peer
node_peer -->|"sends segments"| node_sender
node_peer -->|"processes segments"| node_receiver
node_receiver -->|"inserts payload"| node_reassembler
node_reassembler -->|"reassembles into"| node_byte_stream
node_sender -->|"reads outbound"| node_byte_stream
node_sender -->|"wraps sequence numbers"| node_seq_numbers
node_receiver -->|"unwraps sequence numbers"| node_seq_numbers
node_peer -->|"exchanges TCP messages"| node_tcp_adapter
node_tcp_adapter -->|"encapsulates in IPv4"| node_tun_adapter
node_tun_adapter -->|"reads and writes packets"| node_tun
node_tun -->|"exchanges packets"| node_host_network
node_eventloop -->|"dispatches I/O"| node_tun_adapter
node_router -->|"forwards datagrams"| node_interface
node_interface -->|"resolves next hop"| node_arp
node_interface -->|"receives datagrams"| node_router

click node_tcp_app "https://github.com/amazy2596/cs144/blob/main/apps/tcp_ipv4.cc"
click node_stream_copy "https://github.com/amazy2596/cs144/blob/main/apps/bidirectional_stream_copy.cc"
click node_socket "https://github.com/amazy2596/cs144/blob/main/src/tcp_minnow_socket.cc"
click node_peer "https://github.com/amazy2596/cs144/blob/main/util/tcp_peer.hh"
click node_sender "https://github.com/amazy2596/cs144/blob/main/src/tcp_sender.cc"
click node_receiver "https://github.com/amazy2596/cs144/blob/main/src/tcp_receiver.cc"
click node_reassembler "https://github.com/amazy2596/cs144/blob/main/src/reassembler.cc"
click node_byte_stream "https://github.com/amazy2596/cs144/blob/main/src/byte_stream.cc"
click node_seq_numbers "https://github.com/amazy2596/cs144/blob/main/src/wrapping_integers.cc"
click node_tcp_adapter "https://github.com/amazy2596/cs144/blob/main/util/tcp_over_ip.cc"
click node_tun_adapter "https://github.com/amazy2596/cs144/blob/main/util/tuntap_adapter.cc"
click node_tun "https://github.com/amazy2596/cs144/blob/main/util/tun.cc"
click node_router "https://github.com/amazy2596/cs144/blob/main/src/router.cc"
click node_interface "https://github.com/amazy2596/cs144/blob/main/src/network_interface.cc"
click node_arp "https://github.com/amazy2596/cs144/blob/main/util/arp_message.cc"
click node_eventloop "https://github.com/amazy2596/cs144/blob/main/util/eventloop.cc"

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_tcp_app,node_stream_copy,node_user toneBlue
class node_socket,node_peer,node_sender,node_receiver,node_reassembler,node_byte_stream,node_seq_numbers toneAmber
class node_tcp_adapter,node_tun_adapter,node_tun,node_router toneMint
class node_interface,node_arp,node_eventloop toneRose
class node_host_network toneIndigo
```

## Components

### Applications

- [TCP IPv4 app](https://github.com/amazy2596/cs144/blob/main/apps/tcp_ipv4.cc): `apps/tcp_ipv4.cc`
- [Stream copier](https://github.com/amazy2596/cs144/blob/main/apps/bidirectional_stream_copy.cc): `apps/bidirectional_stream_copy.cc`

### TCP transport

- [Minnow socket](https://github.com/amazy2596/cs144/blob/main/src/tcp_minnow_socket.cc): `src/tcp_minnow_socket.cc`
- [TCP peer](https://github.com/amazy2596/cs144/blob/main/util/tcp_peer.hh): `util/tcp_peer.hh`
- [TCP sender](https://github.com/amazy2596/cs144/blob/main/src/tcp_sender.cc): `src/tcp_sender.cc`
- [TCP receiver](https://github.com/amazy2596/cs144/blob/main/src/tcp_receiver.cc): `src/tcp_receiver.cc`
- [Stream reassembler](https://github.com/amazy2596/cs144/blob/main/src/reassembler.cc): `src/reassembler.cc`
- [Byte stream](https://github.com/amazy2596/cs144/blob/main/src/byte_stream.cc): `src/byte_stream.cc`
- [Sequence numbers](https://github.com/amazy2596/cs144/blob/main/src/wrapping_integers.cc): `src/wrapping_integers.cc`

### IP and routing

- [TCP over IP](https://github.com/amazy2596/cs144/blob/main/util/tcp_over_ip.cc): `util/tcp_over_ip.cc`
- [TUN adapter](https://github.com/amazy2596/cs144/blob/main/util/tuntap_adapter.cc): `util/tuntap_adapter.cc`
- [TUN device](https://github.com/amazy2596/cs144/blob/main/util/tun.cc): `util/tun.cc`
- [IPv4 router](https://github.com/amazy2596/cs144/blob/main/src/router.cc): `src/router.cc`

### Link and runtime

- [Network interface](https://github.com/amazy2596/cs144/blob/main/src/network_interface.cc): `src/network_interface.cc`
- [ARP messages](https://github.com/amazy2596/cs144/blob/main/util/arp_message.cc): `util/arp_message.cc`
- [Event loop](https://github.com/amazy2596/cs144/blob/main/util/eventloop.cc): `util/eventloop.cc`

### Other components

- **Application user**
- **Host network**

## Connections

- Application user → TCP IPv4 app: starts
- TCP IPv4 app → Minnow socket: connects or listens
- TCP IPv4 app → Stream copier: copies bytes
- Stream copier → Minnow socket: reads and writes
- Minnow socket → TCP peer: drives TCP
- TCP peer → TCP sender: sends segments
- TCP peer → TCP receiver: processes segments
- TCP receiver → Stream reassembler: inserts payload
- Stream reassembler → Byte stream: reassembles into
- TCP sender → Byte stream: reads outbound
- TCP sender → Sequence numbers: wraps sequence numbers
- TCP receiver → Sequence numbers: unwraps sequence numbers
- TCP peer → TCP over IP: exchanges TCP messages
- TCP over IP → TUN adapter: encapsulates in IPv4
- TUN adapter → TUN device: reads and writes packets
- TUN device → Host network: exchanges packets
- Event loop → TUN adapter: dispatches I/O
- IPv4 router → Network interface: forwards datagrams
- Network interface → ARP messages: resolves next hop
- Network interface → IPv4 router: receives datagrams
