# emprider/cursor-byok architecture

> Architecture diagram of the GitHub repository emprider/cursor-byok, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/emprider/cursor-byok
- Repository: https://github.com/emprider/cursor-byok

## Overview

1. This repository is a cross-platform desktop application, not just a backend library. The top-level shape is: a Go runtime and local service layer, a Vue-based embedded UI, and several supporting subsystems for Cursor integration, model-provider routing, and network/proxy control.

2. The desktop shell is built around Wails 3. The frontend lives in `frontend/` and is packaged into the Go app through generated Wails bindings under `build/frontend/bindings/...`. The UI pages (`Home`, `Config`, `ModelConfig`, `ModelEditor`) are driven by a small client API layer and shared app state, so the browser-like UI is only a presentation layer over backend-managed state.

3. The backend entry point is `main.go` plus `internal/app`. That layer owns application startup, tray/locale behavior, appdata path management, migration, and update lifecycle. It is the orchestration boundary for the whole desktop app.

4. The core control plane is `internal/backend/server`. It provides configuration management, request routing, local middleware/policy enforcement, and a notion of “upstream” communication. This is the part that likely exposes the local API the UI uses and coordinates access to external model services or Cursor services.

5. The most important execution pipeline is `internal/backend/forwarder`. This subsystem appears to be the agent/session engine: it handles prompts, tool catalogs, tool execution, file writes, shell recovery, compaction, runtime summaries, token accounting, replay/debug artifacts, and workspace/index maintenance. In architecture terms, it is the layer that turns UI/config input into agent actions and streamed results.

6. Agent behavior is split from forwarding mechanics in `internal/backend/agent`. That package contains:
   - `core` for plan creation, tool arguments, and MCP-related logic,
   - `model` adapters for providers such as OpenAI and Anthropic,
   - `prompt` rendering/replay support,
   - `protocol` and `bridge` layers for execution/interaction boundaries,
   - `step` recording for tracing or replay.
   This is the provider-agnostic agent abstraction layer.

7. Cursor-specific integration is handled by `internal/cursor`, `internal/client`, `internal/bridge`, and `internal/mitm`. These packages manage Cursor app state, device/cert handling, client lifecycle, licensing/config discovery, localization/window integration, and local relay behavior. The presence of `internal/certs`, `internal/netproxy`, and MITM code strongly suggests the app intercepts or reroutes Cursor’s network traffic through a local trusted proxy.

8. The runtime’s external I/O boundary is therefore local-first: the UI talks to the Go backend; the backend reads Cursor/app state and configuration; the proxy/cert layer can intercept requests; and the model adapter layer sends normalized requests to external model APIs. The main external services are model providers and whatever upstream Cursor-related API the project proxies or emulates.

9. There is a separate `cursor-tab-server/` Go service. It is an auxiliary server with its own `go.mod`, config, Dockerfile, and README, so it should be treated as a standalone deployment unit rather than a library. It likely supports a specific browser/tab or extension workflow alongside the main desktop app.

10. Protocol compatibility is a first-class concern. The `proto/` tree contains `agent_v1.proto`, `aiserver_v1.proto`, extracted extension protos, and helper tooling. This indicates the project preserves or reuses Cursor/extension wire contracts so it can interoperate with existing Cursor components and extension-style tooling.

11. The repo is heavily platform-aware. There are OS-specific implementations for macOS, Windows, and Linux in network proxy, certificates, packaging, tray behavior, and build scripts. The `build/` tree contains Wails/build packaging, DMG, NSIS, MSIX, Docker cross-builds, and release workflow automation, so deployment differs by platform even though the application architecture is shared.

12. Operationally, the app also maintains local state and telemetry-like history data. `internal/appdata`, `internal/historymetrics`, and the related scripts suggest persisted config/history/usage data and reporting around cache or usage metrics. Those are supporting services around the main agent/proxy flow, not the primary user interaction path.

Main entry points: [`internal/app`](https://github.com/emprider/cursor-byok/tree/main/internal/app) (App runtime), [`internal/backend/forwarder`](https://github.com/emprider/cursor-byok/tree/main/internal/backend/forwarder) (Forwarder), [`internal/backend/server`](https://github.com/emprider/cursor-byok/tree/main/internal/backend/server) (Local server), [`frontend`](https://github.com/emprider/cursor-byok/tree/main/frontend) (Vue UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_shell["Desktop shell"]
  node_node_main["App entry<br/>go entrypoint<br/>[main.go]"]
  node_node_app["App runtime<br/>startup/orchestration"]
  node_node_frontend["Vue UI<br/>embedded frontend"]
  node_node_wails["Wails bindings<br/>generated bridge<br/>[internal]"]
  node_node_updater["Updater<br/>release/update"]
end

subgraph group_group_backend["Backend core"]
  node_node_server["Local server<br/>control plane"]
  node_node_forwarder["Forwarder<br/>agent session engine"]
  node_node_agent["Agent core<br/>provider-agnostic agent"]
  node_node_model["Model routing<br/>provider adapters"]
  node_node_prompt["Prompt system<br/>prompt rendering"]
end

subgraph group_group_integration["Cursor integration"]
  node_node_cursor["Cursor state<br/>app integration"]
  node_node_client["Client lifecycle<br/>cursor client"]
  node_node_bridge["Local bridge<br/>interop layer"]
  node_node_mitm["MITM relay<br/>traffic relay"]
  node_node_certs[("Certs<br/>trust material")]
  node_node_proxy["Net proxy<br/>system proxy"]
end

subgraph group_group_contracts["Contracts"]
  node_node_proto["Wire contracts<br/>protobuf contracts"]
  node_node_prompt_assets["Prompt assets<br/>embedded prompts"]
end

subgraph group_group_aux["Auxiliary service"]
  node_node_tab_server["Tab server<br/>auxiliary service"]
end

node_node_main -->|"boots"| node_node_app
node_node_app -->|"hosts"| node_node_frontend
node_node_frontend -->|"calls"| node_node_wails
node_node_frontend -->|"uses API"| node_node_server
node_node_app -->|"initializes"| node_node_server
node_node_server -->|"dispatches"| node_node_forwarder
node_node_forwarder -->|"invokes"| node_node_agent
node_node_agent -->|"adapts"| node_node_model
node_node_agent -->|"renders"| node_node_prompt
node_node_forwarder -.->|"speaks"| node_node_proto
node_node_forwarder -->|"loads"| node_node_prompt_assets
node_node_app -->|"manages"| node_node_updater
node_node_app -->|"bridges"| node_node_bridge
node_node_server -->|"routes"| node_node_mitm
node_node_mitm -->|"trusts"| node_node_certs
node_node_mitm -->|"controls"| node_node_proxy
node_node_client -->|"reads state"| node_node_cursor
node_node_bridge -.->|"configures"| node_node_proxy
node_node_tab_server -.->|"compatible with"| node_node_proto
node_node_forwarder -.->|"supports"| node_node_tab_server

click node_node_main "https://github.com/emprider/cursor-byok/blob/main/main.go"
click node_node_app "https://github.com/emprider/cursor-byok/tree/main/internal/app"
click node_node_frontend "https://github.com/emprider/cursor-byok/tree/main/frontend"
click node_node_wails "https://github.com/emprider/cursor-byok/blob/main/build/frontend/bindings/github.com/wailsapp/wails/v3/internal"
click node_node_server "https://github.com/emprider/cursor-byok/tree/main/internal/backend/server"
click node_node_forwarder "https://github.com/emprider/cursor-byok/tree/main/internal/backend/forwarder"
click node_node_agent "https://github.com/emprider/cursor-byok/tree/main/internal/backend/agent"
click node_node_model "https://github.com/emprider/cursor-byok/tree/main/internal/backend/agent/model"
click node_node_prompt "https://github.com/emprider/cursor-byok/tree/main/internal/backend/agent/prompt"
click node_node_cursor "https://github.com/emprider/cursor-byok/tree/main/internal/cursor"
click node_node_client "https://github.com/emprider/cursor-byok/tree/main/internal/client"
click node_node_bridge "https://github.com/emprider/cursor-byok/tree/main/internal/bridge"
click node_node_mitm "https://github.com/emprider/cursor-byok/tree/main/internal/mitm"
click node_node_certs "https://github.com/emprider/cursor-byok/tree/main/internal/certs"
click node_node_proxy "https://github.com/emprider/cursor-byok/tree/main/internal/netproxy"
click node_node_proto "https://github.com/emprider/cursor-byok/tree/main/proto"
click node_node_prompt_assets "https://github.com/emprider/cursor-byok/tree/main/prompt"
click node_node_tab_server "https://github.com/emprider/cursor-byok/tree/main/cursor-tab-server"
click node_node_updater "https://github.com/emprider/cursor-byok/tree/main/internal/updater"

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_app,node_node_frontend,node_node_wails,node_node_updater toneBlue
class node_node_server,node_node_forwarder,node_node_agent,node_node_model,node_node_prompt toneAmber
class node_node_cursor,node_node_client,node_node_bridge,node_node_mitm,node_node_certs,node_node_proxy toneMint
class node_node_proto,node_node_prompt_assets toneRose
class node_node_tab_server toneIndigo
```

## Components

### Desktop shell

Wails-based desktop application UI and startup orchestration.

- [App entry](https://github.com/emprider/cursor-byok/blob/main/main.go): go entrypoint · Process bootstrap and top-level execution. · `main.go`
- [App runtime](https://github.com/emprider/cursor-byok/tree/main/internal/app): startup/orchestration · App lifecycle, tray/locale behavior, migrations, and update coordination. · `internal/app`
- [Vue UI](https://github.com/emprider/cursor-byok/tree/main/frontend): embedded frontend · Presentation layer with views, state, router, and client API. · `frontend`
- [Wails bindings](https://github.com/emprider/cursor-byok/blob/main/build/frontend/bindings/github.com/wailsapp/wails/v3/internal): generated bridge · Generated frontend bindings used to connect the web UI to the Go backend. · `build/frontend/bindings/github.com/wailsapp/wails/v3/internal`
- [Updater](https://github.com/emprider/cursor-byok/tree/main/internal/updater): release/update · Versioning and update management for the desktop application. · `internal/updater`

### Backend core

Local API, agent pipeline, and runtime services inside the Go app.

- [Local server](https://github.com/emprider/cursor-byok/tree/main/internal/backend/server): control plane · Configuration, routing, middleware, and upstream coordination for the local API. · `internal/backend/server`
- [Forwarder](https://github.com/emprider/cursor-byok/tree/main/internal/backend/forwarder): agent session engine · Core execution pipeline for prompts, tools, file writes, replay, and workspace maintenance. · `internal/backend/forwarder`
- [Agent core](https://github.com/emprider/cursor-byok/tree/main/internal/backend/agent): provider-agnostic agent · Agent abstraction layer for plans, prompts, protocol boundaries, steps, and model adapters. · `internal/backend/agent`
- [Model routing](https://github.com/emprider/cursor-byok/tree/main/internal/backend/agent/model): provider adapters · Normalization and routing for model providers such as OpenAI and Anthropic. · `internal/backend/agent/model`
- [Prompt system](https://github.com/emprider/cursor-byok/tree/main/internal/backend/agent/prompt): prompt rendering · Prompt templates, rendering, and replay support for agent interactions. · `internal/backend/agent/prompt`

### Cursor integration

Cursor app state, client lifecycle, proxying, certs, and MITM relay.

- [Cursor state](https://github.com/emprider/cursor-byok/tree/main/internal/cursor): app integration · Cursor settings, device identity, and local state database access. · `internal/cursor`
- [Client lifecycle](https://github.com/emprider/cursor-byok/tree/main/internal/client): cursor client · License, lifecycle, config discovery, and model-adapter-related client behavior. · `internal/client`
- [Local bridge](https://github.com/emprider/cursor-byok/tree/main/internal/bridge): interop layer · Window, localization, metrics, and proxy-facing bridge helpers. · `internal/bridge`
- [MITM relay](https://github.com/emprider/cursor-byok/tree/main/internal/mitm): traffic relay · Local relay service that participates in request interception and forwarding. · `internal/mitm`
- [Certs](https://github.com/emprider/cursor-byok/tree/main/internal/certs): trust material · Local certificate authority material used for trusted interception. · `internal/certs`
- [Net proxy](https://github.com/emprider/cursor-byok/tree/main/internal/netproxy): system proxy · Platform-specific proxy control for redirecting local and external traffic. · `internal/netproxy`

### Contracts

Protocol buffers and prompt assets that define external and agent-facing interfaces.

- [Wire contracts](https://github.com/emprider/cursor-byok/tree/main/proto): protobuf contracts · Agent and server protocol definitions plus extracted extension schemas. · `proto`
- [Prompt assets](https://github.com/emprider/cursor-byok/tree/main/prompt): embedded prompts · Packaged prompts and tool manifests used by agent modes. · `prompt`

### Auxiliary service

Standalone supporting server shipped alongside the main desktop app.

- [Tab server](https://github.com/emprider/cursor-byok/tree/main/cursor-tab-server): auxiliary service · Standalone Go service with its own deployment and config for tab/extension workflows. · `cursor-tab-server`

## Connections

- App entry → App runtime: boots · Main process starts the application runtime.
- App runtime → Vue UI: hosts · The runtime serves the embedded UI.
- Vue UI → Wails bindings: calls · UI actions use generated Wails bindings to reach Go services.
- Vue UI → Local server: uses API · Views and shared state are backed by the local control plane.
- App runtime → Local server: initializes · App startup wires the local backend server.
- Local server → Forwarder: dispatches · The control plane routes agent work into the execution pipeline.
- Forwarder → Agent core: invokes · Forwarder uses provider-agnostic agent logic for plans and tools.
- Agent core → Model routing: adapts · Agent logic normalizes provider-specific model interactions.
- Agent core → Prompt system: renders · Prompt templates and replay logic shape agent requests.
- Forwarder → Wire contracts: speaks · Pipeline respects protocol and compatibility contracts.
- Forwarder → Prompt assets: loads · Packaged prompts define behavior for different agent modes.
- App runtime → Updater: manages · Application runtime coordinates update lifecycle.
- App runtime → Local bridge: bridges · Desktop shell integrates window, localization, and metrics helpers.
- Local server → MITM relay: routes · Server-side policy can direct traffic through local relay behavior.
- MITM relay → Certs: trusts · MITM interception relies on local CA material.
- MITM relay → Net proxy: controls · Relay behavior depends on platform proxy control.
- Client lifecycle → Cursor state: reads state · Client lifecycle is tied to Cursor configuration and state.
- Local bridge → Net proxy: configures · Bridge helpers participate in proxy and window integration.
- Tab server → Wire contracts: compatible with · Auxiliary server participates in the same protocol ecosystem.
- Forwarder → Tab server: supports · Auxiliary service may feed or complement forwarder workflows.
