# raulvidis/hermes-android architecture

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

- Interactive diagram: https://gitdiagram.com/raulvidis/hermes-android
- Repository: https://github.com/raulvidis/hermes-android

## Overview

1. **High-level topology**
   - The repo implements a two-sided Android remote-control system:
     - an **Android bridge app** on the phone
     - a **Python toolset/relay layer** on the Hermes server side
   - The phone does **not** accept inbound connections; it connects outward to the server over a **WebSocket**. The server exposes an **HTTP** interface used by the AI agent/tooling.

2. **Primary control flow**
   - The main data path is: **AI agent → server tools → relay → phone bridge → Android Accessibility APIs**.
   - The phone returns device state back through the same path, including accessibility tree data, screenshots, foreground app info, and event/notification state.

3. **Android bridge app boundary**
   - `hermes-android-bridge/` is the runtime that lives on the device.
   - It is a Kotlin/Android app built around:
     - `BridgeAccessibilityService` for UI inspection and UI actions
     - `BridgeNotificationListener` for notification capture
     - `BridgeServer` / `BridgeRouter` for local HTTP development or bridge endpoints
     - `RelayClient` for outbound connection to the Hermes server

4. **Interaction execution layer on Android**
   - `ActionExecutor`, `ScreenReader`, and `ScreenNode` form the UI automation core.
   - This layer translates remote commands into Android accessibility interactions such as tap, type, swipe, scroll, back/home/recent keys, and reading the current screen tree.
   - The architecture is intentionally accessibility-driven rather than UI-scraping driven.

5. **Device state capture on Android**
   - `ScreenRecorder` handles screenshot capture.
   - `EventStore` and `NotificationStore` track recent device events and notifications for retrieval by the agent.
   - These stores suggest the bridge is stateful on-device, not purely stateless RPC.

6. **Session setup and trust**
   - `PairingManager` handles pairing-code-based authentication.
   - The pairing code is the trust bootstrap for linking a phone to a Hermes server; once paired, the server address is entered into the app and the device keeps an outbound relay connection.
   - This is a security boundary: the app grants broad device-control capability only after pairing.

7. **Lifecycle, visibility, and power management**
   - `BridgeApplication` and `MainActivity` provide the Android app shell and setup UI.
   - `StatusOverlay` gives a persistent on-device status indicator.
   - `WakeLockManager` keeps the bridge alive during active control sessions.
   - The presence of these pieces indicates the app is meant to behave like a service, not just a foreground UI.

8. **Server-side Python tool layer**
   - `hermes-android-plugin/`, `tools/`, and `tests/` contain the Python side.
   - This layer publishes the `android_*` tools consumed by **hermes-agent**; the README notes the production copy lives in the hermes-agent repo, while this repo is for development/testing.
   - The plugin packaging (`plugin.yaml`, `skill.md`, `skills/android/SKILL.md`) is what makes the tools installable into Hermes.

9. **Relay and transport responsibility on the server**
   - The server-side relay is responsible for connecting agent tool calls to the Android bridge over the network.
   - The README indicates a WebSocket + HTTP relay on port `8766`, with pairing/authentication and rate limiting.
   - The `contrib/` directory includes a daemon/service wrapper (`hermes-relay-daemon.py`, `hermes-android-relay.service`) for persistent relay operation.

10. **Repository packaging and deployment model**
   - The repo is split into two deployable units:
     - an **Android Gradle project** under `hermes-android-bridge/`
     - a **Python package/plugin** at the root and under `hermes-android-plugin/`
   - This separation reflects the real boundary in the system: device runtime vs. server integration.

11. **Testing and validation**
   - `tests/` covers the Python relay/tool behavior.
   - Android behavior is built/tested through the Gradle project.
   - The tests are centered on the server-side control plane, which is the part most likely to be reused inside hermes-agent.

12. **External dependency boundary**
   - The bridge app depends on Android platform services: AccessibilityService, notification access, and screenshot capture APIs.
   - The system also depends on the Hermes server/agent ecosystem; this repo is not a standalone phone-control product by itself.

13. **What to show in an architecture diagram**
   - Draw three main boxes:
     - **Android phone runtime**: accessibility service, relay client, screenshot/event/notification capture
     - **Hermes server**: relay + `android_*` tools/plugin
     - **Hermes agent**: invokes tools and receives device state
   - Connect them with an **outbound WebSocket from phone to server** and an **HTTP/tool invocation path from agent to server**.
   - Mark the Android AccessibilityService boundary as the point where remote commands become real device actions.

Main entry points: [`hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/service/BridgeAccessibilityService.kt`](https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/service/BridgeAccessibilityService.kt) (Accessibility), [`hermes-android-plugin/android_tool.py`](https://github.com/raulvidis/hermes-android/blob/main/hermes-android-plugin/android_tool.py) (Android tools), [`hermes-android-plugin/android_relay.py`](https://github.com/raulvidis/hermes-android/blob/main/hermes-android-plugin/android_relay.py) (Android relay), [`hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/BridgeApplication.kt`](https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/BridgeApplication.kt) (Bridge app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_android_bridge["Android bridge"]
  node_bridge_app["Bridge app<br/>android app"]
  node_main_activity["Main screen<br/>android activity<br/>[MainActivity.kt]"]
  node_pairing_manager{{"Pairing<br/>auth<br/>[PairingManager.kt]"}}
  node_relay_client["Relay client<br/>ws client<br/>[RelayClient.kt]"]
  node_accessibility_service["Accessibility<br/>android service"]
  node_notification_listener["Notifications<br/>android service"]
  node_action_executor["Action exec<br/>ui automation<br/>[ActionExecutor.kt]"]
  node_screen_reader["Screen reader<br/>ui inspection<br/>[ScreenReader.kt]"]
  node_screen_node["Screen node<br/>ui model<br/>[ScreenNode.kt]"]
  node_screen_recorder["Screenshots<br/>capture<br/>[ScreenRecorder.kt]"]
  node_event_store[("Event store<br/>state store<br/>[EventStore.kt]")]
  node_notification_store[("Notification store<br/>state store")]
  node_status_overlay["Status overlay<br/>[StatusOverlay.kt]"]
  node_wake_lock_manager["Wake lock<br/>power<br/>[WakeLockManager.kt]"]
  node_bridge_server["Bridge server<br/>http server<br/>[BridgeServer.kt]"]
  node_bridge_router["Router<br/>http routing<br/>[BridgeRouter.kt]"]
end

subgraph group_server_tools["Server tools"]
  node_android_tool["Android tools<br/>python tools<br/>[android_tool.py]"]
  node_android_relay["Android relay<br/>python relay<br/>[android_relay.py]"]
  node_plugin_yaml["Plugin spec<br/>plugin manifest<br/>[plugin.yaml]"]
  node_skill_md["Skill docs<br/>skill spec<br/>[skill.md]"]
  node_android_skill_md["Android skill<br/>skill spec<br/>[SKILL.md]"]
end

subgraph group_deployment["Packaging"]
  node_daemon["Relay daemon<br/>service wrapper"]
  node_systemd_unit["Systemd unit<br/>service config"]
end

node_main_activity -->|"starts pairing"| node_pairing_manager
node_pairing_manager -->|"enables"| node_relay_client
node_relay_client -->|"connects"| node_android_relay
node_android_relay -->|"serves tools"| node_android_tool
node_android_tool -->|"invokes actions"| node_accessibility_service
node_accessibility_service -->|"delegates"| node_action_executor
node_action_executor -->|"reads state"| node_screen_reader
node_screen_reader -->|"produces"| node_screen_node
node_accessibility_service -->|"captures"| node_screen_recorder
node_accessibility_service -->|"records"| node_event_store
node_notification_listener -->|"records"| node_notification_store
node_accessibility_service -->|"listens with"| node_notification_listener
node_bridge_app -->|"hosts"| node_bridge_server
node_bridge_server -->|"routes"| node_bridge_router
node_bridge_app -->|"shows"| node_status_overlay
node_bridge_app -->|"keeps alive"| node_wake_lock_manager
node_android_relay -.->|"deploys as"| node_daemon
node_daemon -->|"configured by"| node_systemd_unit
node_plugin_yaml -->|"packages"| node_android_tool
node_skill_md -->|"documents"| node_android_tool
node_android_skill_md -->|"specializes"| node_android_tool
node_android_relay -->|"bridges"| node_relay_client
node_accessibility_service -->|"inspects"| node_screen_reader

click node_bridge_app "https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/BridgeApplication.kt"
click node_main_activity "https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/MainActivity.kt"
click node_pairing_manager "https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/auth/PairingManager.kt"
click node_relay_client "https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/client/RelayClient.kt"
click node_accessibility_service "https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/service/BridgeAccessibilityService.kt"
click node_notification_listener "https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/service/BridgeNotificationListener.kt"
click node_action_executor "https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/executor/ActionExecutor.kt"
click node_screen_reader "https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/executor/ScreenReader.kt"
click node_screen_node "https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/model/ScreenNode.kt"
click node_screen_recorder "https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/media/ScreenRecorder.kt"
click node_event_store "https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/event/EventStore.kt"
click node_notification_store "https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/notification/NotificationStore.kt"
click node_status_overlay "https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/overlay/StatusOverlay.kt"
click node_wake_lock_manager "https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/power/WakeLockManager.kt"
click node_bridge_server "https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/server/BridgeServer.kt"
click node_bridge_router "https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/server/BridgeRouter.kt"
click node_android_tool "https://github.com/raulvidis/hermes-android/blob/main/hermes-android-plugin/android_tool.py"
click node_android_relay "https://github.com/raulvidis/hermes-android/blob/main/hermes-android-plugin/android_relay.py"
click node_plugin_yaml "https://github.com/raulvidis/hermes-android/blob/main/hermes-android-plugin/plugin.yaml"
click node_skill_md "https://github.com/raulvidis/hermes-android/blob/main/hermes-android-plugin/skill.md"
click node_android_skill_md "https://github.com/raulvidis/hermes-android/blob/main/skills/android/SKILL.md"
click node_daemon "https://github.com/raulvidis/hermes-android/blob/main/contrib/hermes-relay-daemon.py"
click node_systemd_unit "https://github.com/raulvidis/hermes-android/blob/main/contrib/hermes-android-relay.service"

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_bridge_app,node_main_activity,node_pairing_manager,node_relay_client,node_accessibility_service,node_notification_listener,node_action_executor,node_screen_reader,node_screen_node,node_screen_recorder,node_event_store,node_notification_store,node_status_overlay,node_wake_lock_manager,node_bridge_server,node_bridge_router toneBlue
class node_android_tool,node_android_relay,node_plugin_yaml,node_skill_md,node_android_skill_md toneAmber
class node_daemon,node_systemd_unit toneMint
```

## Components

### Android bridge

Device-side Kotlin app that runs on the phone and executes accessibility-driven control.

- [Bridge app](https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/BridgeApplication.kt): android app · Android runtime shell and setup UI. · `hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/BridgeApplication.kt`
- [Main screen](https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/MainActivity.kt): android activity · User-facing setup and configuration entrypoint. · `hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/MainActivity.kt`
- [Pairing](https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/auth/PairingManager.kt): auth · Bootstraps trust with pairing-code authentication. · `hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/auth/PairingManager.kt`
- [Relay client](https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/client/RelayClient.kt): ws client · Outbound connection from phone to Hermes server. · `hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/client/RelayClient.kt`
- [Accessibility](https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/service/BridgeAccessibilityService.kt): android service · Receives remote UI commands and inspects the screen tree. · `hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/service/BridgeAccessibilityService.kt`
- [Notifications](https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/service/BridgeNotificationListener.kt): android service · Captures device notifications for remote retrieval. · `hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/service/BridgeNotificationListener.kt`
- [Action exec](https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/executor/ActionExecutor.kt): ui automation · Translates remote commands into taps, typing, scrolling, and key actions. · `hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/executor/ActionExecutor.kt`
- [Screen reader](https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/executor/ScreenReader.kt): ui inspection · Builds readable state from the current accessibility tree. · `hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/executor/ScreenReader.kt`
- [Screen node](https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/model/ScreenNode.kt): ui model · Structured representation of accessibility tree elements. · `hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/model/ScreenNode.kt`
- [Screenshots](https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/media/ScreenRecorder.kt): capture · Captures device screenshots for the agent. · `hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/media/ScreenRecorder.kt`
- [Event store](https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/event/EventStore.kt): state store · Keeps recent device events on-device. · `hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/event/EventStore.kt`
- [Notification store](https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/notification/NotificationStore.kt): state store · Keeps recent notifications on-device. · `hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/notification/NotificationStore.kt`
- [Status overlay](https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/overlay/StatusOverlay.kt): overlay · Persistent on-device status indicator. · `hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/overlay/StatusOverlay.kt`
- [Wake lock](https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/power/WakeLockManager.kt): power · Keeps the bridge alive during active sessions. · `hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/power/WakeLockManager.kt`
- [Bridge server](https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/server/BridgeServer.kt): http server · Local HTTP bridge endpoint and development server. · `hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/server/BridgeServer.kt`
- [Router](https://github.com/raulvidis/hermes-android/blob/main/hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/server/BridgeRouter.kt): http routing · Routes bridge requests to device capabilities. · `hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/server/BridgeRouter.kt`

### Server tools

Python relay and plugin layer that exposes Android control tools to the Hermes ecosystem.

- [Android tools](https://github.com/raulvidis/hermes-android/blob/main/hermes-android-plugin/android_tool.py): python tools · Public android_* tool surface used by the Hermes agent. · `hermes-android-plugin/android_tool.py`
- [Android relay](https://github.com/raulvidis/hermes-android/blob/main/hermes-android-plugin/android_relay.py): python relay · Server-side relay between tool calls and the phone bridge. · `hermes-android-plugin/android_relay.py`
- [Plugin spec](https://github.com/raulvidis/hermes-android/blob/main/hermes-android-plugin/plugin.yaml): plugin manifest · Packaged plugin metadata for Hermes installation. · `hermes-android-plugin/plugin.yaml`
- [Skill docs](https://github.com/raulvidis/hermes-android/blob/main/hermes-android-plugin/skill.md): skill spec · Tool usage and skill packaging metadata. · `hermes-android-plugin/skill.md`
- [Android skill](https://github.com/raulvidis/hermes-android/blob/main/skills/android/SKILL.md): skill spec · Android-specific skill definition. · `skills/android/SKILL.md`

### Packaging

Repo-level packaging, install, and daemonization assets.

- [Relay daemon](https://github.com/raulvidis/hermes-android/blob/main/contrib/hermes-relay-daemon.py): service wrapper · Persistent relay process for server deployment. · `contrib/hermes-relay-daemon.py`
- [Systemd unit](https://github.com/raulvidis/hermes-android/blob/main/contrib/hermes-android-relay.service): service config · Service definition for running the relay as a daemon. · `contrib/hermes-android-relay.service`

## Connections

- Main screen → Pairing: starts pairing · The setup UI initiates trust bootstrap.
- Pairing → Relay client: enables · Paired devices open the outbound relay connection.
- Relay client → Android relay: connects · Phone sends state and receives commands through the server relay.
- Android relay → Android tools: serves tools · Relay backs the android_* tool interface exposed to the agent.
- Android tools → Accessibility: invokes actions · Tool calls become device-control commands.
- Accessibility → Action exec: delegates · Accessibility service hands remote intents to the automation core.
- Action exec → Screen reader: reads state · Action layer requests current screen structure before or after actions.
- Screen reader → Screen node: produces · Readable accessibility output is normalized into screen nodes.
- Accessibility → Screenshots: captures · Device screenshots are collected for remote consumption.
- Accessibility → Event store: records · Recent device events are persisted locally.
- Notifications → Notification store: records · Notifications are stored for later retrieval.
- Accessibility → Notifications: listens with · Notification access is part of the bridge runtime.
- Bridge app → Bridge server: hosts · The Android app includes a local HTTP bridge surface.
- Bridge server → Router: routes · Requests are dispatched to bridge capabilities.
- Bridge app → Status overlay: shows · Persistent overlay communicates bridge status.
- Bridge app → Wake lock: keeps alive · Power management supports long-running sessions.
- Android relay → Relay daemon: deploys as · Relay can run as a persistent service wrapper.
- Relay daemon → Systemd unit: configured by · System service file supports deployment.
- Plugin spec → Android tools: packages · Plugin metadata exposes the tool surface to Hermes.
- Skill docs → Android tools: documents · Skill docs describe the tool behavior.
- Android skill → Android tools: specializes · Android-specific skill content narrows the toolset.
- Android relay → Relay client: bridges · Server relay connects tool invocation to the phone's outbound channel.
- Accessibility → Screen reader: inspects · Accessibility boundary is where remote intent becomes UI state access.
