# derrors/iphone-control architecture

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

- Interactive diagram: https://gitdiagram.com/derrors/iphone-control
- Repository: https://github.com/derrors/iphone-control

## Overview

iphone-control is a Rust application for AI agents to operate real iPhones and iPads. The main workflow is an agent issuing MCP actions, the daemon routing them through native iOS 27+ control or WebDriverAgent on iOS 17–26, and the device returning screen or UI state. The optional viewer adds browser control, live video, remote MCP, and supervised agent tasks; supporting branches cover signing, recovery, unlock, notifications, and diagnostics. Some subsystem paths and links are based on README capabilities because their source was not sampled.

Main entry points: [`crates/ictl-daemon/src/core.rs`](https://github.com/derrors/iphone-control/blob/main/crates/ictl-daemon/src/core.rs) (Daemon core), [`apps/iphone-control/src/viewer/server.rs`](https://github.com/derrors/iphone-control/blob/main/apps/iphone-control/src/viewer/server.rs) (Viewer server), [`crates/ictl-mcp/src/server.rs`](https://github.com/derrors/iphone-control/blob/main/crates/ictl-mcp/src/server.rs) (MCP server), [`apps/iphone-control/src/viewer/routes.rs`](https://github.com/derrors/iphone-control/blob/main/apps/iphone-control/src/viewer/routes.rs) (Viewer routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Agent access"]
  node_cli["CLI entry<br/>[main.rs]"]
  node_mcp["MCP server<br/>[server.rs]"]
  node_protocol["Daemon protocol<br/>[client.rs]"]
  node_taskrun["Agent task runner<br/>[agent.rs]"]
end

subgraph group_daemon["Device daemon"]
  node_daemoncore["Daemon core<br/>[core.rs]"]
  node_taskcontrol["Task control<br/>[tasks.rs]"]
end

subgraph group_control["Device control"]
  node_native["Native device control<br/>[lib.rs]"]
  node_wda["WebDriverAgent client<br/>[client.rs]"]
  node_accessibility["Accessibility tree<br/>[session.rs]"]
  node_uiquery["UI queries<br/>[query.rs]"]
  node_unlock["Auto-unlock<br/>[durable.rs]"]
end

subgraph group_viewer["Browser viewer"]
  node_viewer["Viewer server<br/>[server.rs]"]
  node_routes["Viewer routes<br/>[routes.rs]"]
  node_auth["Login and access<br/>[auth.rs]"]
  node_webui["Browser controls<br/>[tasks.js]"]
  node_video["Live video<br/>[mod.rs]"]
end

subgraph group_operations["Operations"]
  node_signing["WDA signing<br/>[lib.rs]"]
  node_supervision["WDA supervision<br/>[session.rs]"]
  node_alerts["Notifications<br/>[notify.rs]"]
  node_diagnostics["Diagnostics<br/>[doctor.rs]"]
  node_service["Background service<br/>[service.rs]"]
end

node_agent(("AI agent"))
node_user(("User"))
node_phone["iPhone or iPad"]
node_browser(("Browser user"))

node_agent -->|"calls tools"| node_mcp
node_mcp -->|"sends requests"| node_protocol
node_cli -->|"uses client"| node_protocol
node_taskrun -.->|"starts agent access"| node_mcp
node_mcp -->|"forwards actions"| node_daemoncore
node_protocol -->|"sends requests"| node_daemoncore
node_daemoncore -->|"checks admission"| node_taskcontrol
node_daemoncore -->|"uses native route"| node_native
node_daemoncore -->|"uses legacy route"| node_wda
node_native -->|"controls device"| node_phone
node_wda -->|"controls device"| node_phone
node_daemoncore -.->|"reads UI"| node_accessibility
node_daemoncore -.->|"queries elements"| node_uiquery
node_daemoncore -.->|"may unlock"| node_unlock
node_user -->|"runs commands"| node_cli
node_user -->|"uses page"| node_browser
node_browser -->|"connects"| node_viewer
node_viewer -->|"checks login"| node_auth
node_viewer -->|"dispatches requests"| node_routes
node_routes -->|"requests daemon data"| node_protocol
node_routes -->|"serves HTTP MCP"| node_mcp
node_webui -.->|"uses viewer API"| node_routes
node_viewer -->|"serves streams"| node_video
node_daemoncore -->|"serves several devices"| node_phone
node_daemoncore -.->|"sends notifications"| node_alerts
node_daemoncore -.->|"supports checks"| node_diagnostics
node_supervision -->|"resigns WDA"| node_signing
node_supervision -->|"maintains session"| node_daemoncore
node_service -->|"starts daemon"| node_daemoncore
node_viewer -.->|"supports task handoff"| node_taskcontrol

click node_cli "https://github.com/derrors/iphone-control/blob/main/apps/iphone-control/src/main.rs"
click node_mcp "https://github.com/derrors/iphone-control/blob/main/crates/ictl-mcp/src/server.rs"
click node_protocol "https://github.com/derrors/iphone-control/blob/main/crates/ictl-protocol/src/client.rs"
click node_taskrun "https://github.com/derrors/iphone-control/blob/main/apps/iphone-control/src/agent.rs"
click node_daemoncore "https://github.com/derrors/iphone-control/blob/main/crates/ictl-daemon/src/core.rs"
click node_taskcontrol "https://github.com/derrors/iphone-control/blob/main/crates/ictl-daemon/src/tasks.rs"
click node_native "https://github.com/derrors/iphone-control/blob/main/crates/ictl-device/src/lib.rs"
click node_wda "https://github.com/derrors/iphone-control/blob/main/crates/ictl-wda/src/client.rs"
click node_accessibility "https://github.com/derrors/iphone-control/blob/main/crates/ictl-ax/src/session.rs"
click node_uiquery "https://github.com/derrors/iphone-control/blob/main/crates/ictl-ui/src/query.rs"
click node_unlock "https://github.com/derrors/iphone-control/blob/main/crates/ictl-unlock/src/durable.rs"
click node_viewer "https://github.com/derrors/iphone-control/blob/main/apps/iphone-control/src/viewer/server.rs"
click node_routes "https://github.com/derrors/iphone-control/blob/main/apps/iphone-control/src/viewer/routes.rs"
click node_auth "https://github.com/derrors/iphone-control/blob/main/apps/iphone-control/src/viewer/auth.rs"
click node_webui "https://github.com/derrors/iphone-control/blob/main/apps/iphone-control/web/js/tasks.js"
click node_video "https://github.com/derrors/iphone-control/blob/main/apps/iphone-control/src/video/mod.rs"
click node_signing "https://github.com/derrors/iphone-control/blob/main/crates/ictl-sign/src/lib.rs"
click node_supervision "https://github.com/derrors/iphone-control/blob/main/crates/ictl-daemon/src/supervise/session.rs"
click node_alerts "https://github.com/derrors/iphone-control/blob/main/crates/ictl-daemon/src/notify.rs"
click node_diagnostics "https://github.com/derrors/iphone-control/blob/main/crates/ictl-daemon/src/doctor.rs"
click node_service "https://github.com/derrors/iphone-control/blob/main/apps/iphone-control/src/service.rs"

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_mcp,node_protocol,node_taskrun,node_user,node_browser toneBlue
class node_daemoncore,node_taskcontrol toneAmber
class node_native,node_wda,node_accessibility,node_uiquery,node_unlock toneMint
class node_viewer,node_routes,node_auth,node_webui,node_video toneRose
class node_signing,node_supervision,node_alerts,node_diagnostics,node_service,node_agent,node_phone toneIndigo
```

## Components

### Agent access

- [CLI entry](https://github.com/derrors/iphone-control/blob/main/apps/iphone-control/src/main.rs): `apps/iphone-control/src/main.rs`
- [MCP server](https://github.com/derrors/iphone-control/blob/main/crates/ictl-mcp/src/server.rs): `crates/ictl-mcp/src/server.rs`
- [Daemon protocol](https://github.com/derrors/iphone-control/blob/main/crates/ictl-protocol/src/client.rs): `crates/ictl-protocol/src/client.rs`
- [Agent task runner](https://github.com/derrors/iphone-control/blob/main/apps/iphone-control/src/agent.rs): `apps/iphone-control/src/agent.rs`

### Device daemon

- [Daemon core](https://github.com/derrors/iphone-control/blob/main/crates/ictl-daemon/src/core.rs): `crates/ictl-daemon/src/core.rs`
- [Task control](https://github.com/derrors/iphone-control/blob/main/crates/ictl-daemon/src/tasks.rs): `crates/ictl-daemon/src/tasks.rs`

### Device control

- [Native device control](https://github.com/derrors/iphone-control/blob/main/crates/ictl-device/src/lib.rs): `crates/ictl-device/src/lib.rs`
- [WebDriverAgent client](https://github.com/derrors/iphone-control/blob/main/crates/ictl-wda/src/client.rs): `crates/ictl-wda/src/client.rs`
- [Accessibility tree](https://github.com/derrors/iphone-control/blob/main/crates/ictl-ax/src/session.rs): `crates/ictl-ax/src/session.rs`
- [UI queries](https://github.com/derrors/iphone-control/blob/main/crates/ictl-ui/src/query.rs): `crates/ictl-ui/src/query.rs`
- [Auto-unlock](https://github.com/derrors/iphone-control/blob/main/crates/ictl-unlock/src/durable.rs): `crates/ictl-unlock/src/durable.rs`

### Browser viewer

- [Viewer server](https://github.com/derrors/iphone-control/blob/main/apps/iphone-control/src/viewer/server.rs): `apps/iphone-control/src/viewer/server.rs`
- [Viewer routes](https://github.com/derrors/iphone-control/blob/main/apps/iphone-control/src/viewer/routes.rs): `apps/iphone-control/src/viewer/routes.rs`
- [Login and access](https://github.com/derrors/iphone-control/blob/main/apps/iphone-control/src/viewer/auth.rs): `apps/iphone-control/src/viewer/auth.rs`
- [Browser controls](https://github.com/derrors/iphone-control/blob/main/apps/iphone-control/web/js/tasks.js): `apps/iphone-control/web/js/tasks.js`
- [Live video](https://github.com/derrors/iphone-control/blob/main/apps/iphone-control/src/video/mod.rs): `apps/iphone-control/src/video/mod.rs`

### Operations

- [WDA signing](https://github.com/derrors/iphone-control/blob/main/crates/ictl-sign/src/lib.rs): `crates/ictl-sign/src/lib.rs`
- [WDA supervision](https://github.com/derrors/iphone-control/blob/main/crates/ictl-daemon/src/supervise/session.rs): `crates/ictl-daemon/src/supervise/session.rs`
- [Notifications](https://github.com/derrors/iphone-control/blob/main/crates/ictl-daemon/src/notify.rs): `crates/ictl-daemon/src/notify.rs`
- [Diagnostics](https://github.com/derrors/iphone-control/blob/main/crates/ictl-daemon/src/doctor.rs): `crates/ictl-daemon/src/doctor.rs`
- [Background service](https://github.com/derrors/iphone-control/blob/main/apps/iphone-control/src/service.rs): `apps/iphone-control/src/service.rs`

### Other components

- **AI agent**
- **User**
- **iPhone or iPad**
- **Browser user**

## Connections

- AI agent → MCP server: calls tools (evidence: `README.md`)
- MCP server → Daemon protocol: sends requests (evidence: `crates/ictl-mcp/src/server.rs`)
- CLI entry → Daemon protocol: uses client
- Agent task runner → MCP server: starts agent access
- MCP server → Daemon core: forwards actions (evidence: `README.md`)
- Daemon protocol → Daemon core: sends requests (evidence: `README.md`)
- Daemon core → Task control: checks admission (evidence: `crates/ictl-daemon/src/tasks.rs`)
- Daemon core → Native device control: uses native route (evidence: `README.md`)
- Daemon core → WebDriverAgent client: uses legacy route (evidence: `README.md`)
- Native device control → iPhone or iPad: controls device (evidence: `README.md`)
- WebDriverAgent client → iPhone or iPad: controls device (evidence: `README.md`)
- Daemon core → Accessibility tree: reads UI
- Daemon core → UI queries: queries elements
- Daemon core → Auto-unlock: may unlock
- User → CLI entry: runs commands (evidence: `apps/iphone-control/src/main.rs`)
- User → Browser user: uses page (evidence: `README.md`)
- Browser user → Viewer server: connects (evidence: `README.md`)
- Viewer server → Login and access: checks login (evidence: `apps/iphone-control/src/viewer/server.rs`)
- Viewer server → Viewer routes: dispatches requests (evidence: `apps/iphone-control/src/viewer/server.rs`)
- Viewer routes → Daemon protocol: requests daemon data (evidence: `apps/iphone-control/src/viewer/routes.rs`)
- Viewer routes → MCP server: serves HTTP MCP (evidence: `README.md`)
- Browser controls → Viewer routes: uses viewer API
- Viewer server → Live video: serves streams (evidence: `apps/iphone-control/src/viewer.rs`)
- Daemon core → iPhone or iPad: serves several devices (evidence: `README.md`)
- Daemon core → Notifications: sends notifications
- Daemon core → Diagnostics: supports checks
- WDA supervision → WDA signing: resigns WDA (evidence: `crates/ictl-daemon/src/supervise/session.rs`)
- WDA supervision → Daemon core: maintains session (evidence: `crates/ictl-daemon/src/supervise/session.rs`)
- Background service → Daemon core: starts daemon (evidence: `apps/iphone-control/src/service.rs`)
- Viewer server → Task control: supports task handoff
