How thisisdara/mhr-cfw-go works
1. High-level shape
- This is a single Go command-line application, built as one binary from cmd/mhr-cfw/main.go, with most logic in internal/*.
- Architecturally it is a local proxy relay: client traffic enters on the machine, is optionally intercepted at HTTPS, then is forwarded through a Google-hosted relay path tied to an Apps Script deployment.
2. Startup and control plane
- main.go is the orchestration layer: it reads config, parses CLI flags, decides whether to launch the TUI, start the proxy, run setup, scan, or install/uninstall the CA.
- The app supports both interactive and non-interactive operation, with --no-menu and explicit flags like --install-cert, --scan, and --setup.
3. Configuration boundary
- internal/config owns runtime settings such as proxy host/port, SOCKS5 options, logging level, and the Google relay identifiers (auth_key and script_id in config.json).
- internal/constants centralizes static values used across packages, reducing coupling between the proxy, certificate, and setup flows.
4. Operator UX
- internal/tui provides the interactive menu shown on startup when the app is run normally.
- internal/setup contains the setup wizard that helps populate the config needed to connect to the Google relay backend.
- These packages are the human-facing control surface; they do not carry proxy traffic themselves.
5. Local proxy edge
- internal/proxy is the main traffic ingress for local clients.
- It exposes the local proxy listener(s), likely including the HTTP proxy and optional SOCKS5 path mentioned in the README.
- This is the boundary where browser/app traffic first enters the system before any interception or relaying happens.
6. HTTPS interception / MITM layer
- internal/mitm and internal/cert implement the man-in-the-middle TLS interception path.
- internal/cert/installer.go handles installing/removing the local CA certificate so the proxy can terminate HTTPS locally and reissue certificates for destination hosts.
- This boundary is essential: without the CA installed, HTTPS traffic cannot be transparently inspected or rewritten.
7. Relay/backhaul to Google
- internal/fronter appears to be the request-shaping layer that converts intercepted requests into the format expected by the remote relay.
- internal/codec handles encoding/decoding of payloads and response data, including the content transformations needed for compatibility and compression handling.
- The external dependency here is Google infrastructure, specifically the Apps Script deployment identified by script_id.
8. Upstream transport
- internal/h2/h2_transport.go provides a custom HTTP/2 transport for outbound requests to the Google side.
- The README’s performance claims align with this layer: pooled TLS connections and HTTP/2 multiplexing reduce overhead versus one-off HTTP/1.1 connections.
- This is the app’s main egress channel to the external relay service.
9. Traffic optimization features
- The README calls out request coalescing, response caching, range-request handling, and better CORS/content-encoding behavior for YouTube and similar streaming workloads.
- Those behaviors are likely split between proxy, fronter, codec, and h2, with the proxy edge deciding whether to reuse or forward requests and the codec layer normalizing responses.
10. Network discovery and environment support
- internal/scanner is a supporting subsystem for scanning Google IPs, which fits the project’s goal of finding workable upstream endpoints.
- internal/lan likely handles local network detection or bind-address selection for the proxy on the host machine.
- internal/logging provides shared logs across all subsystems, important for diagnosing proxy, MITM, and upstream relay failures.
11. Data flow summary
- Client app/browser → local proxy listener → MITM/TLS interception if HTTPS → request encoding/fronting → HTTP/2 outbound relay to Google Apps Script → response decoding/decompression → local proxy response back to the client.
- The CA installation step is an enabling dependency for the HTTPS branch of this flow.
12. Packaging and deployment
- The repository is designed to build into a standalone executable on Windows, Linux, macOS, and Termux/Android.
- Build scripts and CI workflows exist to produce the binary, but they do not change the runtime architecture: it remains a local proxy service with optional interactive management.
Main entry points: main.go Main · proxy_server.go Proxy · mitm.go MITM · constants.go Constants
Components 14
Control plane
Startup, configuration, and operator entrypoints.
- Main · Parses flags, loads config, and routes startup into proxy, setup, scan, TUI, or cert actions.
cmd/mhr-cfw/main.go - Config · Owns proxy settings, SOCKS5 options, logging, and relay identifiers.
internal/config/config.go - Constants · Centralizes static values used across packages.
internal/constants/constants.go - Menu · Startup menu for interactive operator control.
internal/tui/menu.go - Setup · Guides initial configuration for the relay backend.
internal/setup/wizard.go
Local edge
Local client ingress and HTTPS interception.
- Proxy · Accepts client traffic on the machine and begins the forwarding flow.
internal/proxy/proxy_server.go - MITM · Terminates HTTPS locally and prepares traffic for relay handling.
internal/mitm/mitm.go - CA cert · Installs and removes the local CA needed for HTTPS interception.
internal/cert/installer.go
Relay path
Request shaping and outbound transport to the Google-backed relay.
- Fronter · Converts intercepted requests into relay-compatible form.
internal/fronter/fronter.go - Codec · Encodes payloads and decodes relay responses, including content transformations.
internal/codec/codec.go - H2 transport · Pooled multiplexed transport used for egress to the Google relay side.
internal/h2/h2_transport.go
Support
Shared utilities, discovery, and logging.
- Scanner · Discovers workable Google-side endpoints or IPs for the relay path.
internal/scanner/scanner.go - LAN · Helps determine local network or bind context for the proxy host.
internal/lan/lan.go - Logging · Shared logging used across proxy, MITM, setup, and relay subsystems.
internal/logging/logging.go
Connections 23
- Main → Config: loads · Startup reads runtime settings before choosing an execution path.
- Main → Menu: opens · Interactive mode starts the operator menu.
- Main → Setup: runs · Explicit setup path launches the configuration wizard.
- Main → Proxy: starts · Main process launches the local proxy server.
- Main → Scanner: scans · CLI can trigger endpoint scanning.
- Main → CA cert: installs · CLI can install or remove the local CA certificate.
- Proxy → MITM: intercepts · Proxy hands HTTPS traffic into the TLS interception layer.
- CA cert → MITM: enables · CA installation makes transparent HTTPS termination possible.
- MITM → Fronter: forwards · Intercepted requests are normalized for relay compatibility.
- Fronter → Codec: encodes · Request and response payloads are transformed for transport.
- Codec → H2 transport: ships · Encoded relay traffic is sent through the outbound HTTP/2 transport.
- H2 transport → Fronter: returns · Relay responses flow back into the shaping layer.
- Proxy → Logging: logs · Proxy operations and failures are recorded centrally.
- MITM → Logging: logs · TLS interception events and errors are recorded centrally.
- Fronter → Logging: logs · Request shaping and relay translation are logged.
- Scanner → Logging: logs · Scan results and connectivity issues are logged.
- Setup → Config: writes · Setup populates relay identifiers and proxy settings.
- Menu → Config: edits · Interactive menu adjusts runtime configuration.
- LAN → Proxy: supports · LAN detection informs how the local listener binds or advertises.
- Constants → Config: shared by · Static values support config parsing and defaults.
- Constants → Proxy: shared by · Proxy behavior uses shared constants.
- Constants → MITM: shared by · MITM behavior uses shared constants.
- Constants → H2 transport: shared by · Outbound transport uses shared constants.