# orailnoor/private-agent architecture

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

- Interactive diagram: https://gitdiagram.com/orailnoor/private-agent
- Repository: https://github.com/orailnoor/private-agent

## Overview

#### Purpose and Runtime

PrivateAgent is a Flutter Android application that translates text, voice, or Telegram commands into multi-step automation across installed apps. Its core loop combines an LLM provider with Android Accessibility APIs: inspect current UI, ask the model for the next action, execute it natively, and repeat. Primary Flutter entry points are `lib/main.dart` and the overlay entry point `lib/overlay_main.dart`; Android starts through `android/app/src/main/kotlin/com/orailnoor/privateagent/MainActivity.kt`.

#### UI, Onboarding, and User Control

Flutter screens expose command interaction, setup, configuration, and history. Onboarding guides required Android accessibility permissions; settings holds AI-provider and Telegram configuration; the home screen is the primary interactive surface. Key paths: `lib/screens/home_screen.dart`, `lib/screens/onboarding_screen.dart`, `lib/screens/settings_screen.dart`. Feature availability is gated centrally in `lib/config/feature_flags.dart`.

#### Task Models and Execution Orchestration

The task domain is represented by actions, chat messages, and reusable saved skills. `TaskExecutor` is the likely orchestration boundary for a requested task, while `ActionHandler` dispatches individual AI-selected operations and recovery handles failure/retry behavior. Relevant paths: `lib/models/agent_action.dart`, `lib/services/task_executor.dart`, `lib/services/action_handler.dart`, `lib/services/recovery_engine.dart`.

#### AI Decision and Feedback Loop

`AIService` is the external-model boundary, expected to package task context, screen state, and prior action result for DeepSeek/OpenRouter-compatible APIs. Its output becomes `AgentAction` data, which the execution layer performs; subsequent screen inspection feeds the next iteration. Conversation and persistent skill context are managed separately through `lib/services/chat_history_service.dart` and `lib/services/skill_memory_service.dart`. The principal paths are `lib/services/ai_service.dart`, `lib/models/chat_message.dart`, and `lib/models/saved_skill.dart`.

#### Native Android Automation Boundary

Android Accessibility is the privileged actuator and UI-reader boundary. The declared service and its accessibility metadata are in `android/app/src/main/kotlin/com/orailnoor/privateagent/AgentAccessibilityService.kt` and `android/app/src/main/res/xml/accessibility_service_config.xml`. Flutter-facing automation abstractions include `lib/services/screen_automation_service.dart` and `lib/services/system_control_service.dart`. This boundary requires user-enabled Accessibility Service permissions and is Android-specific.

#### Command Inputs, Remote Control, and Device Integrations

Commands can originate locally, through speech recognition, or Telegram polling. Telegram is an external Bot API integration rather than an application backend; it forwards remote task commands and likely progress. Device-facing services cover voice, notifications, contacts, alarms, and app launch. Core paths: `lib/services/telegram_service.dart`, `lib/services/voice_service.dart`, `lib/services/communication_service.dart`, `lib/services/notification_service.dart`, and `lib/services/app_launcher_service.dart`.

#### Overlay and Platform Plugins

A separate Flutter overlay runtime supports persistent on-screen agent UI over other apps, backed by a vendored Android foreground/overlay plugin: `lib/overlay_main.dart`, `local_plugins/flutter_overlay_window/lib/flutter_overlay_window.dart`, and `local_plugins/flutter_overlay_window/android/src/main/java/flutter/overlay/window/flutter_overlay_window/OverlayService.java`. A second local method-channel plugin bridges custom native functions via `local_plugins/agent_native/lib/agent_native_method_channel.dart` and `local_plugins/agent_native/android/src/main/kotlin/com/example/agent_native/AgentNativePlugin.kt`.

#### Build and Release Infrastructure

The deployable target is Android/Flutter, built with Gradle Kotlin DSL under `android/app/build.gradle.kts`. Automated Android release packaging is defined in `.github/workflows/android-release.yml`. Runtime dependencies include Android API 26+, Accessibility Services, LLM HTTP APIs (DeepSeek/OpenRouter), Telegram Bot API polling, and native speech-to-text.

Main entry points: [`lib/services/task_executor.dart`](https://github.com/orailnoor/private-agent/blob/main/lib/services/task_executor.dart) (Task executor), [`lib/services/action_handler.dart`](https://github.com/orailnoor/private-agent/blob/main/lib/services/action_handler.dart) (Action handler), [`android/app/src/main/kotlin/com/orailnoor/privateagent/AgentAccessibilityService.kt`](https://github.com/orailnoor/private-agent/blob/main/android/app/src/main/kotlin/com/orailnoor/privateagent/AgentAccessibilityService.kt) (Accessibility service), [`lib/main.dart`](https://github.com/orailnoor/private-agent/blob/main/lib/main.dart) (App entry point)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_flutter["Flutter app"]
  node_main["App entry point<br/>Flutter runtime<br/>[main.dart]"]
  node_home["Home command UI<br/>Flutter screen<br/>[home_screen.dart]"]
  node_onboarding["Accessibility onboarding<br/>Flutter screen"]
  node_settings["Provider settings<br/>Flutter screen"]
  node_flags["Feature flags<br/>app configuration<br/>[feature_flags.dart]"]
end

subgraph group_automation["Agent automation"]
  node_task_executor{{"Task executor<br/>orchestrator<br/>[task_executor.dart]"}}
  node_action_handler["Action handler<br/>action dispatcher"]
  node_recovery["Recovery engine<br/>retry handler"]
  node_actions["Agent actions<br/>task model<br/>[agent_action.dart]"]
  node_ai{{"AI service<br/>LLM client<br/>[ai_service.dart]"}}
  node_memory[("Conversation and skills<br/>persistent context")]
  node_skills["Saved skills<br/>skill model<br/>[saved_skill.dart]"]
end

subgraph group_native["Android native"]
  node_automation_bridge["Screen automation<br/>Flutter platform service"]
  node_accessibility{{"Accessibility service<br/>Android service"}}
  node_accessibility_config["Accessibility metadata<br/>Android resource"]
  node_overlay["Overlay runtime<br/>Flutter overlay entry<br/>[overlay_main.dart]"]
  node_overlay_plugin["Overlay foreground service<br/>vendored Android plugin"]
  node_android_build["Android build target<br/>Gradle application<br/>[build.gradle.kts]"]
end

subgraph group_integrations["External integrations"]
  node_telegram["Telegram commands<br/>Bot API client"]
  node_voice["Voice commands<br/>speech input<br/>[voice_service.dart]"]
  node_device_services["Device integrations<br/>device service layer"]
end

node_release["Android release workflow<br/>CI workflow"]

node_main -->|"launches"| node_home
node_main -->|"routes to"| node_onboarding
node_main -->|"routes to"| node_settings
node_flags -.->|"gates features"| node_home
node_home -->|"submits commands"| node_task_executor
node_voice -->|"supplies commands"| node_task_executor
node_telegram -->|"supplies remote commands"| node_task_executor
node_task_executor -->|"requests next action"| node_ai
node_task_executor -->|"dispatches action"| node_action_handler
node_ai -->|"returns"| node_actions
node_actions -->|"defines operation"| node_action_handler
node_task_executor -->|"loads context"| node_memory
node_skills -->|"stored as"| node_memory
node_action_handler -->|"executes UI operation"| node_automation_bridge
node_automation_bridge -->|"uses platform boundary"| node_accessibility
node_accessibility_config -->|"declares capabilities"| node_accessibility
node_accessibility -->|"returns screen state"| node_task_executor
node_action_handler -.->|"on failure"| node_recovery
node_recovery -->|"retries or adapts"| node_task_executor
node_action_handler -->|"invokes device actions"| node_device_services
node_overlay -->|"runs through"| node_overlay_plugin
node_android_build -->|"packages"| node_accessibility
node_release -->|"builds release"| node_android_build

click node_main "https://github.com/orailnoor/private-agent/blob/main/lib/main.dart"
click node_home "https://github.com/orailnoor/private-agent/blob/main/lib/screens/home_screen.dart"
click node_onboarding "https://github.com/orailnoor/private-agent/blob/main/lib/screens/onboarding_screen.dart"
click node_settings "https://github.com/orailnoor/private-agent/blob/main/lib/screens/settings_screen.dart"
click node_flags "https://github.com/orailnoor/private-agent/blob/main/lib/config/feature_flags.dart"
click node_task_executor "https://github.com/orailnoor/private-agent/blob/main/lib/services/task_executor.dart"
click node_action_handler "https://github.com/orailnoor/private-agent/blob/main/lib/services/action_handler.dart"
click node_recovery "https://github.com/orailnoor/private-agent/blob/main/lib/services/recovery_engine.dart"
click node_actions "https://github.com/orailnoor/private-agent/blob/main/lib/models/agent_action.dart"
click node_ai "https://github.com/orailnoor/private-agent/blob/main/lib/services/ai_service.dart"
click node_memory "https://github.com/orailnoor/private-agent/blob/main/lib/services/chat_history_service.dart"
click node_skills "https://github.com/orailnoor/private-agent/blob/main/lib/models/saved_skill.dart"
click node_automation_bridge "https://github.com/orailnoor/private-agent/blob/main/lib/services/screen_automation_service.dart"
click node_accessibility "https://github.com/orailnoor/private-agent/blob/main/android/app/src/main/kotlin/com/orailnoor/privateagent/AgentAccessibilityService.kt"
click node_accessibility_config "https://github.com/orailnoor/private-agent/blob/main/android/app/src/main/res/xml/accessibility_service_config.xml"
click node_overlay "https://github.com/orailnoor/private-agent/blob/main/lib/overlay_main.dart"
click node_overlay_plugin "https://github.com/orailnoor/private-agent/blob/main/local_plugins/flutter_overlay_window/android/src/main/java/flutter/overlay/window/flutter_overlay_window/OverlayService.java"
click node_telegram "https://github.com/orailnoor/private-agent/blob/main/lib/services/telegram_service.dart"
click node_voice "https://github.com/orailnoor/private-agent/blob/main/lib/services/voice_service.dart"
click node_device_services "https://github.com/orailnoor/private-agent/blob/main/lib/services/communication_service.dart"
click node_android_build "https://github.com/orailnoor/private-agent/blob/main/android/app/build.gradle.kts"
click node_release "https://github.com/orailnoor/private-agent/blob/main/.github/workflows/android-release.yml"

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_main,node_home,node_onboarding,node_settings,node_flags toneBlue
class node_task_executor,node_action_handler,node_recovery,node_actions,node_ai,node_memory,node_skills toneAmber
class node_automation_bridge,node_accessibility,node_accessibility_config,node_overlay,node_overlay_plugin,node_android_build toneMint
class node_telegram,node_voice,node_device_services toneRose
class node_release toneNeutral
```

## Components

### Flutter app

- [App entry point](https://github.com/orailnoor/private-agent/blob/main/lib/main.dart): Flutter runtime · `lib/main.dart`
- [Home command UI](https://github.com/orailnoor/private-agent/blob/main/lib/screens/home_screen.dart): Flutter screen · Primary local command surface. · `lib/screens/home_screen.dart`
- [Accessibility onboarding](https://github.com/orailnoor/private-agent/blob/main/lib/screens/onboarding_screen.dart): Flutter screen · Guides users through required permissions. · `lib/screens/onboarding_screen.dart`
- [Provider settings](https://github.com/orailnoor/private-agent/blob/main/lib/screens/settings_screen.dart): Flutter screen · Configures AI provider and Telegram. · `lib/screens/settings_screen.dart`
- [Feature flags](https://github.com/orailnoor/private-agent/blob/main/lib/config/feature_flags.dart): app configuration · Central availability gates. · `lib/config/feature_flags.dart`

### Agent automation

- [Task executor](https://github.com/orailnoor/private-agent/blob/main/lib/services/task_executor.dart): orchestrator · Runs the inspect-decide-act loop. · `lib/services/task_executor.dart`
- [Action handler](https://github.com/orailnoor/private-agent/blob/main/lib/services/action_handler.dart): action dispatcher · `lib/services/action_handler.dart`
- [Recovery engine](https://github.com/orailnoor/private-agent/blob/main/lib/services/recovery_engine.dart): retry handler · `lib/services/recovery_engine.dart`
- [Agent actions](https://github.com/orailnoor/private-agent/blob/main/lib/models/agent_action.dart): task model · Model-selected operations. · `lib/models/agent_action.dart`
- [AI service](https://github.com/orailnoor/private-agent/blob/main/lib/services/ai_service.dart): LLM client · Sends task, UI state, and prior results to configured models. · `lib/services/ai_service.dart`
- [Conversation and skills](https://github.com/orailnoor/private-agent/blob/main/lib/services/chat_history_service.dart): persistent context · Stores chat history and reusable skills. · `lib/services/chat_history_service.dart`
- [Saved skills](https://github.com/orailnoor/private-agent/blob/main/lib/models/saved_skill.dart): skill model · `lib/models/saved_skill.dart`

### Android native

- [Screen automation](https://github.com/orailnoor/private-agent/blob/main/lib/services/screen_automation_service.dart): Flutter platform service · Reads UI and performs automation requests. · `lib/services/screen_automation_service.dart`
- [Accessibility service](https://github.com/orailnoor/private-agent/blob/main/android/app/src/main/kotlin/com/orailnoor/privateagent/AgentAccessibilityService.kt): Android service · Privileged UI reader and actuator. · `android/app/src/main/kotlin/com/orailnoor/privateagent/AgentAccessibilityService.kt`
- [Accessibility metadata](https://github.com/orailnoor/private-agent/blob/main/android/app/src/main/res/xml/accessibility_service_config.xml): Android resource · `android/app/src/main/res/xml/accessibility_service_config.xml`
- [Overlay runtime](https://github.com/orailnoor/private-agent/blob/main/lib/overlay_main.dart): Flutter overlay entry · Persistent UI over other apps. · `lib/overlay_main.dart`
- [Overlay foreground service](https://github.com/orailnoor/private-agent/blob/main/local_plugins/flutter_overlay_window/android/src/main/java/flutter/overlay/window/flutter_overlay_window/OverlayService.java): vendored Android plugin · `local_plugins/flutter_overlay_window/android/src/main/java/flutter/overlay/window/flutter_overlay_window/OverlayService.java`
- [Android build target](https://github.com/orailnoor/private-agent/blob/main/android/app/build.gradle.kts): Gradle application · Deployable Android target. · `android/app/build.gradle.kts`

### External integrations

- [Telegram commands](https://github.com/orailnoor/private-agent/blob/main/lib/services/telegram_service.dart): Bot API client · Polls remote task commands and reports progress. · `lib/services/telegram_service.dart`
- [Voice commands](https://github.com/orailnoor/private-agent/blob/main/lib/services/voice_service.dart): speech input · `lib/services/voice_service.dart`
- [Device integrations](https://github.com/orailnoor/private-agent/blob/main/lib/services/communication_service.dart): device service layer · Notifications, communication, and app launching. · `lib/services/communication_service.dart`

### Other components

- [Android release workflow](https://github.com/orailnoor/private-agent/blob/main/.github/workflows/android-release.yml): CI workflow · `.github/workflows/android-release.yml`

## Connections

- App entry point → Home command UI: launches
- App entry point → Accessibility onboarding: routes to
- App entry point → Provider settings: routes to
- Feature flags → Home command UI: gates features
- Home command UI → Task executor: submits commands
- Voice commands → Task executor: supplies commands
- Telegram commands → Task executor: supplies remote commands
- Task executor → AI service: requests next action
- Task executor → Action handler: dispatches action
- AI service → Agent actions: returns
- Agent actions → Action handler: defines operation
- Task executor → Conversation and skills: loads context
- Saved skills → Conversation and skills: stored as
- Action handler → Screen automation: executes UI operation
- Screen automation → Accessibility service: uses platform boundary
- Accessibility metadata → Accessibility service: declares capabilities
- Accessibility service → Task executor: returns screen state
- Action handler → Recovery engine: on failure
- Recovery engine → Task executor: retries or adapts
- Action handler → Device integrations: invokes device actions
- Overlay runtime → Overlay foreground service: runs through
- Android build target → Accessibility service: packages
- Android release workflow → Android build target: builds release
