# thisisdara/mhr-cfw-go architecture

> Architecture diagram of the GitHub repository thisisdara/mhr-cfw-go, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/thisisdara/mhr-cfw-go
- Repository: https://github.com/thisisdara/mhr-cfw-go

## Overview

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: [`cmd/mhr-cfw/main.go`](https://github.com/thisisdara/mhr-cfw-go/blob/master/cmd/mhr-cfw/main.go) (Main), [`internal/proxy/proxy_server.go`](https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/proxy/proxy_server.go) (Proxy), [`internal/mitm/mitm.go`](https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/mitm/mitm.go) (MITM), [`internal/constants/constants.go`](https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/constants/constants.go) (Constants)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_control["Control plane"]
  node_node_main["Main<br/>CLI orchestrator<br/>[main.go]"]
  node_node_config["Config<br/>runtime settings<br/>[config.go]"]
  node_node_constants["Constants<br/>shared values<br/>[constants.go]"]
  node_node_tui["Menu<br/>interactive UI<br/>[menu.go]"]
  node_node_setup["Setup<br/>wizard<br/>[wizard.go]"]
end

subgraph group_group_edge["Local edge"]
  node_node_proxy["Proxy<br/>local listener<br/>[proxy_server.go]"]
  node_node_mitm{{"MITM<br/>TLS interception<br/>[mitm.go]"}}
  node_node_cert["CA cert<br/>certificate management<br/>[installer.go]"]
end

subgraph group_group_relay["Relay path"]
  node_node_fronter["Fronter<br/>request shaping<br/>[fronter.go]"]
  node_node_codec["Codec<br/>encode/decode<br/>[codec.go]"]
  node_node_h2["H2 transport<br/>outbound HTTP/2<br/>[h2_transport.go]"]
end

subgraph group_group_support["Support"]
  node_node_scanner["Scanner<br/>endpoint scan<br/>[scanner.go]"]
  node_node_lan["LAN<br/>network detect<br/>[lan.go]"]
  node_node_logging["Logging<br/>observability<br/>[logging.go]"]
end

node_node_main -->|"loads"| node_node_config
node_node_main -->|"opens"| node_node_tui
node_node_main -->|"runs"| node_node_setup
node_node_main -->|"starts"| node_node_proxy
node_node_main -->|"scans"| node_node_scanner
node_node_main -->|"installs"| node_node_cert
node_node_proxy -->|"intercepts"| node_node_mitm
node_node_cert -->|"enables"| node_node_mitm
node_node_mitm -->|"forwards"| node_node_fronter
node_node_fronter -->|"encodes"| node_node_codec
node_node_codec -->|"ships"| node_node_h2
node_node_h2 -->|"returns"| node_node_fronter
node_node_proxy -->|"logs"| node_node_logging
node_node_mitm -->|"logs"| node_node_logging
node_node_fronter -->|"logs"| node_node_logging
node_node_scanner -->|"logs"| node_node_logging
node_node_setup -->|"writes"| node_node_config
node_node_tui -->|"edits"| node_node_config
node_node_lan -->|"supports"| node_node_proxy
node_node_constants -.->|"shared by"| node_node_config
node_node_constants -.->|"shared by"| node_node_proxy
node_node_constants -.->|"shared by"| node_node_mitm
node_node_constants -.->|"shared by"| node_node_h2

click node_node_main "https://github.com/thisisdara/mhr-cfw-go/blob/master/cmd/mhr-cfw/main.go"
click node_node_config "https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/config/config.go"
click node_node_constants "https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/constants/constants.go"
click node_node_tui "https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/tui/menu.go"
click node_node_setup "https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/setup/wizard.go"
click node_node_proxy "https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/proxy/proxy_server.go"
click node_node_mitm "https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/mitm/mitm.go"
click node_node_cert "https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/cert/installer.go"
click node_node_fronter "https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/fronter/fronter.go"
click node_node_codec "https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/codec/codec.go"
click node_node_h2 "https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/h2/h2_transport.go"
click node_node_scanner "https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/scanner/scanner.go"
click node_node_lan "https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/lan/lan.go"
click node_node_logging "https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/logging/logging.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_node_main,node_node_config,node_node_constants,node_node_tui,node_node_setup toneBlue
class node_node_proxy,node_node_mitm,node_node_cert toneAmber
class node_node_fronter,node_node_codec,node_node_h2 toneMint
class node_node_scanner,node_node_lan,node_node_logging toneRose
```

## Components

### Control plane

Startup, configuration, and operator entrypoints.

- [Main](https://github.com/thisisdara/mhr-cfw-go/blob/master/cmd/mhr-cfw/main.go): CLI orchestrator · Parses flags, loads config, and routes startup into proxy, setup, scan, TUI, or cert actions. · `cmd/mhr-cfw/main.go`
- [Config](https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/config/config.go): runtime settings · Owns proxy settings, SOCKS5 options, logging, and relay identifiers. · `internal/config/config.go`
- [Constants](https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/constants/constants.go): shared values · Centralizes static values used across packages. · `internal/constants/constants.go`
- [Menu](https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/tui/menu.go): interactive UI · Startup menu for interactive operator control. · `internal/tui/menu.go`
- [Setup](https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/setup/wizard.go): wizard · Guides initial configuration for the relay backend. · `internal/setup/wizard.go`

### Local edge

Local client ingress and HTTPS interception.

- [Proxy](https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/proxy/proxy_server.go): local listener · Accepts client traffic on the machine and begins the forwarding flow. · `internal/proxy/proxy_server.go`
- [MITM](https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/mitm/mitm.go): TLS interception · Terminates HTTPS locally and prepares traffic for relay handling. · `internal/mitm/mitm.go`
- [CA cert](https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/cert/installer.go): certificate management · 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](https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/fronter/fronter.go): request shaping · Converts intercepted requests into relay-compatible form. · `internal/fronter/fronter.go`
- [Codec](https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/codec/codec.go): encode/decode · Encodes payloads and decodes relay responses, including content transformations. · `internal/codec/codec.go`
- [H2 transport](https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/h2/h2_transport.go): outbound HTTP/2 · Pooled multiplexed transport used for egress to the Google relay side. · `internal/h2/h2_transport.go`

### Support

Shared utilities, discovery, and logging.

- [Scanner](https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/scanner/scanner.go): endpoint scan · Discovers workable Google-side endpoints or IPs for the relay path. · `internal/scanner/scanner.go`
- [LAN](https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/lan/lan.go): network detect · Helps determine local network or bind context for the proxy host. · `internal/lan/lan.go`
- [Logging](https://github.com/thisisdara/mhr-cfw-go/blob/master/internal/logging/logging.go): observability · Shared logging used across proxy, MITM, setup, and relay subsystems. · `internal/logging/logging.go`

## Connections

- 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.
