MONKEYTESTERDOCS
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/completions with 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):

ServicePortListens onAuthentication
Viewer8089LANLogin 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 Controller8090LANCONTROLLER_TOKEN, required
MonkeyTester-Plugin-AI8091LAN (--lan)MTAI_TOKEN pairing token, required
build-local8094LANPLUGIN_TOKEN, required
Device plugins on the viewer's hostper pluginLoopback by defaultOptional 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

  1. Submit. A build plugin (Build & Test) uploads the app (.apk, .ipa or a .zip holding a .app) and the test files to POST /api/run-test, with the build_request of a build the viewer started. The viewer stages them in Run/.uploads/ and starts run_on_device.py.
  2. Queue. Runs execute one after another in submission order, Android and iOS alike, because they may share device hardware. Each runner waits in phase queued for the previous run, then takes a per-device lock under Run/.locks/.
  3. 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 /health and caches GET /actions.
  4. Install and set up. The controller installs the app (adb install or devicectl). INSTRUCTION.txt decides whether setup runs once or before every test, and whether app data is cleared.
  5. Execute steps. For VERIFY/CLICK/INPUT the 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-event so the run page draws a marker. PLUGIN steps post a job and wait for it.
  6. 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.
  7. Verdict. GET /api/runs/<run>/result returns running, passed, failed or recording; the build follows its run to a conclusion of success, failure or cancelled.

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

ClientTalks toVersion check
Viewer + runnerMobile Controller API version 2 (API.md in that repo)At the start of every run and in /api/status
RunnerAny OpenAI-style chat completions endpoint, normally MonkeyTester-Plugin-AI (API version 3)In /api/status
RunnerDevice plugins, PLUGIN_API.md contract_version 1On a run's first step for each plugin, and in /api/status
ViewerBuild plugins, BUILD_PLUGIN_API.md contract_version 1When 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

RepoContentsKey docs in the repo
MonkeyTesterViewer, runner, build/upload scripts, plugin clientsREADME.md, ARCHITECTURE.md, PLUGIN_API.md, BUILD_PLUGIN_API.md, SNAPSHOTS.md, AGENTS.md (full endpoint and test-format reference)
MonkeyTester-Plugin-Mobile-Controllerdevice_controller.py, Android stream, LaunchAgentREADME.md, API.md, ARCHITECTURE.md
MonkeyTester-Plugin-AIVision gateway, Ollama installer, Copilot and remote providersREADME.md, API.md, ARCHITECTURE.md
MonkeyTester-Plugin-Build-LocalBuild plugin: fetches Gitea/GitHub branches, builds, uploads (contract BUILD_PLUGIN_API.md, kept in the MonkeyTester repo)README.md