# txthinking/brook architecture

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

- Interactive diagram: https://gitdiagram.com/txthinking/brook
- Repository: https://github.com/txthinking/brook

## Overview

Brook is a cross-platform programmable network tool for forwarding network traffic through proxy clients, servers, relays, and DNS services. Its user-facing workflow is to invoke a CLI mode, accept local proxy or service traffic, carry it over a selected transport, and forward it to a destination. The graph preserves major protocol and DNS branches visible in the tree; several services and plugin links are necessarily tentative because their CLI wiring or implementation was not excerpted.

Main entry points: [`cli/brook/main.go`](https://github.com/txthinking/brook/blob/master/cli/brook/main.go) (Brook CLI), [`client.go`](https://github.com/txthinking/brook/blob/master/client.go) (SOCKS client), [`brooklink.go`](https://github.com/txthinking/brook/blob/master/brooklink.go) (Brook links), [`streamclient.go`](https://github.com/txthinking/brook/blob/master/streamclient.go) (Stream framing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI and links"]
  node_cli["Brook CLI<br/>[main.go]"]
  node_link["Brook links<br/>[brooklink.go]"]
end

subgraph group_proxy["Proxy endpoints"]
  node_client["SOCKS client<br/>[client.go]"]
  node_server["Brook server<br/>[server.go]"]
end

subgraph group_transport["Transport protocols"]
  node_quicclient["QUIC client<br/>[quicclient.go]"]
  node_quicserver["QUIC server<br/>[quicserver.go]"]
  node_wsclient["WebSocket client<br/>[wsclient.go]"]
  node_wsserver["WebSocket server<br/>[wsserver.go]"]
  node_stream["Stream framing<br/>[streamclient.go]"]
  node_packet["Packet framing<br/>[packetclient.go]"]
end

subgraph group_dns["DNS services"]
  node_dnsclient["DNS client<br/>[dnsclient.go]"]
  node_dnsserver["DNS server<br/>[dnsserver.go]"]
  node_dohclient["DoH client<br/>[dohclient.go]"]
  node_dohserver["DoH server<br/>[dohserver.go]"]
  node_dhcp["DHCP server<br/>[dhcpserver.go]"]
end

subgraph group_forward["Forwarding and extensions"]
  node_relay["Direct relay<br/>[relay.go]"]
  node_brookrelay["Brook relay<br/>[relayoverbrook.go]"]
  node_plugins["Network plugins"]
end

node_user(("Operator"))
node_destination(("Network destination"))

node_user -->|"invokes"| node_cli
node_cli -->|"parses links"| node_link
node_cli -->|"starts relay"| node_brookrelay
node_cli -.->|"starts service"| node_server
node_cli -.->|"starts proxy"| node_client
node_link -->|"creates exchanger"| node_stream
node_link -->|"creates exchanger"| node_packet
node_client -->|"frames TCP"| node_stream
node_client -->|"frames UDP"| node_packet
node_client -->|"forwards traffic"| node_destination
node_quicclient -->|"frames streams"| node_stream
node_quicclient -->|"tunnels traffic"| node_destination
node_wsclient -->|"frames streams"| node_stream
node_wsclient -->|"tunnels traffic"| node_destination
node_server -->|"forwards traffic"| node_destination
node_quicserver -->|"forwards traffic"| node_destination
node_wsserver -->|"forwards traffic"| node_destination
node_relay -->|"relays traffic"| node_destination
node_brookrelay -->|"creates exchanger"| node_link
node_brookrelay -->|"relays traffic"| node_destination
node_dohserver -->|"queries DNS"| node_dnsclient
node_dohserver -->|"queries DoH"| node_dohclient
node_dnsclient -.->|"resolves names"| node_destination
node_dohclient -.->|"queries upstream"| node_destination
node_cli -.->|"configures service"| node_dnsserver
node_cli -.->|"configures service"| node_dohserver
node_cli -.->|"configures service"| node_dhcp
node_cli -->|"registers plugins"| node_plugins

click node_cli "https://github.com/txthinking/brook/blob/master/cli/brook/main.go"
click node_link "https://github.com/txthinking/brook/blob/master/brooklink.go"
click node_client "https://github.com/txthinking/brook/blob/master/client.go"
click node_server "https://github.com/txthinking/brook/blob/master/server.go"
click node_quicclient "https://github.com/txthinking/brook/blob/master/quicclient.go"
click node_quicserver "https://github.com/txthinking/brook/blob/master/quicserver.go"
click node_wsclient "https://github.com/txthinking/brook/blob/master/wsclient.go"
click node_wsserver "https://github.com/txthinking/brook/blob/master/wsserver.go"
click node_stream "https://github.com/txthinking/brook/blob/master/streamclient.go"
click node_packet "https://github.com/txthinking/brook/blob/master/packetclient.go"
click node_relay "https://github.com/txthinking/brook/blob/master/relay.go"
click node_brookrelay "https://github.com/txthinking/brook/blob/master/relayoverbrook.go"
click node_plugins "https://github.com/txthinking/brook/tree/master/plugins"
click node_dnsclient "https://github.com/txthinking/brook/blob/master/dnsclient.go"
click node_dnsserver "https://github.com/txthinking/brook/blob/master/dnsserver.go"
click node_dohclient "https://github.com/txthinking/brook/blob/master/dohclient.go"
click node_dohserver "https://github.com/txthinking/brook/blob/master/dohserver.go"
click node_dhcp "https://github.com/txthinking/brook/blob/master/dhcpserver.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_link toneBlue
class node_client,node_server toneAmber
class node_quicclient,node_quicserver,node_wsclient,node_wsserver,node_stream,node_packet toneMint
class node_dnsclient,node_dnsserver,node_dohclient,node_dohserver,node_dhcp toneRose
class node_relay,node_brookrelay,node_plugins,node_user,node_destination toneIndigo
```

## Components

### CLI and links

- [Brook CLI](https://github.com/txthinking/brook/blob/master/cli/brook/main.go): `cli/brook/main.go`
- [Brook links](https://github.com/txthinking/brook/blob/master/brooklink.go): `brooklink.go`

### Proxy endpoints

- [SOCKS client](https://github.com/txthinking/brook/blob/master/client.go): `client.go`
- [Brook server](https://github.com/txthinking/brook/blob/master/server.go): `server.go`

### Transport protocols

- [QUIC client](https://github.com/txthinking/brook/blob/master/quicclient.go): `quicclient.go`
- [QUIC server](https://github.com/txthinking/brook/blob/master/quicserver.go): `quicserver.go`
- [WebSocket client](https://github.com/txthinking/brook/blob/master/wsclient.go): `wsclient.go`
- [WebSocket server](https://github.com/txthinking/brook/blob/master/wsserver.go): `wsserver.go`
- [Stream framing](https://github.com/txthinking/brook/blob/master/streamclient.go): `streamclient.go`
- [Packet framing](https://github.com/txthinking/brook/blob/master/packetclient.go): `packetclient.go`

### DNS services

- [DNS client](https://github.com/txthinking/brook/blob/master/dnsclient.go): `dnsclient.go`
- [DNS server](https://github.com/txthinking/brook/blob/master/dnsserver.go): `dnsserver.go`
- [DoH client](https://github.com/txthinking/brook/blob/master/dohclient.go): `dohclient.go`
- [DoH server](https://github.com/txthinking/brook/blob/master/dohserver.go): `dohserver.go`
- [DHCP server](https://github.com/txthinking/brook/blob/master/dhcpserver.go): `dhcpserver.go`

### Forwarding and extensions

- [Direct relay](https://github.com/txthinking/brook/blob/master/relay.go): `relay.go`
- [Brook relay](https://github.com/txthinking/brook/blob/master/relayoverbrook.go): `relayoverbrook.go`
- [Network plugins](https://github.com/txthinking/brook/tree/master/plugins): `plugins`

### Other components

- **Operator**
- **Network destination**

## Connections

- Operator → Brook CLI: invokes (evidence: `README.md`)
- Brook CLI → Brook links: parses links (evidence: `cli/brook/main.go`)
- Brook CLI → Brook relay: starts relay (evidence: `cli/brook/main.go`)
- Brook CLI → Brook server: starts service
- Brook CLI → SOCKS client: starts proxy
- Brook links → Stream framing: creates exchanger (evidence: `brooklink.go`)
- Brook links → Packet framing: creates exchanger (evidence: `brooklink.go`)
- SOCKS client → Stream framing: frames TCP (evidence: `client.go`)
- SOCKS client → Packet framing: frames UDP (evidence: `client.go`)
- SOCKS client → Network destination: forwards traffic (evidence: `client.go`)
- QUIC client → Stream framing: frames streams (evidence: `quicclient.go`)
- QUIC client → Network destination: tunnels traffic (evidence: `quicclient.go`)
- WebSocket client → Stream framing: frames streams (evidence: `wsclient.go`)
- WebSocket client → Network destination: tunnels traffic (evidence: `wsclient.go`)
- Brook server → Network destination: forwards traffic (evidence: `server.go`)
- QUIC server → Network destination: forwards traffic (evidence: `quicserver.go`)
- WebSocket server → Network destination: forwards traffic (evidence: `wsserver.go`)
- Direct relay → Network destination: relays traffic (evidence: `relay.go`)
- Brook relay → Brook links: creates exchanger (evidence: `relayoverbrook.go`)
- Brook relay → Network destination: relays traffic (evidence: `relayoverbrook.go`)
- DoH server → DNS client: queries DNS (evidence: `dohserver.go`)
- DoH server → DoH client: queries DoH (evidence: `dohserver.go`)
- DNS client → Network destination: resolves names
- DoH client → Network destination: queries upstream
- Brook CLI → DNS server: configures service
- Brook CLI → DoH server: configures service
- Brook CLI → DHCP server: configures service
- Brook CLI → Network plugins: registers plugins (evidence: `cli/brook/main.go`)
