# taksan/proxy-glass architecture

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

- Interactive diagram: https://gitdiagram.com/taksan/proxy-glass
- Repository: https://github.com/taksan/proxy-glass

## Overview

1. **What the system is**
   ProxyGlass is a local HTTP interception tool with two user-facing surfaces: a **transparent proxy** that sits between a client and a target server, and a **web console** that visualizes captured traffic in real time.

2. **Core runtime topology**
   The app is split into three active roles:
   - **Proxy listener** on `--source-port`
   - **Target forwarder** on `--target-port`
   - **Web UI/API server** on `--web-port`
   
   These all run on the same host, usually `127.0.0.1`, with `--host` controlling bind interface.

3. **Capture and forwarding path**
   The main request flow is: client → proxy listener → target server → proxy listener → client.  
   While forwarding, the proxy records request metadata, bodies, response metadata, timing, and status into shared application state.

4. **Shared state / log storage**
   `proxyglass/logstore.py` is the central state container. It holds the ordered collection of captured entries and is the main boundary between the network-capture side and the UI side. The tests suggest it also supports clearing and persistence-related behavior.

5. **Data model boundary**
   `proxyglass/models.py` defines the structured representation of captured traffic. This is where request/response entry shape, timestamps, durations, and body encoding decisions are likely normalized before being stored or serialized.

6. **Real-time update channel**
   `proxyglass/websocket_manager.py` is the notification layer between the proxy/log store and browsers. When a request is created, updated with a response, or the log is cleared, the manager pushes events to connected WebSocket clients so the UI updates live without polling.

7. **Web application layer**
   `proxyglass/web_app.py` serves the operator-facing interface and JSON endpoints. The documented API is:
   - `GET /api/entries`
   - `GET /api/entries/{id}`
   - `POST /api/clear`
   - `WS /ws`
   
   This is the automation and dashboard boundary for external consumers.

8. **HTML presentation layer**
   `proxyglass/templates/index.html` and `proxyglass/templates/detail.html` are the server-rendered UI surfaces. The browser experience is enhanced with client-side behavior for:
   - split-pane request/detail browsing
   - keyboard navigation
   - WebSocket reconnection
   - JSON pretty-printing / highlighting
   - SSE rendering as structured tables
   - resizable panes

9. **Content-aware rendering**
   The UI treats some payloads specially:
   - `application/json` bodies can be pretty-printed and syntax highlighted
   - `text/event-stream` bodies are rendered as nested event rows
   - JSON inside SSE `data` fields gets its own formatting toggle  
   
   This is presentation logic on top of stored raw traffic, not a change to capture semantics.

10. **Startup and CLI orchestration**
   `proxyglass/cli.py` is the installed command entry point, while `proxyglass/run.py` is a legacy module entry path. These modules parse ports/host/version flags and wire together the proxy server, web server, and shared store.

11. **Observability and operator workflow**
   The operator sends traffic to the proxy port, watches live updates in the web UI, drills into a selected entry for headers/body details, and can clear all logs from the interface or API. The live status indicator and auto-reconnect behavior are part of that operational loop.

12. **Test-driven architecture clues**
   The test suite is broad and maps cleanly to the subsystems:
   - `test_models.py`, `test_logstore.py` for core state
   - `test_proxy_app.py`, `test_streaming_integration.py`, `test_e2e.py` for forwarding and capture
   - `test_web_app.py`, `test_websocket.py` for UI/API/event delivery
   - `test_json_prettify.py`, `test_sse_and_json_highlighting.py`, `test_keyboard_navigation.py`, `test_split_interface.py` for browser behavior  
   
   That suggests a clean separation between capture, storage, realtime broadcast, and presentation.

Main entry points: [`proxyglass/web_app.py`](https://github.com/taksan/proxy-glass/blob/main/proxyglass/web_app.py) (Web app), [`tests`](https://github.com/taksan/proxy-glass/tree/main/tests) (Tests), [`proxyglass/proxy_app.py`](https://github.com/taksan/proxy-glass/blob/main/proxyglass/proxy_app.py) (Proxy app), [`proxyglass/templates/index.html`](https://github.com/taksan/proxy-glass/blob/main/proxyglass/templates/index.html) (Dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_cli["CLI<br/>entrypoint<br/>[cli.py]"]
  node_run["Run path<br/>legacy entrypoint<br/>[run.py]"]
end

subgraph group_core["Core capture"]
  node_proxy_app["Proxy app<br/>proxy server<br/>[proxy_app.py]"]
  node_logstore[("Log store<br/>shared state<br/>[logstore.py]")]
  node_models["Models<br/>traffic schema<br/>[models.py]"]
end

subgraph group_web["Web surface"]
  node_ws_manager(("WebSocket mgr<br/>event broadcaster"))
  node_web_app["Web app<br/>http api<br/>[web_app.py]"]
  node_index_tpl["Dashboard<br/>html view<br/>[index.html]"]
  node_detail_tpl["Detail view<br/>html view<br/>[detail.html]"]
  node_entries_api["Entries API<br/>endpoint<br/>[web_app.py]"]
  node_clear_api["Clear API<br/>endpoint<br/>[web_app.py]"]
  node_ws_api(("Live WS<br/>endpoint<br/>[web_app.py]"))
  node_browser_ui["Browser UI<br/>client logic<br/>[index.html]"]
  node_json_render["JSON render<br/>presentation logic<br/>[index.html]"]
  node_sse_render["SSE render<br/>presentation logic<br/>[index.html]"]
end

node_tests["Tests<br/>verification suite"]

node_cli -->|"starts"| node_proxy_app
node_cli -->|"starts"| node_web_app
node_cli -->|"shares"| node_logstore
node_run -.->|"delegates"| node_cli
node_proxy_app -->|"normalizes"| node_models
node_proxy_app -->|"stores"| node_logstore
node_proxy_app -->|"publishes"| node_ws_manager
node_logstore -->|"contains"| node_models
node_web_app -->|"exposes"| node_entries_api
node_web_app -->|"exposes"| node_clear_api
node_web_app -->|"exposes"| node_ws_api
node_web_app -->|"renders"| node_index_tpl
node_web_app -->|"renders"| node_detail_tpl
node_ws_manager -->|"feeds"| node_ws_api
node_index_tpl -->|"contains"| node_browser_ui
node_index_tpl -->|"formats"| node_json_render
node_index_tpl -->|"formats"| node_sse_render
node_browser_ui -->|"reads"| node_entries_api
node_browser_ui -->|"subscribes"| node_ws_api
node_browser_ui -->|"clears"| node_clear_api
node_detail_tpl -->|"uses"| node_json_render
node_detail_tpl -->|"uses"| node_sse_render
node_tests -.->|"verifies"| node_models
node_tests -.->|"verifies"| node_logstore
node_tests -.->|"verifies"| node_proxy_app
node_tests -.->|"verifies"| node_web_app
node_tests -.->|"verifies"| node_ws_manager

click node_cli "https://github.com/taksan/proxy-glass/blob/main/proxyglass/cli.py"
click node_run "https://github.com/taksan/proxy-glass/blob/main/proxyglass/run.py"
click node_proxy_app "https://github.com/taksan/proxy-glass/blob/main/proxyglass/proxy_app.py"
click node_logstore "https://github.com/taksan/proxy-glass/blob/main/proxyglass/logstore.py"
click node_models "https://github.com/taksan/proxy-glass/blob/main/proxyglass/models.py"
click node_ws_manager "https://github.com/taksan/proxy-glass/blob/main/proxyglass/websocket_manager.py"
click node_web_app "https://github.com/taksan/proxy-glass/blob/main/proxyglass/web_app.py"
click node_index_tpl "https://github.com/taksan/proxy-glass/blob/main/proxyglass/templates/index.html"
click node_detail_tpl "https://github.com/taksan/proxy-glass/blob/main/proxyglass/templates/detail.html"
click node_entries_api "https://github.com/taksan/proxy-glass/blob/main/proxyglass/web_app.py"
click node_clear_api "https://github.com/taksan/proxy-glass/blob/main/proxyglass/web_app.py"
click node_ws_api "https://github.com/taksan/proxy-glass/blob/main/proxyglass/web_app.py"
click node_browser_ui "https://github.com/taksan/proxy-glass/blob/main/proxyglass/templates/index.html"
click node_json_render "https://github.com/taksan/proxy-glass/blob/main/proxyglass/templates/index.html"
click node_sse_render "https://github.com/taksan/proxy-glass/blob/main/proxyglass/templates/index.html"
click node_tests "https://github.com/taksan/proxy-glass/tree/main/tests"

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_cli,node_run toneBlue
class node_proxy_app,node_logstore,node_models toneAmber
class node_ws_manager,node_web_app,node_index_tpl,node_detail_tpl,node_entries_api,node_clear_api,node_ws_api,node_browser_ui,node_json_render,node_sse_render toneMint
class node_tests toneNeutral
```

## Components

### Runtime

Command-line startup and the active proxy/web processes

- [CLI](https://github.com/taksan/proxy-glass/blob/main/proxyglass/cli.py): entrypoint · Installed command entry point that parses host and port flags and wires the app together · `proxyglass/cli.py`
- [Run path](https://github.com/taksan/proxy-glass/blob/main/proxyglass/run.py): legacy entrypoint · Legacy module entry path for starting the application · `proxyglass/run.py`

### Core capture

Traffic capture, storage, and data model boundaries

- [Proxy app](https://github.com/taksan/proxy-glass/blob/main/proxyglass/proxy_app.py): proxy server · Transparent proxy listener and forwarding pipeline between client and target server · `proxyglass/proxy_app.py`
- [Log store](https://github.com/taksan/proxy-glass/blob/main/proxyglass/logstore.py): shared state · Ordered capture store and boundary between network interception and UI access · `proxyglass/logstore.py`
- [Models](https://github.com/taksan/proxy-glass/blob/main/proxyglass/models.py): traffic schema · Structured request and response entry model with timing and body normalization · `proxyglass/models.py`

### Web surface

HTTP API, websocket updates, and rendered browser UI

- [WebSocket mgr](https://github.com/taksan/proxy-glass/blob/main/proxyglass/websocket_manager.py): event broadcaster · Pushes create update and clear events from capture state to connected browsers · `proxyglass/websocket_manager.py`
- [Web app](https://github.com/taksan/proxy-glass/blob/main/proxyglass/web_app.py): http api · Operator-facing HTTP API and websocket endpoint for browsing and clearing captures · `proxyglass/web_app.py`
- [Dashboard](https://github.com/taksan/proxy-glass/blob/main/proxyglass/templates/index.html): html view · Main split-pane traffic browser and live status interface · `proxyglass/templates/index.html`
- [Detail view](https://github.com/taksan/proxy-glass/blob/main/proxyglass/templates/detail.html): html view · Selected-entry page for headers bodies and deep inspection · `proxyglass/templates/detail.html`
- [Entries API](https://github.com/taksan/proxy-glass/blob/main/proxyglass/web_app.py): endpoint · Lists captured entries and fetches individual entry details · `proxyglass/web_app.py`
- [Clear API](https://github.com/taksan/proxy-glass/blob/main/proxyglass/web_app.py): endpoint · Clears captured logs from the shared store · `proxyglass/web_app.py`
- [Live WS](https://github.com/taksan/proxy-glass/blob/main/proxyglass/web_app.py): endpoint · WebSocket channel for real-time UI updates · `proxyglass/web_app.py`
- [Browser UI](https://github.com/taksan/proxy-glass/blob/main/proxyglass/templates/index.html): client logic · Client-side behavior for navigation reconnection resizing and formatting · `proxyglass/templates/index.html`
- [JSON render](https://github.com/taksan/proxy-glass/blob/main/proxyglass/templates/index.html): presentation logic · Pretty printing and highlighting for JSON bodies and nested JSON payloads · `proxyglass/templates/index.html`
- [SSE render](https://github.com/taksan/proxy-glass/blob/main/proxyglass/templates/index.html): presentation logic · Structured rendering for text event stream bodies and data fields · `proxyglass/templates/index.html`

### Other components

- [Tests](https://github.com/taksan/proxy-glass/tree/main/tests): verification suite · Architecture-level coverage for models storage proxy flow web UI websocket and persistence · `tests`

## Connections

- CLI → Proxy app: starts · Creates and configures the proxy listener
- CLI → Web app: starts · Creates and configures the web server
- CLI → Log store: shares · Provides shared capture state to both runtimes
- Run path → CLI: delegates · Legacy entry path forwards into the main CLI startup
- Proxy app → Models: normalizes · Builds structured traffic entries from live request and response data
- Proxy app → Log store: stores · Writes captured entries and updates into shared state
- Proxy app → WebSocket mgr: publishes · Notifies live clients when entries are created or updated
- Log store → Models: contains · Holds ordered captured entries using the shared entry schema
- Web app → Entries API: exposes · Serves entry listing and detail retrieval endpoints
- Web app → Clear API: exposes · Serves the log clearing endpoint
- Web app → Live WS: exposes · Serves the browser websocket endpoint
- Web app → Dashboard: renders · Serves the main dashboard page
- Web app → Detail view: renders · Serves the entry detail page
- WebSocket mgr → Live WS: feeds · Delivers live events to connected browser clients
- Dashboard → Browser UI: contains · Hosts the client-side behavior for live browsing
- Dashboard → JSON render: formats · Pretty prints and highlights JSON payloads
- Dashboard → SSE render: formats · Renders event-stream payloads as structured rows
- Browser UI → Entries API: reads · Loads the capture list and entry details
- Browser UI → Live WS: subscribes · Receives live updates and reconnects on disconnect
- Browser UI → Clear API: clears · Triggers log clearing from the UI
- Detail view → JSON render: uses · Applies content-aware formatting for bodies and payloads
- Detail view → SSE render: uses · Applies event-stream specific rendering
- Tests → Models: verifies · Covers entry schema and normalization behavior
- Tests → Log store: verifies · Covers storage clearing ordering and persistence behavior
- Tests → Proxy app: verifies · Covers forwarding capture and streaming integration
- Tests → Web app: verifies · Covers HTTP API and dashboard behavior
- Tests → WebSocket mgr: verifies · Covers websocket event delivery
