# zhongerxin/iphone-use architecture

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

- Interactive diagram: https://gitdiagram.com/zhongerxin/iphone-use
- Repository: https://github.com/zhongerxin/iphone-use

## Overview

iPhone Use is a local MCP product for controlling a real iPhone over USB through WebDriverAgent (WDA), with setup guidance and a live screen preview. The principal workflow is an assistant invoking MCP tools: the server routes setup or phone actions, obtains app and page state or performs gestures through WDA, and returns observations and screenshots. A separate widget displays the live screen. The graph includes documented WorkBuddy and Doubao host adapters; unsampled wiring is omitted unless documented. The experimental tree-handle driver is excluded as an opt-in experiment.

Main entry points: [`server/iphone_use.py`](https://github.com/zhongerxin/iphone-use/blob/main/server/iphone_use.py) (Codex MCP), [`server/wda_screen.py`](https://github.com/zhongerxin/iphone-use/blob/main/server/wda_screen.py) (Screen capture), [`workbuddy/mcp_server.py`](https://github.com/zhongerxin/iphone-use/blob/main/workbuddy/mcp_server.py) (WorkBuddy MCP), [`server/wda_controller.py`](https://github.com/zhongerxin/iphone-use/blob/main/server/wda_controller.py) (Phone actions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_hosts["Host integrations"]
  node_codex["Codex MCP<br/>[iphone_use.py]"]
  node_workbuddy["WorkBuddy MCP<br/>[mcp_server.py]"]
  node_workbuddy_text["WorkBuddy adaptation<br/>[host_text.py]"]
  node_workbuddy_preview["WorkBuddy frame source<br/>[preview.py]"]
  node_doubao["Doubao MCP<br/>[mcp_stdio.py]"]
  node_doubao_text["Doubao adaptation<br/>[doubao_text.py]"]
end

subgraph group_runtime["MCP runtime"]
  node_setup["Setup and readiness<br/>[wda_setup.py]"]
  node_analytics["Usage analytics<br/>[analytics.py]"]
end

subgraph group_device["Device operations"]
  node_controller["Phone actions<br/>[wda_controller.py]"]
  node_client["WDA transport<br/>[wda_client.py]"]
  node_text["Text input<br/>[wda_text.py]"]
  node_image["Screenshot processing<br/>[wda_image.py]"]
  node_apps["App discovery<br/>[wda_apps.py]"]
end

subgraph group_preview["Screen preview"]
  node_screenhub["Screen capture<br/>[wda_screen.py]"]
  node_widget["Screen widget<br/>[app.ts]"]
  node_forward["USB forwarding<br/>[forward.mjs]"]
  node_stream["Screen streaming<br/>[screen-stream.mjs]"]
end

node_assistant(("Assistant"))
node_iphone(("iPhone"))
node_wda["WebDriverAgent"]
node_apple["Apple catalog"]

node_assistant -->|"calls tools"| node_codex
node_assistant -->|"calls tools"| node_workbuddy
node_assistant -->|"calls tools"| node_doubao
node_workbuddy -->|"adapts runtime"| node_codex
node_workbuddy -->|"rewrites guidance"| node_workbuddy_text
node_workbuddy -->|"starts preview"| node_workbuddy_preview
node_doubao -->|"adapts runtime"| node_codex
node_doubao -->|"adapts text"| node_doubao_text
node_codex -->|"routes setup"| node_setup
node_codex -->|"routes actions"| node_controller
node_codex -->|"routes app lookup"| node_apps
node_codex -->|"routes preview"| node_screenhub
node_codex -->|"records usage"| node_analytics
node_controller -->|"sends commands"| node_client
node_controller -->|"delegates input"| node_text
node_controller -->|"processes screenshots"| node_image
node_client -->|"sends HTTP"| node_wda
node_wda -->|"controls device"| node_iphone
node_apps -->|"queries installed apps"| node_client
node_apps -->|"looks up catalog"| node_apple
node_screenhub -->|"captures frames"| node_wda
node_widget -->|"shows live screen"| node_screenhub
node_workbuddy_preview -->|"reads frames"| node_screenhub
node_forward -.->|"forwards USB"| node_wda
node_stream -.->|"streams frames"| node_screenhub

click node_codex "https://github.com/zhongerxin/iphone-use/blob/main/server/iphone_use.py"
click node_workbuddy "https://github.com/zhongerxin/iphone-use/blob/main/workbuddy/mcp_server.py"
click node_workbuddy_text "https://github.com/zhongerxin/iphone-use/blob/main/workbuddy/host_text.py"
click node_workbuddy_preview "https://github.com/zhongerxin/iphone-use/blob/main/workbuddy/preview.py"
click node_doubao "https://github.com/zhongerxin/iphone-use/blob/main/doubao/mcp_stdio.py"
click node_doubao_text "https://github.com/zhongerxin/iphone-use/blob/main/doubao/doubao_text.py"
click node_setup "https://github.com/zhongerxin/iphone-use/blob/main/server/wda_setup.py"
click node_analytics "https://github.com/zhongerxin/iphone-use/blob/main/server/analytics.py"
click node_controller "https://github.com/zhongerxin/iphone-use/blob/main/server/wda_controller.py"
click node_client "https://github.com/zhongerxin/iphone-use/blob/main/server/wda_client.py"
click node_text "https://github.com/zhongerxin/iphone-use/blob/main/server/wda_text.py"
click node_image "https://github.com/zhongerxin/iphone-use/blob/main/server/wda_image.py"
click node_apps "https://github.com/zhongerxin/iphone-use/blob/main/server/wda_apps.py"
click node_screenhub "https://github.com/zhongerxin/iphone-use/blob/main/server/wda_screen.py"
click node_widget "https://github.com/zhongerxin/iphone-use/blob/main/ui/src/app.ts"
click node_forward "https://github.com/zhongerxin/iphone-use/blob/main/tooling/forward.mjs"
click node_stream "https://github.com/zhongerxin/iphone-use/blob/main/tooling/screen-stream.mjs"

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_codex,node_workbuddy,node_workbuddy_text,node_workbuddy_preview,node_doubao,node_doubao_text toneBlue
class node_setup,node_analytics toneAmber
class node_controller,node_client,node_text,node_image,node_apps toneMint
class node_screenhub,node_widget,node_forward,node_stream toneRose
class node_assistant,node_iphone,node_wda,node_apple toneIndigo
```

## Components

### Host integrations

- [Codex MCP](https://github.com/zhongerxin/iphone-use/blob/main/server/iphone_use.py): `server/iphone_use.py`
- [WorkBuddy MCP](https://github.com/zhongerxin/iphone-use/blob/main/workbuddy/mcp_server.py): `workbuddy/mcp_server.py`
- [WorkBuddy adaptation](https://github.com/zhongerxin/iphone-use/blob/main/workbuddy/host_text.py): `workbuddy/host_text.py`
- [WorkBuddy frame source](https://github.com/zhongerxin/iphone-use/blob/main/workbuddy/preview.py): `workbuddy/preview.py`
- [Doubao MCP](https://github.com/zhongerxin/iphone-use/blob/main/doubao/mcp_stdio.py): `doubao/mcp_stdio.py`
- [Doubao adaptation](https://github.com/zhongerxin/iphone-use/blob/main/doubao/doubao_text.py): `doubao/doubao_text.py`

### MCP runtime

- [Setup and readiness](https://github.com/zhongerxin/iphone-use/blob/main/server/wda_setup.py): `server/wda_setup.py`
- [Usage analytics](https://github.com/zhongerxin/iphone-use/blob/main/server/analytics.py): `server/analytics.py`

### Device operations

- [Phone actions](https://github.com/zhongerxin/iphone-use/blob/main/server/wda_controller.py): `server/wda_controller.py`
- [WDA transport](https://github.com/zhongerxin/iphone-use/blob/main/server/wda_client.py): `server/wda_client.py`
- [Text input](https://github.com/zhongerxin/iphone-use/blob/main/server/wda_text.py): `server/wda_text.py`
- [Screenshot processing](https://github.com/zhongerxin/iphone-use/blob/main/server/wda_image.py): `server/wda_image.py`
- [App discovery](https://github.com/zhongerxin/iphone-use/blob/main/server/wda_apps.py): `server/wda_apps.py`

### Screen preview

- [Screen capture](https://github.com/zhongerxin/iphone-use/blob/main/server/wda_screen.py): `server/wda_screen.py`
- [Screen widget](https://github.com/zhongerxin/iphone-use/blob/main/ui/src/app.ts): `ui/src/app.ts`
- [USB forwarding](https://github.com/zhongerxin/iphone-use/blob/main/tooling/forward.mjs): `tooling/forward.mjs`
- [Screen streaming](https://github.com/zhongerxin/iphone-use/blob/main/tooling/screen-stream.mjs): `tooling/screen-stream.mjs`

### Other components

- **Assistant**
- **iPhone**
- **WebDriverAgent**
- **Apple catalog**

## Connections

- Assistant → Codex MCP: calls tools (evidence: `README.md`)
- Assistant → WorkBuddy MCP: calls tools (evidence: `README.md`)
- Assistant → Doubao MCP: calls tools (evidence: `README.md`)
- WorkBuddy MCP → Codex MCP: adapts runtime (evidence: `workbuddy/mcp_server.py`)
- WorkBuddy MCP → WorkBuddy adaptation: rewrites guidance (evidence: `workbuddy/mcp_server.py`)
- WorkBuddy MCP → WorkBuddy frame source: starts preview (evidence: `workbuddy/mcp_server.py`)
- Doubao MCP → Codex MCP: adapts runtime (evidence: `doubao/mcp_stdio.py`)
- Doubao MCP → Doubao adaptation: adapts text (evidence: `doubao/doubao_text.py`)
- Codex MCP → Setup and readiness: routes setup (evidence: `server/iphone_use.py`)
- Codex MCP → Phone actions: routes actions (evidence: `server/iphone_use.py`)
- Codex MCP → App discovery: routes app lookup (evidence: `server/iphone_use.py`)
- Codex MCP → Screen capture: routes preview (evidence: `server/iphone_use.py`)
- Codex MCP → Usage analytics: records usage (evidence: `server/iphone_use.py`)
- Phone actions → WDA transport: sends commands (evidence: `server/wda_controller.py`)
- Phone actions → Text input: delegates input (evidence: `server/wda_controller.py`)
- Phone actions → Screenshot processing: processes screenshots (evidence: `server/wda_controller.py`)
- WDA transport → WebDriverAgent: sends HTTP (evidence: `README.md`)
- WebDriverAgent → iPhone: controls device (evidence: `README.md`)
- App discovery → WDA transport: queries installed apps (evidence: `README.md`)
- App discovery → Apple catalog: looks up catalog (evidence: `server/wda_apps.py`)
- Screen capture → WebDriverAgent: captures frames (evidence: `README.md`)
- Screen widget → Screen capture: shows live screen (evidence: `README.md`)
- WorkBuddy frame source → Screen capture: reads frames (evidence: `workbuddy/preview.py`)
- USB forwarding → WebDriverAgent: forwards USB (evidence: `README.md`)
- Screen streaming → Screen capture: streams frames (evidence: `README.md`)
