Docs / Architecture
How it fits together
MonkeyTester is the orchestrator. Phones, the vision model and other hardware each sit behind their own HTTP service, so every piece can live on the machine that suits it.
System diagram
Linux host (192.168.125.70) Mac (192.168.125.71)
┌──────────────────────────────────────────┐ ┌──────────────────────────────────────┐
│ MonkeyTester viewer app.py :8089 │ │ Mobile Controller plugin :8090 │
│ ├─ web UI, run results, Build & Test │ │ ├─ Appium :4723 ─► iPhone (XCUITest)│
│ ├─ /stream, /api/frame proxies ─────────┼──►│ ├─ xcrun devicectl ─► iPhone install│
│ └─ launches runs │ │ └─ adb + ffmpeg ─► Android phone │
│ │ │ │
│ runner run_on_device.py │ │ AI plugin :8091 (vision model) │
│ ├─ controller_client.py ────────────────┼──►│ ├─ Local: Qwen2.5-VL via Ollama │
│ ├─ vision_analyzer.py ──────────────────┼──►│ ├─ Remote OpenAI-compatible server │
│ └─ plugin_client.py ──► device plugins │ │ └─ GitHub Copilot │
│ │ │ │
│ DIFF plugin :8095 (loopback) │ │ │
│ Gitea :3000 (the lab's code host) │ │ build-local :8094 (build plugin) │
│ │ │ fetches Gitea/GitHub branches, │
│ │ │ builds on the Mac, uploads the apps │
└──────────────────────────────────────────┘ └──────────────────────────────────────┘
Design rules
- Everything is HTTP. The viewer has no adb, Appium, devicectl or capture code. The Mobile Controller's API is the only coupling to phones, and the controller knows nothing about tests or vision models.
- Device pixels everywhere. The vision model, input and screenshot dimensions all use device pixels, so press markers land exactly where the test pressed. (The controller converts to points for WebDriverAgent on iOS.)
- Standard library only. The viewer, runner, controller and AI service need no
pip install; device plugins bring their own dependencies. - Plugins own their hardware. Anything that isn't a phone is a device plugin implementing the Device Plugin API (health, devices, actions with parameter schemas, jobs). A new plugin needs no change to MonkeyTester.
- The AI plugin owns the model choice. The runner always posts to the plugin's
/v1/chat/completionswith the pairing token. The plugin decides whether its local model, a remote server or Copilot answers. - Every listener authenticates. After the security update the viewer requires a login, uploads carry a CI token, and every service requires a token whenever it listens beyond loopback. See Ports and authentication.
Ports and authentication
After the security update (full table, token setup and limits on Security):
| Service | Port | Listens on | Authentication |
|---|---|---|---|
| Viewer | 8089 | LAN | Login required (default admin account on first start — change its password; the admin creates further accounts in Settings → Users). Uploads and result polling from submit.py use the CI token instead, which grants nothing else. |
| Mobile Controller | 8090 | LAN | CONTROLLER_TOKEN, required |
| MonkeyTester-Plugin-AI | 8091 | LAN (--lan) | MTAI_TOKEN pairing token, required |
| build-local | 8094 | LAN | PLUGIN_TOKEN, required |
| Device plugins on the viewer's host | per plugin | Loopback by default | Optional on loopback; required on any other bind |
A service bound to a non-loopback address without a token refuses to start. The viewer keeps the tokens it sends to the other services in its Settings, not in its environment.
What happens during a run
- Submit. A build plugin (Build & Test) uploads the app (
.apk,.ipaor a.zipholding a.app) and the test files toPOST /api/run-test, with thebuild_requestof a build the viewer started. The viewer stages them inRun/.uploads/and startsrun_on_device.py. - Queue. Runs execute one after another in submission order, Android and iOS alike, because they may share device hardware. Each runner waits in phase
queuedfor the previous run, then takes a per-device lock underRun/.locks/. - Check dependencies. The runner asks the controller for its API version (must be 2) and each device's platform. On a plugin's first use it checks
GET /healthand cachesGET /actions. - Install and set up. The controller installs the app (
adb installordevicectl).INSTRUCTION.txtdecides whether setup runs once or before every test, and whether app data is cleared. - Execute steps. For
VERIFY/CLICK/INPUTthe runner grabs a screenshot from the controller, asks the vision model where the element is, then sends the tap or text. Each press is posted to/api/press-eventso the run page draws a marker.PLUGINsteps post a job and wait for it. - Record. Screen recordings are made on the controller and downloaded into the run's
outputs/. The viewer converts them to WebM (VP9 + Opus) with ffmpeg for the browser. - Verdict.
GET /api/runs/<run>/resultreturnsrunning,passed,failedorrecording; the build follows its run to a conclusion ofsuccess,failureorcancelled.
Live view
- Android: the run page shows
/stream/<id>, an MJPEG stream proxied from the controller (ffmpeg on the Mac). - iOS: there is no stream, so the page polls
/api/frame/<id>for fresh screenshots.
Contracts between services
| Client | Talks to | Version check |
|---|---|---|
| Viewer + runner | Mobile Controller API version 2 (API.md in that repo) | At the start of every run and in /api/status |
| Runner | Any OpenAI-style chat completions endpoint, normally MonkeyTester-Plugin-AI (API version 3) | In /api/status |
| Runner | Device plugins, PLUGIN_API.md contract_version 1 | On a run's first step for each plugin, and in /api/status |
| Viewer | Build plugins, BUILD_PLUGIN_API.md contract_version 1 | When saving a plugin's address in Settings, and for every build |
All three services report {ok, service, api_version} from an open GET /health (it reveals no configuration or secrets) and fail with {"error": {"code", "message"}}. GET /api/status on the viewer shows the state of every dependency in one call; use it after any setup change.
Repositories
| Repo | Contents | Key docs in the repo |
|---|---|---|
MonkeyTester | Viewer, runner, build/upload scripts, plugin clients | README.md, ARCHITECTURE.md, PLUGIN_API.md, BUILD_PLUGIN_API.md, SNAPSHOTS.md, AGENTS.md (full endpoint and test-format reference) |
MonkeyTester-Plugin-Mobile-Controller | device_controller.py, Android stream, LaunchAgent | README.md, API.md, ARCHITECTURE.md |
MonkeyTester-Plugin-AI | Vision gateway, Ollama installer, Copilot and remote providers | README.md, API.md, ARCHITECTURE.md |
MonkeyTester-Plugin-Build-Local | Build plugin: fetches Gitea/GitHub branches, builds, uploads (contract BUILD_PLUGIN_API.md, kept in the MonkeyTester repo) | README.md |