# rohit267/net-merge architecture

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

- Interactive diagram: https://gitdiagram.com/rohit267/net-merge
- Repository: https://github.com/rohit267/net-merge

## Overview

net-merge combines network adapters by assigning each new flow to a link, with system-wide TUN operation as its primary mode and an optional SOCKS5 front end. The CLI starts and monitors the runtime; adapter discovery and probing inform the scheduler, which the balancer uses to dial and relay traffic. A tray provides status and pause/quit controls through shared state. Platform-specific TUN setup and README-described platform support are represented, but unsampled implementation details are not inferred; optional or undocumented links are omitted.

Main entry points: [`cmd/net-merge/main.go`](https://github.com/rohit267/net-merge/blob/main/cmd/net-merge/main.go) (CLI runtime), [`internal/engine/balancer.go`](https://github.com/rohit267/net-merge/blob/main/internal/engine/balancer.go) (Flow balancer), [`internal/tun/tun.go`](https://github.com/rohit267/net-merge/blob/main/internal/tun/tun.go) (System TUN), [`internal/tray/tray.go`](https://github.com/rohit267/net-merge/blob/main/internal/tray/tray.go) (Tray controls)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime and control"]
  node_cli["CLI runtime<br/>[main.go]"]
end

subgraph group_network["Link selection"]
  node_discovery["Adapter discovery<br/>[nics.go]"]
  node_telemetry["Link counters<br/>[counters_linux.go]"]
  node_probe["Internet probes<br/>[probe.go]"]
  node_scheduler["Flow scheduler<br/>[sched.go]"]
end

subgraph group_traffic["Traffic handling"]
  node_balancer["Flow balancer<br/>[balancer.go]"]
  node_relay["Flow relay<br/>[flowconn.go]"]
  node_tun["System TUN<br/>[tun.go]"]
  node_forward["Packet forwarding<br/>[forward.go]"]
  node_socks["SOCKS5 endpoint<br/>[socks5.go]"]
end

subgraph group_ui["Tray and state"]
  node_tray["Tray controls<br/>[tray.go]"]
  node_icon["Tray icon art<br/>[icon.go]"]
  node_state["Status and controls<br/>[state.go]"]
end

subgraph group_platform["Platform support"]
  node_osroutes["TUN route setup<br/>[tun_darwin.go]"]
  node_platform["Platform services<br/>[platform_linux.go]"]
  node_autostart["Login autostart<br/>[autostart_linux.go]"]
end

node_user(("User"))
node_externalnet(("Network adapters"))

node_user -->|"starts or controls"| node_cli
node_cli -->|"scans adapters"| node_discovery
node_cli -->|"updates and ticks"| node_scheduler
node_cli -->|"starts probes"| node_probe
node_discovery -.->|"reads interfaces"| node_externalnet
node_cli -->|"boots runtime"| node_balancer
node_balancer -->|"acquires links"| node_scheduler
node_balancer -->|"relays flows"| node_relay
node_balancer -->|"pins egress"| node_discovery
node_cli -->|"starts system mode"| node_tun
node_tun -->|"installs forwarders"| node_forward
node_tun -->|"sets proxy"| node_balancer
node_tun -->|"configures routes"| node_osroutes
node_cli -->|"serves SOCKS5"| node_socks
node_cli -->|"writes status"| node_state
node_tray -->|"reads controls"| node_state
node_tray -->|"toggles merging"| node_tun
node_tray -->|"uses icons"| node_icon
node_tray -->|"shows link stats"| node_scheduler
node_cli -->|"checks driver"| node_platform
node_user -->|"enables login start"| node_autostart
node_telemetry -.->|"measures links"| node_scheduler

click node_cli "https://github.com/rohit267/net-merge/blob/main/cmd/net-merge/main.go"
click node_discovery "https://github.com/rohit267/net-merge/blob/main/internal/nics/nics.go"
click node_telemetry "https://github.com/rohit267/net-merge/blob/main/internal/nics/counters_linux.go"
click node_probe "https://github.com/rohit267/net-merge/blob/main/internal/engine/probe.go"
click node_scheduler "https://github.com/rohit267/net-merge/blob/main/internal/engine/sched.go"
click node_balancer "https://github.com/rohit267/net-merge/blob/main/internal/engine/balancer.go"
click node_relay "https://github.com/rohit267/net-merge/blob/main/internal/engine/flowconn.go"
click node_tun "https://github.com/rohit267/net-merge/blob/main/internal/tun/tun.go"
click node_forward "https://github.com/rohit267/net-merge/blob/main/internal/tun/forward.go"
click node_osroutes "https://github.com/rohit267/net-merge/blob/main/internal/tun/tun_darwin.go"
click node_socks "https://github.com/rohit267/net-merge/blob/main/internal/engine/socks5.go"
click node_tray "https://github.com/rohit267/net-merge/blob/main/internal/tray/tray.go"
click node_icon "https://github.com/rohit267/net-merge/blob/main/internal/icon/icon.go"
click node_state "https://github.com/rohit267/net-merge/blob/main/internal/state/state.go"
click node_platform "https://github.com/rohit267/net-merge/blob/main/internal/platform/platform_linux.go"
click node_autostart "https://github.com/rohit267/net-merge/blob/main/internal/platform/autostart_linux.go"

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_cli,node_user toneBlue
class node_discovery,node_telemetry,node_probe,node_scheduler toneAmber
class node_balancer,node_relay,node_tun,node_forward,node_socks toneMint
class node_tray,node_icon,node_state toneRose
class node_osroutes,node_platform,node_autostart,node_externalnet toneIndigo
```

## Components

### Runtime and control

- [CLI runtime](https://github.com/rohit267/net-merge/blob/main/cmd/net-merge/main.go): `cmd/net-merge/main.go`

### Link selection

- [Adapter discovery](https://github.com/rohit267/net-merge/blob/main/internal/nics/nics.go): `internal/nics/nics.go`
- [Link counters](https://github.com/rohit267/net-merge/blob/main/internal/nics/counters_linux.go): `internal/nics/counters_linux.go`
- [Internet probes](https://github.com/rohit267/net-merge/blob/main/internal/engine/probe.go): `internal/engine/probe.go`
- [Flow scheduler](https://github.com/rohit267/net-merge/blob/main/internal/engine/sched.go): `internal/engine/sched.go`

### Traffic handling

- [Flow balancer](https://github.com/rohit267/net-merge/blob/main/internal/engine/balancer.go): `internal/engine/balancer.go`
- [Flow relay](https://github.com/rohit267/net-merge/blob/main/internal/engine/flowconn.go): `internal/engine/flowconn.go`
- [System TUN](https://github.com/rohit267/net-merge/blob/main/internal/tun/tun.go): `internal/tun/tun.go`
- [Packet forwarding](https://github.com/rohit267/net-merge/blob/main/internal/tun/forward.go): `internal/tun/forward.go`
- [SOCKS5 endpoint](https://github.com/rohit267/net-merge/blob/main/internal/engine/socks5.go): `internal/engine/socks5.go`

### Tray and state

- [Tray controls](https://github.com/rohit267/net-merge/blob/main/internal/tray/tray.go): `internal/tray/tray.go`
- [Tray icon art](https://github.com/rohit267/net-merge/blob/main/internal/icon/icon.go): `internal/icon/icon.go`
- [Status and controls](https://github.com/rohit267/net-merge/blob/main/internal/state/state.go): `internal/state/state.go`

### Platform support

- [TUN route setup](https://github.com/rohit267/net-merge/blob/main/internal/tun/tun_darwin.go): `internal/tun/tun_darwin.go`
- [Platform services](https://github.com/rohit267/net-merge/blob/main/internal/platform/platform_linux.go): `internal/platform/platform_linux.go`
- [Login autostart](https://github.com/rohit267/net-merge/blob/main/internal/platform/autostart_linux.go): `internal/platform/autostart_linux.go`

### Other components

- **User**
- **Network adapters**

## Connections

- User → CLI runtime: starts or controls (evidence: `README.md`)
- CLI runtime → Adapter discovery: scans adapters (evidence: `cmd/net-merge/main.go`)
- CLI runtime → Flow scheduler: updates and ticks (evidence: `cmd/net-merge/main.go`)
- CLI runtime → Internet probes: starts probes (evidence: `cmd/net-merge/main.go`)
- Adapter discovery → Network adapters: reads interfaces
- CLI runtime → Flow balancer: boots runtime (evidence: `cmd/net-merge/main.go`)
- Flow balancer → Flow scheduler: acquires links (evidence: `internal/engine/balancer.go`)
- Flow balancer → Flow relay: relays flows (evidence: `internal/engine/balancer.go`)
- Flow balancer → Adapter discovery: pins egress (evidence: `internal/engine/balancer.go`)
- CLI runtime → System TUN: starts system mode (evidence: `README.md`)
- System TUN → Packet forwarding: installs forwarders (evidence: `internal/tun/tun.go`)
- System TUN → Flow balancer: sets proxy (evidence: `internal/tun/tun.go`)
- System TUN → TUN route setup: configures routes (evidence: `internal/tun/tun_darwin.go`)
- CLI runtime → SOCKS5 endpoint: serves SOCKS5 (evidence: `cmd/net-merge/main.go`)
- CLI runtime → Status and controls: writes status (evidence: `cmd/net-merge/main.go`)
- Tray controls → Status and controls: reads controls (evidence: `internal/tray/tray.go`)
- Tray controls → System TUN: toggles merging (evidence: `internal/tray/tray.go`)
- Tray controls → Tray icon art: uses icons (evidence: `internal/tray/tray.go`)
- Tray controls → Flow scheduler: shows link stats (evidence: `internal/tray/tray.go`)
- CLI runtime → Platform services: checks driver (evidence: `cmd/net-merge/main.go`)
- User → Login autostart: enables login start (evidence: `README.md`)
- Link counters → Flow scheduler: measures links
