# imsnif/bandwhich architecture

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

- Interactive diagram: https://gitdiagram.com/imsnif/bandwhich
- Repository: https://github.com/imsnif/bandwhich

## Overview

bandwhich is a CLI network-utilization monitor: users select an interface and output options, then it captures traffic, associates connections with processes, optionally resolves remote IPs, and presents live or raw bandwidth summaries. The graph preserves the documented DNS, platform-specific socket lookup, and terminal-display capabilities. Some orchestration and display wiring is unsampled; dashed edges mark relationships not directly shown in the excerpts.

Main entry points: [`src/display/ui.rs`](https://github.com/imsnif/bandwhich/blob/main/src/display/ui.rs) (Terminal and raw UI), [`src/main.rs`](https://github.com/imsnif/bandwhich/blob/main/src/main.rs) (Monitor runtime), [`src/os/shared.rs`](https://github.com/imsnif/bandwhich/blob/main/src/os/shared.rs) (Input setup), [`src/network/sniffer.rs`](https://github.com/imsnif/bandwhich/blob/main/src/network/sniffer.rs) (Packet capture)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI and orchestration"]
  node_options["CLI options<br/>[cli.rs]"]
  node_runtime["Monitor runtime<br/>[main.rs]"]
end

subgraph group_capture["Traffic and process data"]
  node_input["Input setup<br/>[shared.rs]"]
  node_packet["Packet capture<br/>[sniffer.rs]"]
  node_connection["Connection model<br/>[connection.rs]"]
  node_utilization["Traffic utilization<br/>[utilization.rs]"]
  node_socket_map["Socket lookup<br/>[shared.rs]"]
  node_linux["Linux sockets<br/>[linux.rs]"]
  node_lsof["lsof socket lookup<br/>[lsof.rs]"]
  node_lsof_utils["lsof parsing<br/>[lsof_utils.rs]"]
  node_windows["Windows sockets<br/>[windows.rs]"]
end

subgraph group_names["Address resolution"]
  node_dns_setup["DNS setup<br/>[shared.rs]"]
  node_resolver["Reverse resolver<br/>[resolver.rs]"]
  node_dns_client["DNS client<br/>[client.rs]"]
end

subgraph group_display["State and presentation"]
  node_ui_state["Bandwidth state<br/>[ui_state.rs]"]
  node_ui["Terminal and raw UI<br/>[ui.rs]"]
  node_bandwidth["Bandwidth display"]
  node_headers["Header details<br/>[header_details.rs]"]
  node_layout["Responsive layout<br/>[layout.rs]"]
  node_tables["Summary tables<br/>[table.rs]"]
  node_help["Help text<br/>[help_text.rs]"]
end

node_user(("CLI user"))

node_user -->|"sets options"| node_options
node_options -->|"configures"| node_runtime
node_runtime -.->|"starts input"| node_input
node_input -.->|"opens capture"| node_packet
node_packet -->|"identifies flows"| node_connection
node_packet -.->|"reports traffic"| node_utilization
node_input -->|"provides lookup"| node_socket_map
node_socket_map -->|"dispatches on Linux"| node_linux
node_socket_map -->|"dispatches on macOS"| node_lsof
node_lsof -->|"uses parsing"| node_lsof_utils
node_socket_map -->|"dispatches on Windows"| node_windows
node_input -->|"initializes DNS"| node_dns_setup
node_dns_setup -->|"creates client"| node_dns_client
node_dns_client -->|"calls lookup"| node_resolver
node_runtime -->|"requests names"| node_dns_client
node_runtime -->|"updates state"| node_ui_state
node_runtime -->|"drives display"| node_ui
node_ui -.->|"reads state"| node_ui_state
node_ui -.->|"renders bandwidth"| node_bandwidth
node_ui -.->|"renders headers"| node_headers
node_ui -.->|"uses layout"| node_layout
node_ui -.->|"renders tables"| node_tables
node_ui -.->|"renders help"| node_help

click node_options "https://github.com/imsnif/bandwhich/blob/main/src/cli.rs"
click node_runtime "https://github.com/imsnif/bandwhich/blob/main/src/main.rs"
click node_input "https://github.com/imsnif/bandwhich/blob/main/src/os/shared.rs"
click node_packet "https://github.com/imsnif/bandwhich/blob/main/src/network/sniffer.rs"
click node_connection "https://github.com/imsnif/bandwhich/blob/main/src/network/connection.rs"
click node_utilization "https://github.com/imsnif/bandwhich/blob/main/src/network/utilization.rs"
click node_socket_map "https://github.com/imsnif/bandwhich/blob/main/src/os/shared.rs"
click node_linux "https://github.com/imsnif/bandwhich/blob/main/src/os/linux.rs"
click node_lsof "https://github.com/imsnif/bandwhich/blob/main/src/os/lsof.rs"
click node_lsof_utils "https://github.com/imsnif/bandwhich/blob/main/src/os/lsof_utils.rs"
click node_windows "https://github.com/imsnif/bandwhich/blob/main/src/os/windows.rs"
click node_dns_setup "https://github.com/imsnif/bandwhich/blob/main/src/os/shared.rs"
click node_resolver "https://github.com/imsnif/bandwhich/blob/main/src/network/dns/resolver.rs"
click node_dns_client "https://github.com/imsnif/bandwhich/blob/main/src/network/dns/client.rs"
click node_ui_state "https://github.com/imsnif/bandwhich/blob/main/src/display/ui_state.rs"
click node_ui "https://github.com/imsnif/bandwhich/blob/main/src/display/ui.rs"
click node_bandwidth "https://github.com/imsnif/bandwhich/blob/main/src/display/components/display_bandwidth.rs"
click node_headers "https://github.com/imsnif/bandwhich/blob/main/src/display/components/header_details.rs"
click node_layout "https://github.com/imsnif/bandwhich/blob/main/src/display/components/layout.rs"
click node_tables "https://github.com/imsnif/bandwhich/blob/main/src/display/components/table.rs"
click node_help "https://github.com/imsnif/bandwhich/blob/main/src/display/components/help_text.rs"

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_options,node_runtime,node_user toneBlue
class node_input,node_packet,node_connection,node_utilization,node_socket_map,node_linux,node_lsof,node_lsof_utils,node_windows toneAmber
class node_dns_setup,node_resolver,node_dns_client toneMint
class node_ui_state,node_ui,node_bandwidth,node_headers,node_layout,node_tables,node_help toneRose
```

## Components

### CLI and orchestration

- [CLI options](https://github.com/imsnif/bandwhich/blob/main/src/cli.rs): `src/cli.rs`
- [Monitor runtime](https://github.com/imsnif/bandwhich/blob/main/src/main.rs): `src/main.rs`

### Traffic and process data

- [Input setup](https://github.com/imsnif/bandwhich/blob/main/src/os/shared.rs): `src/os/shared.rs`
- [Packet capture](https://github.com/imsnif/bandwhich/blob/main/src/network/sniffer.rs): `src/network/sniffer.rs`
- [Connection model](https://github.com/imsnif/bandwhich/blob/main/src/network/connection.rs): `src/network/connection.rs`
- [Traffic utilization](https://github.com/imsnif/bandwhich/blob/main/src/network/utilization.rs): `src/network/utilization.rs`
- [Socket lookup](https://github.com/imsnif/bandwhich/blob/main/src/os/shared.rs): `src/os/shared.rs`
- [Linux sockets](https://github.com/imsnif/bandwhich/blob/main/src/os/linux.rs): `src/os/linux.rs`
- [lsof socket lookup](https://github.com/imsnif/bandwhich/blob/main/src/os/lsof.rs): `src/os/lsof.rs`
- [lsof parsing](https://github.com/imsnif/bandwhich/blob/main/src/os/lsof_utils.rs): `src/os/lsof_utils.rs`
- [Windows sockets](https://github.com/imsnif/bandwhich/blob/main/src/os/windows.rs): `src/os/windows.rs`

### Address resolution

- [DNS setup](https://github.com/imsnif/bandwhich/blob/main/src/os/shared.rs): `src/os/shared.rs`
- [Reverse resolver](https://github.com/imsnif/bandwhich/blob/main/src/network/dns/resolver.rs): `src/network/dns/resolver.rs`
- [DNS client](https://github.com/imsnif/bandwhich/blob/main/src/network/dns/client.rs): `src/network/dns/client.rs`

### State and presentation

- [Bandwidth state](https://github.com/imsnif/bandwhich/blob/main/src/display/ui_state.rs): `src/display/ui_state.rs`
- [Terminal and raw UI](https://github.com/imsnif/bandwhich/blob/main/src/display/ui.rs): `src/display/ui.rs`
- [Bandwidth display](https://github.com/imsnif/bandwhich/blob/main/src/display/components/display_bandwidth.rs): `src/display/components/display_bandwidth.rs`
- [Header details](https://github.com/imsnif/bandwhich/blob/main/src/display/components/header_details.rs): `src/display/components/header_details.rs`
- [Responsive layout](https://github.com/imsnif/bandwhich/blob/main/src/display/components/layout.rs): `src/display/components/layout.rs`
- [Summary tables](https://github.com/imsnif/bandwhich/blob/main/src/display/components/table.rs): `src/display/components/table.rs`
- [Help text](https://github.com/imsnif/bandwhich/blob/main/src/display/components/help_text.rs): `src/display/components/help_text.rs`

### Other components

- **CLI user**

## Connections

- CLI user → CLI options: sets options (evidence: `README.md`)
- CLI options → Monitor runtime: configures (evidence: `src/main.rs`)
- Monitor runtime → Input setup: starts input
- Input setup → Packet capture: opens capture
- Packet capture → Connection model: identifies flows (evidence: `src/network/sniffer.rs`)
- Packet capture → Traffic utilization: reports traffic
- Input setup → Socket lookup: provides lookup (evidence: `src/os/shared.rs`)
- Socket lookup → Linux sockets: dispatches on Linux (evidence: `src/os/shared.rs`)
- Socket lookup → lsof socket lookup: dispatches on macOS (evidence: `src/os/shared.rs`)
- lsof socket lookup → lsof parsing: uses parsing (evidence: `src/os/lsof.rs`)
- Socket lookup → Windows sockets: dispatches on Windows (evidence: `src/os/shared.rs`)
- Input setup → DNS setup: initializes DNS (evidence: `src/os/shared.rs`)
- DNS setup → DNS client: creates client (evidence: `src/os/shared.rs`)
- DNS client → Reverse resolver: calls lookup (evidence: `src/network/dns/client.rs`)
- Monitor runtime → DNS client: requests names (evidence: `src/main.rs`)
- Monitor runtime → Bandwidth state: updates state (evidence: `src/main.rs`)
- Monitor runtime → Terminal and raw UI: drives display (evidence: `src/main.rs`)
- Terminal and raw UI → Bandwidth state: reads state
- Terminal and raw UI → Bandwidth display: renders bandwidth
- Terminal and raw UI → Header details: renders headers
- Terminal and raw UI → Responsive layout: uses layout
- Terminal and raw UI → Summary tables: renders tables
- Terminal and raw UI → Help text: renders help
