How tunneltodev/tunnelto works
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: lib.rs Library · local.rs Forwarder · mod.rs Dashboard Core · index.html Templates
Components 18
Tunnelto CLI
Main executable, config, forwarding, updates, and user-facing control flow.
- Main · Binary entrypoint and bootstrap.
tunnelto/src/main.rs - Library · Wires the crate modules together.
tunnelto/src/lib.rs - CLI UI · Command-line interaction and status output.
tunnelto/src/cli_ui.rs - Config · Host, port, scheme, subdomain, auth, and dashboard settings.
tunnelto/src/config.rs - Errors · Central application error definitions.
tunnelto/src/error.rs - Forwarder · Binds local service and proxies tunnel traffic to localhost.
tunnelto/src/local.rs - Updater · Checks for or applies binary updates.
tunnelto/src/update.rs
Introspection UI
Local traffic inspection dashboard with request/response views.
- Dashboard Core · Traffic capture and dashboard orchestration.
tunnelto/src/introspect/mod.rs - Console Log · Surfaces diagnostic and console output in the dashboard.
tunnelto/src/introspect/console_log.rs - Templates · Server-rendered HTML views for request inspection.
tunnelto/templates/index.html - Detail View · Per-request detail page template.
tunnelto/templates/detail.html - Headers View · Header-focused detail template.
tunnelto/templates/headers_detail.html - Body View · Body-focused detail template.
tunnelto/templates/body_detail.html - Static Assets · Dashboard styles and images.
tunnelto/static/css/styles.css
Shared Protocol
Wire types shared by tunnel client and server counterparts.
- Protocol · Shared tunnel handshake and message types.
tunnelto_protocol/src/lib.rs
CI / Release
Automation for validation and publishing.
- Workflows · CI validation and release automation.
.github/workflows/check.yml
External Systems
Runtime dependencies outside this repository.
- Local App · User application listening on the configured host and port.
- Tunnel Service · Remote tunnel endpoint and public ingress outside this repository.
Connections 21
- 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.