# zzdragon-158/taplan2 architecture

> Architecture diagram of the GitHub repository zzdragon-158/taplan2, 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/zzdragon-158/taplan2
- Repository: https://github.com/zzdragon-158/taplan2

## Overview

TapLan creates a virtual IPv4 LAN over direct IPv6-reachable links, with Windows and Linux support. The main workflow parses settings, initializes a TAP device and UDP transport, then moves Ethernet frames between the TAP interface and remote peers. In server/client mode, NodeMgr uses TCP synchronization to allocate client addresses and distribute peer state; in --nosync mode, traffic goes directly to the configured peer. Optional asynchronous I/O changes the I/O implementation, while port cycling can vary UDP source ports. The graph reflects the README and sampled source; some runtime wiring is inferred only where those sources explicitly document it.

Main entry points: [`src/TapLan.cpp`](https://github.com/zzdragon-158/taplan2/blob/main/src/TapLan.cpp) (LAN coordinator), [`src/main.cpp`](https://github.com/zzdragon-158/taplan2/blob/main/src/main.cpp) (CLI and runtime), [`src/NodeMgr.cpp`](https://github.com/zzdragon-158/taplan2/blob/main/src/NodeMgr.cpp) (Node registry), [`src/BsdSock.cpp`](https://github.com/zzdragon-158/taplan2/blob/main/src/BsdSock.cpp) (UDP transport)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application"]
  node_main["CLI and runtime<br/>[main.cpp]"]
  node_config["Runtime config<br/>[Config.cpp]"]
  node_taplan["LAN coordinator<br/>[TapLan.cpp]"]
end

subgraph group_network["Peer Networking"]
  node_nodes["Node registry<br/>[NodeMgr.cpp]"]
  node_tcp["TCP sync socket<br/>[BsdSock.cpp]"]
  node_udp["UDP transport<br/>[BsdSock.cpp]"]
  node_fib[("Peer and address state<br/>[NodeMgr.cpp]")]
end

subgraph group_io["Packet I/O"]
  node_linuxio["Linux I/O<br/>[UioIntfLinux.cpp]"]
  node_winio["Windows I/O<br/>[UioIntfWin.cpp]"]
end

subgraph group_platform["Platform Services"]
  node_tap["Virtual TAP device<br/>[TapDevLinux.cpp]"]
  node_logger["Logging<br/>[LogMgr.cpp]"]
end

node_user(("Operator"))
node_peer(("Remote TapLan peers"))

node_user -->|"starts"| node_main
node_main -->|"parses options"| node_config
node_main -->|"starts logging"| node_logger
node_main -->|"starts runtime"| node_taplan
node_taplan -->|"reads settings"| node_config
node_taplan -->|"opens device"| node_tap
node_taplan -->|"creates sockets"| node_udp
node_taplan -->|"starts sync"| node_nodes
node_nodes -->|"connects and listens"| node_tcp
node_nodes -->|"syncs node state"| node_peer
node_nodes -->|"updates"| node_fib
node_taplan -->|"reads peer routes"| node_fib
node_tap -->|"supplies frames"| node_linuxio
node_linuxio -->|"delivers frames"| node_taplan
node_taplan -->|"requests I/O"| node_linuxio
node_taplan -.->|"requests I/O"| node_winio
node_winio -.->|"reads and writes"| node_tap
node_taplan -->|"sends and receives"| node_udp
node_udp -->|"exchanges frames"| node_peer
node_peer -->|"returns frames"| node_udp
node_taplan -->|"reports status"| node_logger
node_main -->|"shows node status"| node_nodes

click node_main "https://github.com/zzdragon-158/taplan2/blob/main/src/main.cpp"
click node_config "https://github.com/zzdragon-158/taplan2/blob/main/src/Config.cpp"
click node_taplan "https://github.com/zzdragon-158/taplan2/blob/main/src/TapLan.cpp"
click node_nodes "https://github.com/zzdragon-158/taplan2/blob/main/src/NodeMgr.cpp"
click node_tcp "https://github.com/zzdragon-158/taplan2/blob/main/src/BsdSock.cpp"
click node_udp "https://github.com/zzdragon-158/taplan2/blob/main/src/BsdSock.cpp"
click node_tap "https://github.com/zzdragon-158/taplan2/blob/main/src/TapDevLinux.cpp"
click node_linuxio "https://github.com/zzdragon-158/taplan2/blob/main/src/UioIntfLinux.cpp"
click node_winio "https://github.com/zzdragon-158/taplan2/blob/main/src/UioIntfWin.cpp"
click node_logger "https://github.com/zzdragon-158/taplan2/blob/main/src/LogMgr.cpp"
click node_fib "https://github.com/zzdragon-158/taplan2/blob/main/src/NodeMgr.cpp"

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_main,node_config,node_taplan toneBlue
class node_nodes,node_tcp,node_udp,node_fib toneAmber
class node_linuxio,node_winio toneMint
class node_tap,node_logger toneRose
class node_user,node_peer toneIndigo
```

## Components

### Application

- [CLI and runtime](https://github.com/zzdragon-158/taplan2/blob/main/src/main.cpp): `src/main.cpp`
- [Runtime config](https://github.com/zzdragon-158/taplan2/blob/main/src/Config.cpp): `src/Config.cpp`
- [LAN coordinator](https://github.com/zzdragon-158/taplan2/blob/main/src/TapLan.cpp): `src/TapLan.cpp`

### Peer Networking

- [Node registry](https://github.com/zzdragon-158/taplan2/blob/main/src/NodeMgr.cpp): `src/NodeMgr.cpp`
- [TCP sync socket](https://github.com/zzdragon-158/taplan2/blob/main/src/BsdSock.cpp): `src/BsdSock.cpp`
- [UDP transport](https://github.com/zzdragon-158/taplan2/blob/main/src/BsdSock.cpp): `src/BsdSock.cpp`
- [Peer and address state](https://github.com/zzdragon-158/taplan2/blob/main/src/NodeMgr.cpp): `src/NodeMgr.cpp`

### Packet I/O

- [Linux I/O](https://github.com/zzdragon-158/taplan2/blob/main/src/UioIntfLinux.cpp): `src/UioIntfLinux.cpp`
- [Windows I/O](https://github.com/zzdragon-158/taplan2/blob/main/src/UioIntfWin.cpp): `src/UioIntfWin.cpp`

### Platform Services

- [Virtual TAP device](https://github.com/zzdragon-158/taplan2/blob/main/src/TapDevLinux.cpp): `src/TapDevLinux.cpp`
- [Logging](https://github.com/zzdragon-158/taplan2/blob/main/src/LogMgr.cpp): `src/LogMgr.cpp`

### Other components

- **Operator**
- **Remote TapLan peers**

## Connections

- Operator → CLI and runtime: starts
- CLI and runtime → Runtime config: parses options
- CLI and runtime → Logging: starts logging
- CLI and runtime → LAN coordinator: starts runtime
- LAN coordinator → Runtime config: reads settings
- LAN coordinator → Virtual TAP device: opens device
- LAN coordinator → UDP transport: creates sockets
- LAN coordinator → Node registry: starts sync
- Node registry → TCP sync socket: connects and listens
- Node registry → Remote TapLan peers: syncs node state
- Node registry → Peer and address state: updates
- LAN coordinator → Peer and address state: reads peer routes
- Virtual TAP device → Linux I/O: supplies frames
- Linux I/O → LAN coordinator: delivers frames
- LAN coordinator → Linux I/O: requests I/O
- LAN coordinator → Windows I/O: requests I/O
- Windows I/O → Virtual TAP device: reads and writes
- LAN coordinator → UDP transport: sends and receives
- UDP transport → Remote TapLan peers: exchanges frames
- Remote TapLan peers → UDP transport: returns frames
- LAN coordinator → Logging: reports status
- CLI and runtime → Node registry: shows node status
