# masterking32/masterhttprelayvpn architecture

> Architecture diagram of the GitHub repository masterking32/masterhttprelayvpn, 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/masterking32/masterhttprelayvpn
- Repository: https://github.com/masterking32/masterhttprelayvpn

## Overview

1. **What this system is**
   - MasterHttpRelayVPN is a **local proxy gateway** that sits on the user machine and forwards browser traffic through a **Google Apps Script relay** using **domain fronting**.
   - The core trust boundary is: **browser/device → local proxy → Google-facing relay → destination site**.
   - An **optional exit node** can be added later for sites that block Google egress IPs.

2. **Primary runtime entry points**
   - `main.py` is the Python application entry point.
   - `start.sh` and `start.bat` are the user-facing launchers; they create/install the environment, load config, and start the proxy.
   - `Dockerfile` and `docker-compose.yml` package the same runtime for containerized deployment.
   - `config.example.json` indicates the app is configuration-driven, with a generated `config.json` used at runtime.

3. **Local proxy subsystem**
   - `src/proxy/` is the local network-facing layer.
   - It exposes both **HTTP proxy** and **SOCKS5** endpoints, matching the quick-start ports in the README (`8085` and `1080`).
   - This layer accepts browser/client connections, normalizes requests, and routes them into the relay path.

4. **MITM and certificate handling**
   - `src/proxy/mitm.py` and `src/core/cert_installer.py` implement the **TLS interception** path.
   - The proxy installs a local CA certificate so it can decrypt HTTPS traffic, inspect or modify it, then re-encrypt for the upstream path.
   - This is a major security boundary: the browser trusts the local CA, while the proxy can inspect content before forwarding.

5. **Relay forwarding layer**
   - `src/relay/` is the outbound transport subsystem that connects the local proxy to the remote relay service.
   - `domain_fronter.py`, `fronting_support.py`, `h2_transport.py`, `http_reader.py`, and `relay_response.py` together suggest:
     - request shaping for fronting,
     - HTTP/2-based upstream transport,
     - response parsing/relay reconstruction.
   - This layer is where the project hides the true destination behind a Google-looking connection.

6. **Remote relay deployment on Google Apps Script**
   - `apps_script/Code.gs` is the main remote relay endpoint deployed as a Google Web App.
   - The README shows the relay is authenticated with a shared secret (`AUTH_KEY`) and deployed under a Google account.
   - `apps_script/cloudflare_worker.js` and `apps_script/deno_deploy.ts` indicate alternative relay/bridge deployments for environments outside Apps Script.

7. **Optional exit-node extension**
   - `apps_script/vps_exit_node.py` and `apps_script/setup_vps_exit_node.sh` support a separate **exit node** path.
   - The docs and README describe this as an optional layer for destinations that reject Google egress IPs.
   - The exit-node architecture introduces another external boundary: **Google relay → exit node (Cloudflare Worker or VPS) → target site**.

8. **Core utilities used across layers**
   - `src/core/` contains shared helpers that support the proxy and relay stack:
     - `adblock.py` for filtering,
     - `codec.py` for encoding/decoding payloads,
     - `google_ip_scanner.py` for Google IP selection/validation,
     - `lan_utils.py` for LAN sharing,
     - `logging_utils.py` for runtime diagnostics,
     - `constants.py` for shared settings.
   - `src/core/google_ip_scanner.py` and the relay modules suggest the system may actively choose usable Google-facing endpoints.

9. **Traffic policy and filtering**
   - `src/core/adblock.py` and the README’s ad-block references show that request filtering is built into the proxy path.
   - This means traffic is not just forwarded; some requests can be blocked or rewritten before reaching the relay.
   - In an architecture diagram, this sits on the **local proxy ingress path** before upstream relay dispatch.

10. **Configuration, security, and deployment boundaries**
   - `docs/CONFIGURATION.md`, `docs/SECURITY.md`, and `docs/ARCHITECTURE.md` define operational rules rather than code paths, but they matter architecturally.
   - The key secrets/boundaries are `auth_key`, `config.json`, and the installed CA certificate directory.
   - The README explicitly warns not to share the config, CA, or valid exit-node credentials together, which reflects the security model of the system.

11. **Network clients and sharing**
   - The proxy is primarily intended for a browser, but LAN sharing is supported via `docs/LAN_SHARING.md` and `src/core/lan_utils.py`.
   - This means the local proxy can be reused by other devices on the same network, turning the host into a small proxy appliance.
   - The diagram should therefore include optional downstream clients beyond the local browser.

12. **Tests and validation**
   - `tests/` covers focused units around adblock, codec, fronting support, and proxy support.
   - `scripts/benchmark_transport.py` suggests transport-layer performance comparison or tuning.
   - These are supporting tools, not runtime subsystems, but they show where the critical seams are: filtering, encoding, fronting, and proxy behavior.

13. **End-to-end data flow**
   - The typical path is:
     - browser/device sends HTTP(S) traffic to the local proxy,
     - local proxy performs MITM and policy checks,
     - relay layer packages the request for domain fronting,
     - Google Apps Script relay forwards it onward,
     - optional exit node may be used for difficult destinations,
     - response returns through the same chain to the browser.
   - This is the main flow to emphasize in any architecture diagram.

14. **Technology profile**
   - Core runtime is **Python** for the local proxy and relay client.
   - The relay endpoint is **Google Apps Script JavaScript**.
   - Optional deployment targets include **Cloudflare Workers**, **Deno Deploy**, and **VPS-based Python**.
   - The repo also includes Docker and CI workflows, so the project is designed to be portable across local, container, and cloud deployment models.

Main entry points: [`src/proxy/proxy_server.py`](https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/src/proxy/proxy_server.py) (Proxy server), [`src/relay/__init__.py`](https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/src/relay/__init__.py) (Relay client), [`apps_script/Code.gs`](https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/apps_script/Code.gs) (Apps Script), [`main.py`](https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/main.py) (Main app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g1["Local clients"]
  node_n1(("Browser<br/>client"))
  node_n2(("LAN peers<br/>client<br/>[LAN_SHARING.md]"))
end

subgraph group_g2["Local runtime"]
  node_n3["Launchers<br/>startup scripts<br/>[start.sh]"]
  node_n4["Main app<br/>python entrypoint<br/>[main.py]"]
  node_n5["Proxy server<br/>local proxy<br/>[proxy_server.py]"]
  node_n6["SOCKS5<br/>proxy endpoint<br/>[socks5.py]"]
  node_n7["MITM<br/>tls interception<br/>[mitm.py]"]
end

subgraph group_g3["Relay transport"]
  node_n10["Relay client<br/>upstream client<br/>[__init__.py]"]
  node_n11["Domain fronting<br/>fronting logic<br/>[domain_fronter.py]"]
  node_n12["HTTP/2 transport<br/>[h2_transport.py]"]
  node_n13["Relay parser<br/>response handling<br/>[http_reader.py]"]
end

subgraph group_g4["Remote relay"]
  node_n14["Apps Script<br/>remote relay<br/>[Code.gs]"]
  node_n15["Alt relay<br/>alternate deployment"]
end

subgraph group_g5["Optional exit"]
  node_n16["Exit node<br/>optional egress<br/>[vps_exit_node.py]"]
end

subgraph group_g6["Shared core"]
  node_n8["Cert install<br/>trust bootstrap<br/>[cert_installer.py]"]
  node_n9["Policy filter<br/>traffic policy<br/>[adblock.py]"]
  node_n17["Core utils<br/>shared helpers<br/>[constants.py]"]
end

node_n1 -->|"HTTP(S)"| node_n5
node_n2 -->|"shared proxy"| node_n5
node_n3 -->|"starts"| node_n4
node_n4 -->|"boots"| node_n5
node_n5 -->|"SOCKS5"| node_n6
node_n5 -->|"MITM"| node_n7
node_n7 -->|"trusts CA"| node_n8
node_n5 -->|"filters"| node_n9
node_n5 -->|"forwards"| node_n10
node_n10 -->|"shapes"| node_n11
node_n10 -->|"transports"| node_n12
node_n11 -->|"fronts to"| node_n14
node_n12 -->|"upstream"| node_n14
node_n14 -->|"returns"| node_n13
node_n13 -->|"response"| node_n5
node_n14 -.->|"optional egress"| node_n16
node_n16 -.->|"alt bridge"| node_n15
node_n5 -->|"shared core"| node_n17
node_n10 -->|"shared core"| node_n17

click node_n2 "https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/docs/LAN_SHARING.md"
click node_n3 "https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/start.sh"
click node_n4 "https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/main.py"
click node_n5 "https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/src/proxy/proxy_server.py"
click node_n6 "https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/src/proxy/socks5.py"
click node_n7 "https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/src/proxy/mitm.py"
click node_n8 "https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/src/core/cert_installer.py"
click node_n9 "https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/src/core/adblock.py"
click node_n10 "https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/src/relay/__init__.py"
click node_n11 "https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/src/relay/domain_fronter.py"
click node_n12 "https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/src/relay/h2_transport.py"
click node_n13 "https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/src/relay/http_reader.py"
click node_n14 "https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/apps_script/Code.gs"
click node_n15 "https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/apps_script/cloudflare_worker.js"
click node_n16 "https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/apps_script/vps_exit_node.py"
click node_n17 "https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/src/core/constants.py"

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_n1,node_n2 toneBlue
class node_n3,node_n4,node_n5,node_n6,node_n7 toneAmber
class node_n10,node_n11,node_n12,node_n13 toneMint
class node_n14,node_n15 toneRose
class node_n16 toneIndigo
class node_n8,node_n9,node_n17 toneTeal
```

## Components

### Local clients

User devices and downstream consumers of the local proxy.

- **Browser**: client · Primary browser traffic source.
- [LAN peers](https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/docs/LAN_SHARING.md): client · Other devices that can share the local proxy. · `docs/LAN_SHARING.md`

### Local runtime

Python entrypoints and the on-machine proxy stack.

- [Launchers](https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/start.sh): startup scripts · User-facing startup scripts and packaging entrypoints. · `start.sh`
- [Main app](https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/main.py): python entrypoint · Main Python application entrypoint. · `main.py`
- [Proxy server](https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/src/proxy/proxy_server.py): local proxy · Network-facing HTTP proxy and SOCKS5 listener. · `src/proxy/proxy_server.py`
- [SOCKS5](https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/src/proxy/socks5.py): proxy endpoint · SOCKS5 access path for client traffic. · `src/proxy/socks5.py`
- [MITM](https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/src/proxy/mitm.py): tls interception · HTTPS interception and re-encryption boundary. · `src/proxy/mitm.py`

### Relay transport

Outbound packaging and upstream forwarding through fronting.

- [Relay client](https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/src/relay/__init__.py): upstream client · Coordinates outbound relay requests. · `src/relay/__init__.py`
- [Domain fronting](https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/src/relay/domain_fronter.py): fronting logic · Shapes requests to hide the true destination. · `src/relay/domain_fronter.py`
- [HTTP/2 transport](https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/src/relay/h2_transport.py): transport · HTTP/2-based upstream transport to the relay. · `src/relay/h2_transport.py`
- [Relay parser](https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/src/relay/http_reader.py): response handling · Reads and reconstructs relay responses. · `src/relay/http_reader.py`

### Remote relay

Google Apps Script relay and alternate deployment targets.

- [Apps Script](https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/apps_script/Code.gs): remote relay · Google Apps Script web app relay endpoint. · `apps_script/Code.gs`
- [Alt relay](https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/apps_script/cloudflare_worker.js): alternate deployment · Alternative relay/bridge implementation for other runtimes. · `apps_script/cloudflare_worker.js`

### Optional exit

Extra egress path for destinations that reject Google IPs.

- [Exit node](https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/apps_script/vps_exit_node.py): optional egress · Secondary egress path for blocked destinations. · `apps_script/vps_exit_node.py`

### Shared core

Cross-cutting helpers for policy, security, and runtime support.

- [Cert install](https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/src/core/cert_installer.py): trust bootstrap · Installs the local CA certificate used by MITM. · `src/core/cert_installer.py`
- [Policy filter](https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/src/core/adblock.py): traffic policy · Ad blocking and request filtering on ingress. · `src/core/adblock.py`
- [Core utils](https://github.com/masterking32/masterhttprelayvpn/blob/python_testing/src/core/constants.py): shared helpers · Shared constants, logging, encoding, LAN, and Google IP helpers. · `src/core/constants.py`

## Connections

- Browser → Proxy server: HTTP(S) · Browser traffic enters the local proxy.
- LAN peers → Proxy server: shared proxy · LAN clients can reuse the same local proxy.
- Launchers → Main app: starts · Launchers install/load config and start the runtime.
- Main app → Proxy server: boots · Main app initializes the proxy subsystem.
- Proxy server → SOCKS5: SOCKS5 · The proxy exposes a SOCKS5 endpoint.
- Proxy server → MITM: MITM · HTTPS traffic is intercepted for inspection and forwarding.
- MITM → Cert install: trusts CA · MITM depends on the locally installed certificate authority.
- Proxy server → Policy filter: filters · Ingress requests are filtered before upstream dispatch.
- Proxy server → Relay client: forwards · Accepted traffic is handed to the relay client.
- Relay client → Domain fronting: shapes · Relay requests are prepared for domain fronting.
- Relay client → HTTP/2 transport: transports · Outbound relay traffic uses HTTP/2 transport.
- Domain fronting → Apps Script: fronts to · Fronted requests target the Google Apps Script relay.
- HTTP/2 transport → Apps Script: upstream · Transport reaches the remote relay service.
- Apps Script → Relay parser: returns · Responses are read and reconstructed on the way back.
- Relay parser → Proxy server: response · Relay responses flow back to the local proxy.
- Apps Script → Exit node: optional egress · Some deployments chain to an exit node for final delivery.
- Exit node → Alt relay: alt bridge · Exit-node style routing can also be hosted on alternate deployments.
- Proxy server → Core utils: shared core · Proxy behavior relies on shared helpers and runtime utilities.
- Relay client → Core utils: shared core · Relay client reuses codec, logging, IP selection, and constants.
