# tunneltodev/tunnelto architecture

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

- Interactive diagram: https://gitdiagram.com/tunneltodev/tunnelto
- Repository: https://github.com/tunneltodev/tunnelto

## Overview

1. **What this repo is**
   - `tunnelto` is a Rust command-line tool that exposes a locally running service through a public tunnel.
   - The runtime model is: local user process -> tunnel client -> remote tunnel service -> inbound public traffic -> forwarded back to `localhost:<port>`.

2. **Workspace shape**
   - The repository is a small Rust workspace with two crates:
     - `tunnelto`: the main executable and user-facing CLI.
     - `tunnelto_protocol`: a shared protocol library for client/server communication.
   - This split is the main architectural boundary: transport/protocol types are isolated from the CLI and UI code.

3. **CLI and process bootstrap**
   - `tunnelto/src/main.rs` is the entrypoint.
   - `config.rs` holds command-line and runtime configuration such as host, port, scheme, subdomain, auth key, and dashboard address.
   - `error.rs` centralizes application error handling.
   - `lib.rs` likely wires the crate’s major modules together so the binary stays thin.

4. **Tunnel forwarding path**
   - `local.rs` is the core local forwarding layer.
   - Its role is to bind to the configured local service and proxy tunnel traffic to/from that service.
   - This is the main data plane: inbound requests from the public tunnel are relayed to the local host/port, and responses flow back through the tunnel.

5. **Remote tunnel/session logic**
   - Although the remote server implementation is not in this tree, the client clearly depends on a tunnel protocol and an external tunnel endpoint.
   - The CLI options imply the client authenticates, establishes a tunnel, and optionally chooses a subdomain, so session establishment is a first-class part of the flow.

6. **Shared wire protocol**
   - `tunnelto_protocol/src/lib.rs` defines shared message types and/or framing for the tunnel handshake and traffic exchange.
   - Keeping this in a separate crate avoids duplication and keeps the binary and any server-side component aligned on the same protocol contract.

7. **Local introspection dashboard**
   - `introspect/` provides a built-in dashboard for inspecting tunnel traffic.
   - The presence of `console_log.rs` and HTML templates for `detail`, `headers_detail`, and `body_detail` suggests it renders request/response metadata and payload views.
   - `--dashboard-address` in the README shows this dashboard runs as a separate local endpoint rather than inside the tunnel path itself.

8. **Dashboard presentation layer**
   - `templates/` contains server-rendered HTML for the introspection UI.
   - `static/css/` and `static/img/` provide the styling and assets for that local dashboard.
   - This is a classic separation of concerns: traffic capture/aggregation in Rust code, presentation in templates/static assets.

9. **Console and request logging**
   - `introspect/console_log.rs` indicates the tool can surface console or diagnostic output alongside tunnel activity.
   - This makes the dashboard a debugging aid, not just a status page, and ties into the request inspection flow.

10. **Configuration and authentication**
   - The README’s `set-auth` subcommand and `--key` option show that authentication is user-managed and persisted locally.
   - This is part of the control plane: it affects tunnel creation but is separate from request forwarding.

11. **Update path**
   - `update.rs` suggests the binary can check for or apply updates from within the CLI.
   - That is an auxiliary subsystem, not part of the tunnel data path, but relevant to how the binary maintains itself.

12. **Build/release pipeline**
   - `.github/workflows/check.yml` and `release.yml` indicate CI validation and release automation.
   - This matters architecturally because the project is shipped as a compiled native CLI, with release artifacts likely published for multiple target platforms.

13. **Overall boundary diagram to draw**
   - On one side: the user’s local application listening on `host:port`.
   - In the middle: the `tunnelto` CLI proxying traffic and managing session/auth/config.
   - Off to the side: the local introspection dashboard and its static/template UI.
   - On the far side: the external tunnel service and the public URL endpoint, which are outside this repository but are the remote counterpart of the client.

Main entry points: [`tunnelto/src/lib.rs`](https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/src/lib.rs) (Library), [`tunnelto/src/local.rs`](https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/src/local.rs) (Forwarder), [`tunnelto/src/introspect/mod.rs`](https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/src/introspect/mod.rs) (Dashboard Core), [`tunnelto/templates/index.html`](https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/templates/index.html) (Templates)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_client["Tunnelto CLI"]
  node_node_main["Main<br/>entrypoint<br/>[main.rs]"]
  node_node_lib["Library<br/>module root<br/>[lib.rs]"]
  node_node_cli_ui["CLI UI<br/>user interface<br/>[cli_ui.rs]"]
  node_node_config["Config<br/>[config.rs]"]
  node_node_error["Errors<br/>error handling<br/>[error.rs]"]
  node_node_local["Forwarder<br/>data plane<br/>[local.rs]"]
  node_node_update["Updater<br/>maintenance<br/>[update.rs]"]
end

subgraph group_group_dashboard["Introspection UI"]
  node_node_introspect_mod["Dashboard Core<br/>inspection server<br/>[mod.rs]"]
  node_node_console_log["Console Log<br/>logging<br/>[console_log.rs]"]
  node_node_templates["Templates<br/>presentation<br/>[index.html]"]
  node_node_detail_tpl["Detail View<br/>presentation<br/>[detail.html]"]
  node_node_headers_tpl["Headers View<br/>presentation"]
  node_node_body_tpl["Body View<br/>presentation<br/>[body_detail.html]"]
  node_node_static["Static Assets<br/>[styles.css]"]
end

subgraph group_group_protocol["Shared Protocol"]
  node_node_protocol["Protocol<br/>wire format<br/>[lib.rs]"]
end

subgraph group_group_ci["CI / Release"]
  node_node_workflows["Workflows<br/>automation<br/>[check.yml]"]
end

subgraph group_group_external["External Systems"]
  node_node_local_app(("Local App<br/>external service"))
  node_node_remote_service(("Tunnel Service<br/>external service"))
end

node_node_main -->|"boots"| node_node_lib
node_node_lib -->|"loads"| node_node_config
node_node_lib -->|"drives"| node_node_cli_ui
node_node_lib -->|"starts"| node_node_local
node_node_lib -->|"starts"| node_node_introspect_mod
node_node_lib -->|"checks"| node_node_update
node_node_lib -->|"handles"| node_node_error
node_node_local -->|"forwards to"| node_node_local_app
node_node_local -->|"speaks"| node_node_protocol
node_node_local -->|"connects"| node_node_remote_service
node_node_protocol -.->|"contracts with"| node_node_remote_service
node_node_introspect_mod -->|"includes"| node_node_console_log
node_node_introspect_mod -->|"renders"| node_node_templates
node_node_templates -.->|"uses"| node_node_detail_tpl
node_node_templates -.->|"uses"| node_node_headers_tpl
node_node_templates -.->|"uses"| node_node_body_tpl
node_node_introspect_mod -->|"serves"| node_node_static
node_node_config -->|"configures"| node_node_introspect_mod
node_node_config -->|"configures"| node_node_local
node_node_workflows -.->|"builds"| node_node_main
node_node_workflows -.->|"checks"| node_node_protocol

click node_node_main "https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/src/main.rs"
click node_node_lib "https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/src/lib.rs"
click node_node_cli_ui "https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/src/cli_ui.rs"
click node_node_config "https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/src/config.rs"
click node_node_error "https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/src/error.rs"
click node_node_local "https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/src/local.rs"
click node_node_update "https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/src/update.rs"
click node_node_introspect_mod "https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/src/introspect/mod.rs"
click node_node_console_log "https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/src/introspect/console_log.rs"
click node_node_templates "https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/templates/index.html"
click node_node_detail_tpl "https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/templates/detail.html"
click node_node_headers_tpl "https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/templates/headers_detail.html"
click node_node_body_tpl "https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/templates/body_detail.html"
click node_node_static "https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/static/css/styles.css"
click node_node_protocol "https://github.com/tunneltodev/tunnelto/blob/main/tunnelto_protocol/src/lib.rs"
click node_node_workflows "https://github.com/tunneltodev/tunnelto/blob/main/.github/workflows/check.yml"

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_node_main,node_node_lib,node_node_cli_ui,node_node_config,node_node_error,node_node_local,node_node_update toneBlue
class node_node_introspect_mod,node_node_console_log,node_node_templates,node_node_detail_tpl,node_node_headers_tpl,node_node_body_tpl,node_node_static toneAmber
class node_node_protocol toneMint
class node_node_workflows toneRose
class node_node_local_app,node_node_remote_service toneIndigo
```

## Components

### Tunnelto CLI

Main executable, config, forwarding, updates, and user-facing control flow.

- [Main](https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/src/main.rs): entrypoint · Binary entrypoint and bootstrap. · `tunnelto/src/main.rs`
- [Library](https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/src/lib.rs): module root · Wires the crate modules together. · `tunnelto/src/lib.rs`
- [CLI UI](https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/src/cli_ui.rs): user interface · Command-line interaction and status output. · `tunnelto/src/cli_ui.rs`
- [Config](https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/src/config.rs): runtime config · Host, port, scheme, subdomain, auth, and dashboard settings. · `tunnelto/src/config.rs`
- [Errors](https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/src/error.rs): error handling · Central application error definitions. · `tunnelto/src/error.rs`
- [Forwarder](https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/src/local.rs): data plane · Binds local service and proxies tunnel traffic to localhost. · `tunnelto/src/local.rs`
- [Updater](https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/src/update.rs): maintenance · Checks for or applies binary updates. · `tunnelto/src/update.rs`

### Introspection UI

Local traffic inspection dashboard with request/response views.

- [Dashboard Core](https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/src/introspect/mod.rs): inspection server · Traffic capture and dashboard orchestration. · `tunnelto/src/introspect/mod.rs`
- [Console Log](https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/src/introspect/console_log.rs): logging · Surfaces diagnostic and console output in the dashboard. · `tunnelto/src/introspect/console_log.rs`
- [Templates](https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/templates/index.html): presentation · Server-rendered HTML views for request inspection. · `tunnelto/templates/index.html`
- [Detail View](https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/templates/detail.html): presentation · Per-request detail page template. · `tunnelto/templates/detail.html`
- [Headers View](https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/templates/headers_detail.html): presentation · Header-focused detail template. · `tunnelto/templates/headers_detail.html`
- [Body View](https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/templates/body_detail.html): presentation · Body-focused detail template. · `tunnelto/templates/body_detail.html`
- [Static Assets](https://github.com/tunneltodev/tunnelto/blob/main/tunnelto/static/css/styles.css): assets · Dashboard styles and images. · `tunnelto/static/css/styles.css`

### Shared Protocol

Wire types shared by tunnel client and server counterparts.

- [Protocol](https://github.com/tunneltodev/tunnelto/blob/main/tunnelto_protocol/src/lib.rs): wire format · Shared tunnel handshake and message types. · `tunnelto_protocol/src/lib.rs`

### CI / Release

Automation for validation and publishing.

- [Workflows](https://github.com/tunneltodev/tunnelto/blob/main/.github/workflows/check.yml): automation · CI validation and release automation. · `.github/workflows/check.yml`

### External Systems

Runtime dependencies outside this repository.

- **Local App**: external service · User application listening on the configured host and port.
- **Tunnel Service**: external service · Remote tunnel endpoint and public ingress outside this repository.

## Connections

- Main → Library: boots · Binary delegates setup into the crate library.
- Library → Config: loads · Reads and applies runtime configuration.
- Library → CLI UI: drives · Uses CLI presentation for user interaction.
- Library → Forwarder: starts · Starts the local proxying path.
- Library → Dashboard Core: starts · Starts the local dashboard when enabled.
- Library → Updater: checks · Can invoke update logic as part of CLI operations.
- Library → Errors: handles · Routes failures through unified error types.
- Forwarder → Local App: forwards to · Proxies public tunnel traffic into the local service.
- Forwarder → Protocol: speaks · Uses shared tunnel message framing and types.
- Forwarder → Tunnel Service: connects · Maintains a session with the remote tunnel endpoint.
- Protocol → Tunnel Service: contracts with · Defines the wire contract used on both sides of the tunnel.
- Dashboard Core → Console Log: includes · Aggregates console and diagnostic output.
- Dashboard Core → Templates: renders · Serves the dashboard HTML.
- Templates → Detail View: uses · Renders detailed request/response views.
- Templates → Headers View: uses · Renders header-centric views.
- Templates → Body View: uses · Renders body-centric views.
- Dashboard Core → Static Assets: serves · Serves CSS and image assets for the dashboard.
- Config → Dashboard Core: configures · Dashboard address and related settings shape introspection startup.
- Config → Forwarder: configures · Host, port, scheme, subdomain, and auth drive tunnel setup.
- Workflows → Main: builds · CI validates the Rust workspace and release artifacts.
- Workflows → Protocol: checks · Release automation depends on the shared workspace building cleanly.
