# onehumanbeing/esp32-iphone-agent architecture

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

- Interactive diagram: https://gitdiagram.com/onehumanbeing/esp32-iphone-agent
- Repository: https://github.com/onehumanbeing/esp32-iphone-agent

## Overview

ESP32 iPhone Agent lets a user automate a real iPhone through an AI planner/actor loop: the browser submits a goal, the server observes mirrored frames, asks vision-capable models for actions, and sends gestures through an ESP32 HID bridge. Separate manual controls and calibration support direct operation; live status, screenshots, logs, and optional traces expose runs. The README documents AirPlay/UxPlay, firmware behavior, and optional local models; unsampled firmware and some API routes are represented only at the documented subsystem level.

Main entry points: [`server/hidagent/agent.py`](https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/server/hidagent/agent.py) (Planner/actor loop), [`server/hidagent/phone.py`](https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/server/hidagent/phone.py) (Gestures/calibration), [`server/hidagent/app.py`](https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/server/hidagent/app.py) (Web API), [`server/hidagent/screen.py`](https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/server/hidagent/screen.py) (Screen capture)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Web control"]
  node_browser["Control UI<br/>[app.js]"]
  node_locale["Bilingual UI<br/>[i18n.js]"]
  node_api["Web API<br/>[app.py]"]
end

subgraph group_agent["Agent runtime"]
  node_agent["Planner/actor loop<br/>[agent.py]"]
  node_llm["Model client<br/>[llm.py]"]
  node_trace["Run traces<br/>[debug.py]"]
end

subgraph group_phoneio["Phone I/O"]
  node_screen["Screen capture<br/>[screen.py]"]
  node_vision["Frame analysis<br/>[vision.py]"]
  node_phone["Gestures/calibration<br/>[phone.py]"]
  node_device["HID TCP device<br/>[device.py]"]
  node_firmware["HID bridge firmware<br/>[hid_bridge.ino]"]
end

subgraph group_integrations["External integrations"]
  node_iphone(("iPhone"))
  node_uxplay["UxPlay receiver"]
  node_modelservice["Vision model API"]
  node_localmodel["Transformers model server"]
end

node_user(("User"))

node_user -->|"submits goal"| node_browser
node_browser -->|"sends controls"| node_api
node_api -->|"starts/stops runs"| node_agent
node_api -->|"routes manual actions"| node_phone
node_api -->|"serves frames"| node_screen
node_browser -->|"renders translations"| node_locale
node_agent -->|"reads frames"| node_screen
node_agent -->|"requests plans/actions"| node_llm
node_agent -->|"executes actions"| node_phone
node_agent -->|"checks screen changes"| node_vision
node_agent -->|"records run data"| node_trace
node_phone -->|"locates pointer"| node_vision
node_phone -->|"observes pointer"| node_screen
node_phone -->|"sends gestures"| node_device
node_device -->|"sends commands"| node_firmware
node_firmware -->|"emulates HID"| node_iphone
node_iphone -->|"mirrors screen"| node_uxplay
node_uxplay -->|"streams frames"| node_screen
node_llm -->|"calls compatible API"| node_modelservice
node_localmodel -.->|"serves completions"| node_modelservice

click node_browser "https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/server/hidagent/static/app.js"
click node_locale "https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/server/hidagent/static/i18n.js"
click node_api "https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/server/hidagent/app.py"
click node_agent "https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/server/hidagent/agent.py"
click node_llm "https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/server/hidagent/llm.py"
click node_trace "https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/server/hidagent/debug.py"
click node_screen "https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/server/hidagent/screen.py"
click node_vision "https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/server/hidagent/vision.py"
click node_phone "https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/server/hidagent/phone.py"
click node_device "https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/server/hidagent/device.py"
click node_firmware "https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/hardware/hid_bridge/hid_bridge.ino"
click node_localmodel "https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/server/serve/transformers_server.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_browser,node_locale,node_api,node_user toneBlue
class node_agent,node_llm,node_trace toneAmber
class node_screen,node_vision,node_phone,node_device,node_firmware toneMint
class node_iphone,node_uxplay,node_modelservice,node_localmodel toneRose
```

## Components

### Web control

- [Control UI](https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/server/hidagent/static/app.js): `server/hidagent/static/app.js`
- [Bilingual UI](https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/server/hidagent/static/i18n.js): `server/hidagent/static/i18n.js`
- [Web API](https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/server/hidagent/app.py): `server/hidagent/app.py`

### Agent runtime

- [Planner/actor loop](https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/server/hidagent/agent.py): `server/hidagent/agent.py`
- [Model client](https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/server/hidagent/llm.py): `server/hidagent/llm.py`
- [Run traces](https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/server/hidagent/debug.py): `server/hidagent/debug.py`

### Phone I/O

- [Screen capture](https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/server/hidagent/screen.py): `server/hidagent/screen.py`
- [Frame analysis](https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/server/hidagent/vision.py): `server/hidagent/vision.py`
- [Gestures/calibration](https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/server/hidagent/phone.py): `server/hidagent/phone.py`
- [HID TCP device](https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/server/hidagent/device.py): `server/hidagent/device.py`
- [HID bridge firmware](https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/hardware/hid_bridge/hid_bridge.ino): `hardware/hid_bridge/hid_bridge.ino`

### External integrations

- **iPhone**
- **UxPlay receiver**
- **Vision model API**
- [Transformers model server](https://github.com/onehumanbeing/esp32-iphone-agent/blob/main/server/serve/transformers_server.py): `server/serve/transformers_server.py`

### Other components

- **User**

## Connections

- User → Control UI: submits goal (evidence: `README.md`)
- Control UI → Web API: sends controls (evidence: `server/hidagent/static/app.js`)
- Web API → Planner/actor loop: starts/stops runs (evidence: `server/hidagent/app.py`)
- Web API → Gestures/calibration: routes manual actions (evidence: `server/hidagent/app.py`)
- Web API → Screen capture: serves frames (evidence: `server/hidagent/app.py`)
- Control UI → Bilingual UI: renders translations (evidence: `server/hidagent/static/app.js`)
- Planner/actor loop → Screen capture: reads frames (evidence: `server/hidagent/agent.py`)
- Planner/actor loop → Model client: requests plans/actions (evidence: `server/hidagent/agent.py`)
- Planner/actor loop → Gestures/calibration: executes actions (evidence: `server/hidagent/agent.py`)
- Planner/actor loop → Frame analysis: checks screen changes (evidence: `server/hidagent/agent.py`)
- Planner/actor loop → Run traces: records run data (evidence: `server/hidagent/agent.py`)
- Gestures/calibration → Frame analysis: locates pointer (evidence: `server/hidagent/phone.py`)
- Gestures/calibration → Screen capture: observes pointer (evidence: `server/hidagent/phone.py`)
- Gestures/calibration → HID TCP device: sends gestures (evidence: `server/hidagent/phone.py`)
- HID TCP device → HID bridge firmware: sends commands (evidence: `README.md`)
- HID bridge firmware → iPhone: emulates HID (evidence: `README.md`)
- iPhone → UxPlay receiver: mirrors screen (evidence: `README.md`)
- UxPlay receiver → Screen capture: streams frames (evidence: `server/hidagent/screen.py`)
- Model client → Vision model API: calls compatible API (evidence: `server/hidagent/llm.py`)
- Transformers model server → Vision model API: serves completions (evidence: `server/serve/transformers_server.py`)
