# runhey/onmyojiautoscript architecture

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

- Interactive diagram: https://gitdiagram.com/runhey/onmyojiautoscript
- Repository: https://github.com/runhey/onmyojiautoscript

## Overview

##### Project Type & Purpose
- This is a Python-driven automation tool for the mobile game Onmyoji. It automates an extensive list of game-related tasks (daily tasks, weekly events, various in-game battles, etc.) to “free up” the player’s time.
- The README makes it clear that the system is “one-click managed” and involves both a backend automation engine and a GUI frontend that is built separately (with modern frameworks such as Flutter or QML via FluentUI).

##### Analyzing the File Structure — Key Components
- Core Engine & Modules:
– The “module” directory contains the automation’s business logic. It is subdivided into:
- “atom”: Low-level actions (click, swipe, image handling, OCR, etc.)
- “base”: Core utilities (decorators, timers, logging, and utility functions)
- “config”: Configuration management (using pydantic-based config files and watchers)
- “device”: Abstraction for device interaction (ADB, droidcast, scrcpy methods, emulator handling, etc.)
- “server”: A backend server component, likely to coordinate tasks, network requests, or service communications.
- “gui”: Houses the GUI bridging component; includes QML resources and FluentUI support – implying the front end can run independently for user interactions.
- “daemon” and “handler”: Background processing and exception handling/logging.
- GUI & Presentation Layer:
– The separate “fluentui” directory (with CMakeLists, QML, and example projects) and the “module/gui” folder clearly indicate the existence of a dedicated user interface layer.
– This layer is responsible for visual presentation, user task management, and providing a platform-independent front end (potentially built with Flutter as mentioned in the README).
- Tasks & Automation Scripts:
– The “tasks” directory contains many subdirectories that provide ready-to-run automation scripts for different game events. Each task folder includes configuration files, asset definitions (images, click positions, etc.) and a “script_task.py” module that integrates with the backend.
- Helper Tools and Deployment:
– The “bin” folder holds precompiled binaries for device interactions (e.g., scrcpy, droidcast, hermit).
– The “deploy” folder offers scripts to assist in deployment and environment setup.
– “dev_tools” includes scripts for maintenance tasks (generating requirements, asset extraction, etc.).

##### Defining Main Components
- Frontend GUI:
▪ Comprises “module/gui” and “fluentui”.
▪ It accepts user input; displays game state, settings, and task dashboards.
- Automation/Orchestration Engine:
▪ Core logic is in “module” (including submodules like atom, base, config, and daemon).
▪ It schedules and executes tasks, processes configuration files (and uses pydantic models), and manages the global task flow.
- Device Interaction Layer:
▪ Contains “module/device” and integrates with external binaries (from “bin”) such as adb, scrcpy, droidcast.
▪ Manages connections to game devices/emulators and executes touch/click events.
- Task Management Subsystem:
▪ Represented by the “tasks” folder.
▪ Each task (e.g., DailyTrifles, DemonEncounter, GuildBanquet, etc.) acts as a plug-in to the automation engine. They define specific sequences and asset interactions for each game event.
- Server/Communication Module:
▪ Located in “module/server” and possibly invoked via “server.py”.
▪ Handles any networking, remote command control, or inter-process coordination.
- Supporting Components:
▪ Logging, configuration watchers, and utility modules (provided in “module/config”, “module/logger”, etc.)
▪ Deployment and device helper scripts (in “deploy” and “dev_tools”).

##### Specifying Relationships & Data Flow
- The GUI layer sends user commands and configuration changes to the Core Engine.
- The Core Engine uses the configuration modules to load task parameters and triggers appropriate automation scripts from the “tasks” folder.
- For executing interactions, the engine calls the Device Interaction Layer which uses various helper executables (for click, swipe, OCR, etc.).
- The results and status updates flow back from the Device Layer to the Core Engine and then propagate to the GUI for display.
- The Server module may expose API endpoints or websockets to remotely issue commands or to monitor running tasks.

##### Architectural Patterns and Relevant Technologies
- Separation of concerns (frontend vs. backend vs. device communication): clearly separate automation, UI presentation, and low-level device handlers.
- Modular plug-in-like system for tasks; easy to add new game-specific features.
- Utilization of familiar frameworks and libraries:
▪ QML and FluentUI for GUI
▪ pydantic for configuration validation
▪ onnxruntime-based OCR (using ppocr-onnx) integrated for AI-assisted tasks
▪ ADB, scrcpy as external tools for device control.

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Interface Layer
    subgraph "User Interface Layer"
        A1["GUI Frontend (FluentUI & QML)"]:::gui
        A2["FluentUI Resources"]:::gui
    end

    %% Core Automation Engine
    subgraph "Core Automation Engine"
        B1["Automation Engine (Core Modules)"]:::automation
    end

    %% Task Management Subsystem
    subgraph "Task Management Subsystem"
        C1["Task Manager (Plug-In Tasks)"]:::task
    end

    %% Device Interaction Layer
    subgraph "Device Interaction Layer"
        D1["Device Communication (ADB, scrcpy, etc.)"]:::device
        D2["External Device Binaries"]:::device
    end

    %% Server/Communication Module
    subgraph "Server/Communication Module"
        E1["Server/Remote API"]:::server
        E2["Server Entry Point"]:::server
    end

    %% Supporting Components
    subgraph "Supporting Components"
        F1["Deployment Scripts"]:::support
        F2["Dev Tools & Maintenance"]:::support
    end

    %% Connections
    A1 -->|"commands"| B1
    B1 -->|"triggers_tasks"| C1
    B1 -->|"executes_actions"| D1
    D1 -->|"status_update"| B1
    B1 -->|"update_UI"| A1
    B1 -->|"network_sync"| E1
    E1 -->|"remote_cmd"| B1
    %% Auxiliary support connections (dashed lines for supporting utilities)
    B1 -.->|"config_sync"| F1
    B1 -.->|"maintenance"| F2

    %% Click Events
    click A2 "https://github.com/runhey/onmyojiautoscript/tree/master/fluentui"
    click A1 "https://github.com/runhey/onmyojiautoscript/tree/master/module/gui"
    click B1 "https://github.com/runhey/onmyojiautoscript/tree/master/module"
    click D1 "https://github.com/runhey/onmyojiautoscript/tree/master/module/device"
    click D2 "https://github.com/runhey/onmyojiautoscript/tree/master/bin"
    click C1 "https://github.com/runhey/onmyojiautoscript/tree/master/tasks"
    click E1 "https://github.com/runhey/onmyojiautoscript/tree/master/module/server"
    click E2 "https://github.com/runhey/onmyojiautoscript/blob/master/server.py"
    click F1 "https://github.com/runhey/onmyojiautoscript/tree/master/deploy"
    click F2 "https://github.com/runhey/onmyojiautoscript/tree/master/dev_tools"

    %% Styles
    classDef gui fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef automation fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef task fill:#ffcc00,stroke:#000,stroke-width:2px;
    classDef device fill:#ffa500,stroke:#000,stroke-width:2px;
    classDef server fill:#dda0dd,stroke:#000,stroke-width:2px;
    classDef support fill:#d3d3d3,stroke:#000,stroke-width:2px;
```
