# lmoq/u2state architecture

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

- Interactive diagram: https://gitdiagram.com/lmoq/u2state
- Repository: https://github.com/lmoq/u2state

## Overview

U2 is a Python Android UI automation framework. Its main workflow models work as task metadata and UI states: states find UI elements, perform actions, and verify results while a handler controls transitions. Device-session helpers expose the connected device and package context; separate modules provide ADB input, shell-pipe support, notifications, logging, and time utilities. The README is empty, so capabilities are inferred from the source tree and excerpts; relationships not shown there are omitted.

Main entry points: [`U2/states/states.py`](https://github.com/lmoq/u2state/blob/main/U2/states/states.py) (UI states), [`U2/adb_tools/adb.py`](https://github.com/lmoq/u2state/blob/main/U2/adb_tools/adb.py) (ADB input), [`U2/states/state.py`](https://github.com/lmoq/u2state/blob/main/U2/states/state.py) (State handler), [`U2/process/pipes.py`](https://github.com/lmoq/u2state/blob/main/U2/process/pipes.py) (ADB shell pipes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_tasks["Task orchestration"]
  node_task_info["Task metadata<br/>[task.py]"]
  node_handler["State handler<br/>[state.py]"]
  node_ui_states["UI states<br/>[states.py]"]
  node_state_functions["State actions<br/>[functions.py]"]
  node_enums["Action enums<br/>[enums.py]"]
end

subgraph group_device["Android device access"]
  node_device_session["Device session<br/>[base.py]"]
  node_adb_actions["ADB input<br/>[adb.py]"]
  node_pipes["ADB shell pipes<br/>[pipes.py]"]
  node_process_system["System detection<br/>[system.py]"]
end

subgraph group_support["Runtime support"]
  node_shell_notif["Shell notifications<br/>[shell_notif.py]"]
  node_termux_notif["Termux notifications<br/>[termux_notif.py]"]
  node_logger["Logger<br/>[logger.py]"]
  node_stime["Weekly time<br/>[stime.py]"]
  node_time_tracker["Interval tracker<br/>[timetracker.py]"]
end

node_user(("Automation caller"))
node_android(("Android device"))
node_shell(("Host shell"))

node_user -.->|"runs states"| node_handler
node_handler -.->|"dispatches"| node_ui_states
node_ui_states -->|"calls actions"| node_state_functions
node_ui_states -->|"reads metadata"| node_task_info
node_handler -->|"uses metadata"| node_task_info
node_ui_states -->|"queries UI"| node_device_session
node_device_session -.->|"queries device"| node_android
node_adb_actions -->|"sends input"| node_android
node_adb_actions -->|"reads system type"| node_process_system
node_adb_actions -->|"runs commands"| node_shell
node_pipes -->|"opens ADB shell"| node_android
node_pipes -->|"creates pipes"| node_shell
node_shell_notif -->|"posts notification"| node_shell

click node_task_info "https://github.com/lmoq/u2state/blob/main/U2/task.py"
click node_handler "https://github.com/lmoq/u2state/blob/main/U2/states/state.py"
click node_ui_states "https://github.com/lmoq/u2state/blob/main/U2/states/states.py"
click node_state_functions "https://github.com/lmoq/u2state/blob/main/U2/states/functions.py"
click node_enums "https://github.com/lmoq/u2state/blob/main/U2/enums.py"
click node_device_session "https://github.com/lmoq/u2state/blob/main/U2/base.py"
click node_adb_actions "https://github.com/lmoq/u2state/blob/main/U2/adb_tools/adb.py"
click node_pipes "https://github.com/lmoq/u2state/blob/main/U2/process/pipes.py"
click node_process_system "https://github.com/lmoq/u2state/blob/main/U2/process/system.py"
click node_shell_notif "https://github.com/lmoq/u2state/blob/main/U2/notif/shell_notif.py"
click node_termux_notif "https://github.com/lmoq/u2state/blob/main/U2/notif/termux_notif.py"
click node_logger "https://github.com/lmoq/u2state/blob/main/U2/debug/logger.py"
click node_stime "https://github.com/lmoq/u2state/blob/main/U2/time/stime.py"
click node_time_tracker "https://github.com/lmoq/u2state/blob/main/U2/time/timetracker.py"

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_task_info,node_handler,node_ui_states,node_state_functions,node_enums toneBlue
class node_device_session,node_adb_actions,node_pipes,node_process_system toneAmber
class node_shell_notif,node_termux_notif,node_logger,node_stime,node_time_tracker toneMint
class node_user,node_android,node_shell toneIndigo
```

## Components

### Task orchestration

- [Task metadata](https://github.com/lmoq/u2state/blob/main/U2/task.py): `U2/task.py`
- [State handler](https://github.com/lmoq/u2state/blob/main/U2/states/state.py): `U2/states/state.py`
- [UI states](https://github.com/lmoq/u2state/blob/main/U2/states/states.py): `U2/states/states.py`
- [State actions](https://github.com/lmoq/u2state/blob/main/U2/states/functions.py): `U2/states/functions.py`
- [Action enums](https://github.com/lmoq/u2state/blob/main/U2/enums.py): `U2/enums.py`

### Android device access

- [Device session](https://github.com/lmoq/u2state/blob/main/U2/base.py): `U2/base.py`
- [ADB input](https://github.com/lmoq/u2state/blob/main/U2/adb_tools/adb.py): `U2/adb_tools/adb.py`
- [ADB shell pipes](https://github.com/lmoq/u2state/blob/main/U2/process/pipes.py): `U2/process/pipes.py`
- [System detection](https://github.com/lmoq/u2state/blob/main/U2/process/system.py): `U2/process/system.py`

### Runtime support

- [Shell notifications](https://github.com/lmoq/u2state/blob/main/U2/notif/shell_notif.py): `U2/notif/shell_notif.py`
- [Termux notifications](https://github.com/lmoq/u2state/blob/main/U2/notif/termux_notif.py): `U2/notif/termux_notif.py`
- [Logger](https://github.com/lmoq/u2state/blob/main/U2/debug/logger.py): `U2/debug/logger.py`
- [Weekly time](https://github.com/lmoq/u2state/blob/main/U2/time/stime.py): `U2/time/stime.py`
- [Interval tracker](https://github.com/lmoq/u2state/blob/main/U2/time/timetracker.py): `U2/time/timetracker.py`

### Other components

- **Automation caller**
- **Android device**
- **Host shell**

## Connections

- Automation caller → State handler: runs states
- State handler → UI states: dispatches (evidence: `U2/states/states.py`)
- UI states → State actions: calls actions (evidence: `U2/states/states.py`)
- UI states → Task metadata: reads metadata (evidence: `U2/states/states.py`)
- State handler → Task metadata: uses metadata (evidence: `U2/states/state.py`)
- UI states → Device session: queries UI (evidence: `U2/states/states.py`)
- Device session → Android device: queries device
- ADB input → Android device: sends input (evidence: `U2/adb_tools/adb.py`)
- ADB input → System detection: reads system type (evidence: `U2/adb_tools/adb.py`)
- ADB input → Host shell: runs commands (evidence: `U2/adb_tools/adb.py`)
- ADB shell pipes → Android device: opens ADB shell (evidence: `U2/process/pipes.py`)
- ADB shell pipes → Host shell: creates pipes (evidence: `U2/process/pipes.py`)
- Shell notifications → Host shell: posts notification (evidence: `U2/notif/shell_notif.py`)
