# droidrun/mobilerun-portal architecture

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

- Interactive diagram: https://gitdiagram.com/droidrun/mobilerun-portal
- Repository: https://github.com/droidrun/mobilerun-portal

## Overview

Mobilerun Portal is an Android phone-control and UI-observation app. A user or remote operator connects through local HTTP/WebSocket/ADB interfaces or the cloud reverse connection; requests are dispatched to device capabilities and return structured state, events, or streamed media. Separate branches cover triggers, SMS, deep-link inspection, task prompting, and keep-awake recovery. The excerpts show key service wiring, but not every route or subsystem implementation, so some documented capability links are cited to the README rather than inferred from unsampled code.

Main entry points: [`app/src/main/java/com/mobilerun/portal/service/MobilerunAccessibilityService.kt`](https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/service/MobilerunAccessibilityService.kt) (Accessibility Service), [`app/src/main/java/com/mobilerun/portal/api/ApiHandler.kt`](https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/api/ApiHandler.kt) (API Handler), [`app/src/main/java/com/mobilerun/portal/service/ReverseConnectionService.kt`](https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/service/ReverseConnectionService.kt) (Reverse Connection), [`app/src/main/java/com/mobilerun/portal/ui/MainActivity.kt`](https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/ui/MainActivity.kt) (Portal UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Device Access"]
  node_accessibility["Accessibility Service"]
  node_state["State Repository<br/>[StateRepository.kt]"]
  node_overlay["Interactive Overlay<br/>[OverlayManager.kt]"]
  node_keyboard["Portal Keyboard"]
end

subgraph group_transport["Control Transports"]
  node_local["Local API<br/>[SocketServer.kt]"]
  node_provider["ADB Provider"]
  node_dispatcher["Action Dispatch"]
  node_api["API Handler<br/>[ApiHandler.kt]"]
end

subgraph group_cloud["Cloud and Streaming"]
  node_reverse["Reverse Connection"]
  node_auth["Device Sign-in"]
  node_capture["Screen Capture"]
  node_webrtc["WebRTC Streaming<br/>[WebRtcManager.kt]"]
end

subgraph group_automation["Automation Features"]
  node_events["Event Hub<br/>[EventHub.kt]"]
  node_triggers["Triggers<br/>[TriggerRuntime.kt]"]
  node_sms["SMS Bridge<br/>[SmsController.kt]"]
  node_deeplinks["Deep-link Inspector"]
  node_files["File Operations<br/>[FileOperations.kt]"]
end

subgraph group_app["App and Runtime"]
  node_task["Task Prompting"]
  node_ui["Portal UI<br/>[MainActivity.kt]"]
  node_config[("Configuration<br/>[ConfigManager.kt]")]
  node_keepalive["Keep Awake"]
end

node_operator(("Operator"))
node_cloudservice(("Mobilerun Cloud"))

node_operator -->|"sends requests"| node_local
node_operator -->|"issues ADB commands"| node_provider
node_local -.->|"routes requests"| node_api
node_provider -->|"exposes commands"| node_api
node_api -->|"dispatches actions"| node_dispatcher
node_dispatcher -.->|"invokes device actions"| node_accessibility
node_accessibility -->|"initializes handler"| node_api
node_api -->|"reads device state"| node_state
node_accessibility -->|"manages overlay"| node_overlay
node_accessibility -->|"initializes events"| node_events
node_accessibility -->|"initializes runtime"| node_triggers
node_operator -->|"controls remotely"| node_reverse
node_reverse -->|"opens WebSocket"| node_cloudservice
node_reverse -.->|"uses device sign-in"| node_auth
node_reverse -->|"handles signaling"| node_webrtc
node_capture -->|"starts capture"| node_webrtc
node_operator -->|"sends SMS requests"| node_sms
node_operator -->|"queries links"| node_deeplinks
node_operator -->|"requests file actions"| node_files
node_ui -.->|"submits tasks"| node_task
node_ui -.->|"updates settings"| node_config
node_config -->|"controls preference"| node_keepalive
node_ui -.->|"offers keyboard"| node_keyboard

click node_local "https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/service/SocketServer.kt"
click node_provider "https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/service/MobilerunContentProvider.kt"
click node_dispatcher "https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/service/ActionDispatcher.kt"
click node_api "https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/api/ApiHandler.kt"
click node_accessibility "https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/service/MobilerunAccessibilityService.kt"
click node_state "https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/core/StateRepository.kt"
click node_overlay "https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/ui/overlay/OverlayManager.kt"
click node_keyboard "https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/input/MobilerunKeyboardIME.kt"
click node_events "https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/events/EventHub.kt"
click node_triggers "https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/triggers/TriggerRuntime.kt"
click node_sms "https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/sms/SmsController.kt"
click node_deeplinks "https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/deeplinks/DeepLinkInspector.kt"
click node_files "https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/service/FileOperations.kt"
click node_reverse "https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/service/ReverseConnectionService.kt"
click node_auth "https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/auth/DeviceCodeAuthClient.kt"
click node_capture "https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/service/ScreenCaptureService.kt"
click node_webrtc "https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/streaming/WebRtcManager.kt"
click node_task "https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/taskprompt/PortalCloudClient.kt"
click node_ui "https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/ui/MainActivity.kt"
click node_config "https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/config/ConfigManager.kt"
click node_keepalive "https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/keepalive/KeepAliveController.kt"

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_accessibility,node_state,node_overlay,node_keyboard toneBlue
class node_local,node_provider,node_dispatcher,node_api toneAmber
class node_reverse,node_auth,node_capture,node_webrtc toneMint
class node_events,node_triggers,node_sms,node_deeplinks,node_files toneRose
class node_task,node_ui,node_config,node_keepalive,node_operator,node_cloudservice toneIndigo
```

## Components

### Device Access

- [Accessibility Service](https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/service/MobilerunAccessibilityService.kt): `app/src/main/java/com/mobilerun/portal/service/MobilerunAccessibilityService.kt`
- [State Repository](https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/core/StateRepository.kt): `app/src/main/java/com/mobilerun/portal/core/StateRepository.kt`
- [Interactive Overlay](https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/ui/overlay/OverlayManager.kt): `app/src/main/java/com/mobilerun/portal/ui/overlay/OverlayManager.kt`
- [Portal Keyboard](https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/input/MobilerunKeyboardIME.kt): `app/src/main/java/com/mobilerun/portal/input/MobilerunKeyboardIME.kt`

### Control Transports

- [Local API](https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/service/SocketServer.kt): `app/src/main/java/com/mobilerun/portal/service/SocketServer.kt`
- [ADB Provider](https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/service/MobilerunContentProvider.kt): `app/src/main/java/com/mobilerun/portal/service/MobilerunContentProvider.kt`
- [Action Dispatch](https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/service/ActionDispatcher.kt): `app/src/main/java/com/mobilerun/portal/service/ActionDispatcher.kt`
- [API Handler](https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/api/ApiHandler.kt): `app/src/main/java/com/mobilerun/portal/api/ApiHandler.kt`

### Cloud and Streaming

- [Reverse Connection](https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/service/ReverseConnectionService.kt): `app/src/main/java/com/mobilerun/portal/service/ReverseConnectionService.kt`
- [Device Sign-in](https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/auth/DeviceCodeAuthClient.kt): `app/src/main/java/com/mobilerun/portal/auth/DeviceCodeAuthClient.kt`
- [Screen Capture](https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/service/ScreenCaptureService.kt): `app/src/main/java/com/mobilerun/portal/service/ScreenCaptureService.kt`
- [WebRTC Streaming](https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/streaming/WebRtcManager.kt): `app/src/main/java/com/mobilerun/portal/streaming/WebRtcManager.kt`

### Automation Features

- [Event Hub](https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/events/EventHub.kt): `app/src/main/java/com/mobilerun/portal/events/EventHub.kt`
- [Triggers](https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/triggers/TriggerRuntime.kt): `app/src/main/java/com/mobilerun/portal/triggers/TriggerRuntime.kt`
- [SMS Bridge](https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/sms/SmsController.kt): `app/src/main/java/com/mobilerun/portal/sms/SmsController.kt`
- [Deep-link Inspector](https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/deeplinks/DeepLinkInspector.kt): `app/src/main/java/com/mobilerun/portal/deeplinks/DeepLinkInspector.kt`
- [File Operations](https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/service/FileOperations.kt): `app/src/main/java/com/mobilerun/portal/service/FileOperations.kt`

### App and Runtime

- [Task Prompting](https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/taskprompt/PortalCloudClient.kt): `app/src/main/java/com/mobilerun/portal/taskprompt/PortalCloudClient.kt`
- [Portal UI](https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/ui/MainActivity.kt): `app/src/main/java/com/mobilerun/portal/ui/MainActivity.kt`
- [Configuration](https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/config/ConfigManager.kt): `app/src/main/java/com/mobilerun/portal/config/ConfigManager.kt`
- [Keep Awake](https://github.com/droidrun/mobilerun-portal/blob/main/app/src/main/java/com/mobilerun/portal/keepalive/KeepAliveController.kt): `app/src/main/java/com/mobilerun/portal/keepalive/KeepAliveController.kt`

### Other components

- **Operator**
- **Mobilerun Cloud**

## Connections

- Operator → Local API: sends requests
- Operator → ADB Provider: issues ADB commands
- Local API → API Handler: routes requests (evidence: `app/src/main/java/com/mobilerun/portal/service/SocketServer.kt`)
- ADB Provider → API Handler: exposes commands
- API Handler → Action Dispatch: dispatches actions (evidence: `app/src/main/java/com/mobilerun/portal/service/PortalService.kt`)
- Action Dispatch → Accessibility Service: invokes device actions (evidence: `app/src/main/java/com/mobilerun/portal/service/MobilerunAccessibilityService.kt`)
- Accessibility Service → API Handler: initializes handler (evidence: `app/src/main/java/com/mobilerun/portal/service/MobilerunAccessibilityService.kt`)
- API Handler → State Repository: reads device state (evidence: `app/src/main/java/com/mobilerun/portal/api/ApiHandler.kt`)
- Accessibility Service → Interactive Overlay: manages overlay (evidence: `app/src/main/java/com/mobilerun/portal/service/MobilerunAccessibilityService.kt`)
- Accessibility Service → Event Hub: initializes events (evidence: `app/src/main/java/com/mobilerun/portal/service/MobilerunAccessibilityService.kt`)
- Accessibility Service → Triggers: initializes runtime (evidence: `app/src/main/java/com/mobilerun/portal/service/MobilerunAccessibilityService.kt`)
- Operator → Reverse Connection: controls remotely
- Reverse Connection → Mobilerun Cloud: opens WebSocket
- Reverse Connection → Device Sign-in: uses device sign-in (evidence: `app/src/main/java/com/mobilerun/portal/service/ReverseConnectionService.kt`)
- Reverse Connection → WebRTC Streaming: handles signaling (evidence: `app/src/main/java/com/mobilerun/portal/service/ReverseConnectionService.kt`)
- Screen Capture → WebRTC Streaming: starts capture (evidence: `app/src/main/java/com/mobilerun/portal/service/ScreenCaptureService.kt`)
- Operator → SMS Bridge: sends SMS requests
- Operator → Deep-link Inspector: queries links
- Operator → File Operations: requests file actions
- Portal UI → Task Prompting: submits tasks (evidence: `app/src/main/java/com/mobilerun/portal/ui/MainActivity.kt`)
- Portal UI → Configuration: updates settings (evidence: `app/src/main/java/com/mobilerun/portal/ui/MainActivity.kt`)
- Configuration → Keep Awake: controls preference (evidence: `app/src/main/java/com/mobilerun/portal/keepalive/KeepAliveController.kt`)
- Portal UI → Portal Keyboard: offers keyboard (evidence: `app/src/main/java/com/mobilerun/portal/ui/MainActivity.kt`)
