# must-canary/ai-visual-mobile-app-testing architecture

> Architecture diagram of the GitHub repository must-canary/ai-visual-mobile-app-testing, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/must-canary/ai-visual-mobile-app-testing
- Repository: https://github.com/must-canary/ai-visual-mobile-app-testing

## Overview

Visual Mobile Automation Testing is a browser playground for uploading Android APKs, managing emulator sessions, authoring plain-English steps, and observing automation runs. Its main workflow parses a script, executes each step against an Appium session, resolves described screen elements through local history or vision, and streams run events back to the UI. The graph also preserves APK/app management, saved tests, screenshots, and cache controls. Some subsystem links are documented in the README or the SOURCE INDEX; unsampled internals are not expanded beyond those supported relationships.

Main entry points: [`components/playground/context.tsx`](https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/components/playground/context.tsx) (Playground), [`lib/engine/step-executor.ts`](https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/lib/engine/step-executor.ts) (Step executor), [`lib/appium/session-manager.ts`](https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/lib/appium/session-manager.ts) (Appium sessions), [`app/api/apps/route.ts`](https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/app/api/apps/route.ts) (APK app API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_playground["Playground UI"]
  node_playground["Playground<br/>[context.tsx]"]
  node_editor["Script editor<br/>[ScriptEditor.tsx]"]
  node_sessionui["Session controls<br/>[SessionBar.tsx]"]
  node_cacheui["Local-first control"]
  node_runstream["Run event hook<br/>[useRunEvents.ts]"]
end

subgraph group_api["HTTP API"]
  node_appapi["APK app API<br/>[route.ts]"]
  node_sessionapi["Session API<br/>[route.ts]"]
  node_runapi["Run API<br/>[route.ts]"]
  node_eventapi["Run event API<br/>[route.ts]"]
  node_cacheapi["Cache API<br/>[route.ts]"]
end

subgraph group_automation["Automation runtime"]
  node_upload["APK upload<br/>[upload.ts]"]
  node_badging["APK metadata<br/>[badging.ts]"]
  node_parser["Script parser<br/>[parser.ts]"]
  node_controller["Run controller<br/>[run-controller.ts]"]
  node_executor["Step executor<br/>[step-executor.ts]"]
  node_vision["Vision locate<br/>[locate.ts]"]
  node_locatecache[("Locate history<br/>[locate-cache.ts]")]
  node_eventbus["Run event bus<br/>[events.ts]"]
  node_screenshots["Screenshot store"]
end

subgraph group_device["Android device"]
  node_sessionmanager["Appium sessions<br/>[session-manager.ts]"]
  node_android["Android SDK<br/>[sdk.ts]"]
end

subgraph group_data["Persistence"]
  node_mongodb[("MongoDB collections<br/>[mongodb.ts]")]
end

node_user(("Test author"))
node_visionservice{{"Vision provider"}}
node_appium{{"Appium emulator"}}

node_user -->|"authors tests"| node_playground
node_playground -->|"manages APKs"| node_appapi
node_appapi -->|"streams upload"| node_upload
node_appapi -->|"reads metadata"| node_badging
node_appapi -->|"stores app"| node_mongodb
node_playground -->|"manages sessions"| node_sessionapi
node_sessionapi -->|"starts session"| node_sessionmanager
node_sessionmanager -->|"lists devices"| node_android
node_sessionmanager -->|"creates driver"| node_appium
node_playground -->|"edits steps"| node_editor
node_playground -->|"submits run"| node_runapi
node_runapi -->|"parses script"| node_parser
node_runapi -->|"gets session"| node_sessionmanager
node_runapi -->|"starts run"| node_controller
node_controller -->|"persists run"| node_mongodb
node_controller -->|"executes steps"| node_executor
node_controller -->|"publishes events"| node_eventbus
node_executor -->|"locates targets"| node_vision
node_vision -->|"requests vision"| node_visionservice
node_executor -->|"reuses history"| node_locatecache
node_executor -->|"drives session"| node_sessionmanager
node_executor -->|"stores captures"| node_screenshots
node_executor -->|"reports stages"| node_eventbus
node_playground -->|"controls reuse"| node_cacheui
node_cacheui -->|"reads cache stats"| node_cacheapi
node_cacheapi -->|"manages cache"| node_locatecache
node_playground -->|"subscribes events"| node_runstream
node_runstream -->|"opens event stream"| node_eventapi
node_eventapi -->|"streams events"| node_eventbus
node_eventapi -->|"loads run events"| node_mongodb
node_sessionmanager -.->|"closes session"| node_appium
node_mongodb -.->|"backs cache records"| node_locatecache

click node_playground "https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/components/playground/context.tsx"
click node_editor "https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/components/playground/ScriptEditor.tsx"
click node_sessionui "https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/components/playground/SessionBar.tsx"
click node_cacheui "https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/components/playground/LocalFirstControl.tsx"
click node_runstream "https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/hooks/useRunEvents.ts"
click node_appapi "https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/app/api/apps/route.ts"
click node_sessionapi "https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/app/api/sessions/route.ts"
click node_runapi "https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/app/api/runs/route.ts"
click node_eventapi "https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/app/api/runs/%5Bid%5D/events/route.ts"
click node_cacheapi "https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/app/api/cache/route.ts"
click node_upload "https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/lib/apk/upload.ts"
click node_badging "https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/lib/apk/badging.ts"
click node_parser "https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/lib/dsl/parser.ts"
click node_controller "https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/lib/engine/run-controller.ts"
click node_executor "https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/lib/engine/step-executor.ts"
click node_vision "https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/lib/vision/locate.ts"
click node_locatecache "https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/lib/engine/locate-cache.ts"
click node_eventbus "https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/lib/engine/events.ts"
click node_sessionmanager "https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/lib/appium/session-manager.ts"
click node_android "https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/lib/android/sdk.ts"
click node_mongodb "https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/lib/mongodb.ts"
click node_screenshots "https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/lib/engine/screenshot-store.ts"

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_playground,node_editor,node_sessionui,node_cacheui,node_runstream toneBlue
class node_appapi,node_sessionapi,node_runapi,node_eventapi,node_cacheapi toneAmber
class node_upload,node_badging,node_parser,node_controller,node_executor,node_vision,node_locatecache,node_eventbus,node_screenshots toneMint
class node_sessionmanager,node_android toneRose
class node_mongodb,node_user,node_visionservice,node_appium toneIndigo
```

## Components

### Playground UI

- [Playground](https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/components/playground/context.tsx): `components/playground/context.tsx`
- [Script editor](https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/components/playground/ScriptEditor.tsx): `components/playground/ScriptEditor.tsx`
- [Session controls](https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/components/playground/SessionBar.tsx): `components/playground/SessionBar.tsx`
- [Local-first control](https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/components/playground/LocalFirstControl.tsx): `components/playground/LocalFirstControl.tsx`
- [Run event hook](https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/hooks/useRunEvents.ts): `hooks/useRunEvents.ts`

### HTTP API

- [APK app API](https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/app/api/apps/route.ts): `app/api/apps/route.ts`
- [Session API](https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/app/api/sessions/route.ts): `app/api/sessions/route.ts`
- [Run API](https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/app/api/runs/route.ts): `app/api/runs/route.ts`
- [Run event API](https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/app/api/runs/%5Bid%5D/events/route.ts): `app/api/runs/[id]/events/route.ts`
- [Cache API](https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/app/api/cache/route.ts): `app/api/cache/route.ts`

### Automation runtime

- [APK upload](https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/lib/apk/upload.ts): `lib/apk/upload.ts`
- [APK metadata](https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/lib/apk/badging.ts): `lib/apk/badging.ts`
- [Script parser](https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/lib/dsl/parser.ts): `lib/dsl/parser.ts`
- [Run controller](https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/lib/engine/run-controller.ts): `lib/engine/run-controller.ts`
- [Step executor](https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/lib/engine/step-executor.ts): `lib/engine/step-executor.ts`
- [Vision locate](https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/lib/vision/locate.ts): `lib/vision/locate.ts`
- [Locate history](https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/lib/engine/locate-cache.ts): `lib/engine/locate-cache.ts`
- [Run event bus](https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/lib/engine/events.ts): `lib/engine/events.ts`
- [Screenshot store](https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/lib/engine/screenshot-store.ts): `lib/engine/screenshot-store.ts`

### Android device

- [Appium sessions](https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/lib/appium/session-manager.ts): `lib/appium/session-manager.ts`
- [Android SDK](https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/lib/android/sdk.ts): `lib/android/sdk.ts`

### Persistence

- [MongoDB collections](https://github.com/must-canary/ai-visual-mobile-app-testing/blob/main/lib/mongodb.ts): `lib/mongodb.ts`

### Other components

- **Test author**
- **Vision provider**
- **Appium emulator**

## Connections

- Test author → Playground: authors tests (evidence: `README.md`)
- Playground → APK app API: manages APKs (evidence: `components/playground/context.tsx`)
- APK app API → APK upload: streams upload (evidence: `app/api/apps/route.ts`)
- APK app API → APK metadata: reads metadata (evidence: `app/api/apps/route.ts`)
- APK app API → MongoDB collections: stores app (evidence: `app/api/apps/route.ts`)
- Playground → Session API: manages sessions (evidence: `components/playground/context.tsx`)
- Session API → Appium sessions: starts session (evidence: `app/api/sessions/route.ts`)
- Appium sessions → Android SDK: lists devices (evidence: `lib/appium/session-manager.ts`)
- Appium sessions → Appium emulator: creates driver (evidence: `lib/appium/session-manager.ts`)
- Playground → Script editor: edits steps (evidence: `README.md`)
- Playground → Run API: submits run (evidence: `README.md`)
- Run API → Script parser: parses script (evidence: `app/api/runs/route.ts`)
- Run API → Appium sessions: gets session (evidence: `app/api/runs/route.ts`)
- Run API → Run controller: starts run (evidence: `app/api/runs/route.ts`)
- Run controller → MongoDB collections: persists run (evidence: `lib/engine/run-controller.ts`)
- Run controller → Step executor: executes steps (evidence: `lib/engine/run-controller.ts`)
- Run controller → Run event bus: publishes events (evidence: `lib/engine/run-controller.ts`)
- Step executor → Vision locate: locates targets (evidence: `lib/engine/step-executor.ts`)
- Vision locate → Vision provider: requests vision (evidence: `README.md`)
- Step executor → Locate history: reuses history (evidence: `lib/engine/step-executor.ts`)
- Step executor → Appium sessions: drives session (evidence: `lib/engine/step-executor.ts`)
- Step executor → Screenshot store: stores captures (evidence: `lib/engine/step-executor.ts`)
- Step executor → Run event bus: reports stages (evidence: `lib/engine/step-executor.ts`)
- Playground → Local-first control: controls reuse (evidence: `components/playground/context.tsx`)
- Local-first control → Cache API: reads cache stats
- Cache API → Locate history: manages cache (evidence: `app/api/cache/route.ts`)
- Playground → Run event hook: subscribes events (evidence: `components/playground/context.tsx`)
- Run event hook → Run event API: opens event stream (evidence: `hooks/useRunEvents.ts`)
- Run event API → Run event bus: streams events (evidence: `app/api/runs/[id]/events/route.ts`)
- Run event API → MongoDB collections: loads run events (evidence: `app/api/runs/[id]/events/route.ts`)
- Appium sessions → Appium emulator: closes session
- MongoDB collections → Locate history: backs cache records
