# hgjazhgj/fgo-py architecture

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

- Interactive diagram: https://gitdiagram.com/hgjazhgj/fgo-py
- Repository: https://github.com/hgjazhgj/fgo-py

## Overview

##### Main Components
- Entry Points: The main script (fgo.py) serves as the primary launcher. It dispatches to either the GUI (fgoGui.py, fgoMainWindow.py) or the CLI (fgoCli.py) interfaces.
- User Interfaces:
– Graphical Interface (built on Qt6): fgoGui.py, fgoMainWindow.py, and associated UI files (.ui).
– Command Line Interface: fgoCli.py.
- Core Business Logic: Several modules in the FGO-py package manage game automation; these include:
– Battle automation and scheduling (fgoFarming.py, fgoSchedule.py, fgoRunOnce.py).
– Team configuration and parsing (fgoTeamupParser.py, fgoTeamup.ini, fgoTeamupDialog.py).
– Game mechanics helpers such as fgoFuse.py, fgoOcr.py, fgoReishift.py.
– Device management (fgoDevice.py) that handles connection and commands (including specialized connection shortcuts noted in the README).
– Kernel module (fgoKernel.py) that likely orchestrates lower-level operations.
- Configuration and Localization:
– fgoConfig.py for runtime settings stored in JSON.
– Internationalization resources (fgoI18n.[lang].qm/ts files) that allow multi-language support.
- Assets and Resource Management:
– The fgoImage directory holds a large number of graphical assets (for servants, classes, maps, etc.), which are used by the automation UI and logic.
- Utility & Logging:
– fgoLogging.py and the fgoLog folder help track operations.
– fgoMetadata.py, which likely contains data extraction/processing for in-game elements.
- Web Components:
– fgoWebServer.py and fgoWebUI indicate that a web interface exists for remote monitoring/control.
- Deployment Support:
– The deploy/ subdirectories provide Docker setups and automation scripts for environments like AidLux and AzurLaneAutoScript.

##### Establish Relationships and Data Flows
- Both interfaces feed commands to the central launcher (fgo.py), which in turn routes commands to the core business logic.
- The business logic interacts with:
– The device connection layer (fgoDevice.py) to send ADB commands or capture screenshots (aided by fgoImageListener.py).
– The configuration management (fgoConfig.py) for runtime settings and stored preferences.
– The scheduling module (fgoSchedule.py) to manage and queue automated tasks (like automatic missions and team setups).
- Image assets (from fgoImage) and localization files serve as static resources, referenced by both UI and automation logic.
- Logging (fgoLogging.py and fgoLog/) provide continuous feedback from the background operations.
- Optionally, include an external services layer for deployment (Docker, AidLux, and others) that show environment-specific configuration impacting the core engine.
- Built-in “helper” functions for connection strings (e.g., specific shortcuts for BlueStacks) which reside in the device connection modules.

##### Architectural Patterns
- Separation of Concerns: Clearly separate the UI layer (GUI/CLI), the business logic/core automation engine, and the device/operating system integration layer.
- Modular Design: Each component (e.g., team formation, battle management, image recognition) is developed as an independent module that interconnects through well-defined interfaces.
- Extensibility: The use of external configuration (fgoConfig.json, teamup.ini) and asset directories points to an architecture that encourages user customization without changing the core code.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interfaces
    user["User"]:::entry

    subgraph "User Interfaces"
        subgraph "Graphical User Interface"
            fgo_gui["fgoGui.py"]:::ui
            fgo_mainwindow["fgoMainWindow.py"]:::ui
            mainwindow_ui["fgoMainWindow.ui"]:::ui
            fgo_gui_teamup["fgoGuiTeamup.py"]:::ui
        end
        fgo_cli["fgoCli.py"]:::cli
    end

    %% Entry Point
    fgo["fgo.py"]:::entry

    %% Core Business Logic Subgraph
    subgraph "Core Business Logic"
        fgo_farming["fgoFarming.py"]:::bl
        fgo_schedule["fgoSchedule.py"]:::bl
        fgo_runonce["fgoRunOnce.py"]:::bl

        fgo_teamup_parser["fgoTeamupParser.py"]:::bl
        fgo_teamup_dialog["fgoTeamupDialog.py"]:::bl
        teamup_dialog_ui["fgoTeamupDialog.ui"]:::bl
        fgo_teamup_ini["fgoTeamup.ini"]:::bl

        fgo_fuse["fgoFuse.py"]:::bl
        fgo_ocr["fgoOcr.py"]:::bl
        fgo_reishift["fgoReishift.py"]:::bl

        fgo_kernel["fgoKernel.py"]:::bl
    end

    %% Device Management Subgraph
    subgraph "Device Management"
        fgo_device["fgoDevice.py"]:::dev
        fgo_image_listener["fgoImageListener.py"]:::dev
    end

    %% Configuration and Localization
    subgraph "Configuration and Localization"
        fgo_config["fgoConfig.py"]:::conf
        fgo_i18n["Internationalization Resources"]:::conf
    end

    %% Assets and Logging
    subgraph "Assets and Logging"
        fgo_image["fgoImage (Assets)"]:::asset
        fgo_logging["fgoLogging.py"]:::log
        fgo_log["fgoLog (Folder)"]:::log
    end

    %% Metadata Processing
    fgo_metadata["fgoMetadata.py"]:::meta

    %% Web Components and Deployment
    subgraph "Web and Deployment"
        fgo_webserver["fgoWebServer.py"]:::web
        fgo_webui["fgoWebUI (Folder)"]:::web
        deploy_node["deploy (Folder)"]:::deploy
    end

    %% Connections from User Interfaces to Entry Point
    fgo_gui -->|"routes"| fgo
    fgo_mainwindow -->|"routes"| fgo
    mainwindow_ui -->|"routes"| fgo
    fgo_gui_teamup -->|"routes"| fgo
    fgo_cli -->|"routes"| fgo
    user -->|"initiates"| fgo_gui
    user -->|"initiates"| fgo_cli

    %% Entry Point to Core Business Logic and Configuration
    fgo -->|"routes"| fgo_farming
    fgo -->|"routes"| fgo_teamup_parser
    fgo -->|"routes"| fgo_fuse
    fgo -->|"routes"| fgo_kernel
    fgo -->|"loads"| fgo_config
    fgo -->|"triggers"| fgo_webserver

    %% Internal Business Logic flows
    fgo_farming -->|"sequenced"| fgo_schedule
    fgo_schedule -->|"sequenced"| fgo_runonce

    fgo_teamup_parser -->|"parses"| fgo_teamup_dialog
    fgo_teamup_dialog -->|"renders"| teamup_dialog_ui
    fgo_teamup_parser -->|"reads"| fgo_teamup_ini

    fgo_kernel -->|"orchestrates"| fgo_ocr
    fgo_kernel -->|"orchestrates"| fgo_reishift

    %% Business Logic interacts with Device Management
    fgo_kernel -->|"ADB_commands"| fgo_device
    fgo_kernel -->|"ADB_commands"| fgo_image_listener

    %% Business Logic uses Assets and logs feedback
    fgo_fuse -->|"uses"| fgo_image
    fgo_kernel -->|"logs"| fgo_logging
    fgo_device -->|"logs"| fgo_logging

    %% Logging feeds back to UI (for display)
    fgo_logging -->|"feedback"| fgo_gui

    %% Configuration interacts with Localization
    fgo_config -->|"integrates"| fgo_i18n

    %% Metadata extraction from Business Logic
    fgo_kernel -->|"extracts"| fgo_metadata

    %% Web and Deployment integration
    fgo_webserver -->|"serves"| fgo_webui
    fgo_webserver -->|"integrates"| deploy_node

    %% Styles
    classDef entry fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef ui fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef cli fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef bl fill:#ABEBC6,stroke:#239B56,stroke-width:2px;
    classDef dev fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef conf fill:#FDEBD0,stroke:#D35400,stroke-width:2px;
    classDef asset fill:#D7BDE2,stroke:#8E44AD,stroke-width:2px;
    classDef log fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef meta fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
    classDef web fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
    classDef deploy fill:#BB8FCE,stroke:#6C3483,stroke-width:2px;

    %% Click Events
    click fgo "https://github.com/hgjazhgj/fgo-py/blob/master/FGO-py/fgo.py"
    click fgo_gui "https://github.com/hgjazhgj/fgo-py/blob/master/FGO-py/fgoGui.py"
    click fgo_mainwindow "https://github.com/hgjazhgj/fgo-py/blob/master/FGO-py/fgoMainWindow.py"
    click mainwindow_ui "https://github.com/hgjazhgj/fgo-py/blob/master/FGO-py/fgoMainWindow.ui"
    click fgo_gui_teamup "https://github.com/hgjazhgj/fgo-py/blob/master/FGO-py/fgoGuiTeamup.py"
    click fgo_cli "https://github.com/hgjazhgj/fgo-py/blob/master/FGO-py/fgoCli.py"
    click fgo_farming "https://github.com/hgjazhgj/fgo-py/blob/master/FGO-py/fgoFarming.py"
    click fgo_schedule "https://github.com/hgjazhgj/fgo-py/blob/master/FGO-py/fgoSchedule.py"
    click fgo_runonce "https://github.com/hgjazhgj/fgo-py/blob/master/FGO-py/fgoRunOnce.py"
    click fgo_teamup_parser "https://github.com/hgjazhgj/fgo-py/blob/master/FGO-py/fgoTeamupParser.py"
    click fgo_teamup_ini "https://github.com/hgjazhgj/fgo-py/blob/master/FGO-py/fgoTeamup.ini"
    click fgo_teamup_dialog "https://github.com/hgjazhgj/fgo-py/blob/master/FGO-py/fgoTeamupDialog.py"
    click teamup_dialog_ui "https://github.com/hgjazhgj/fgo-py/blob/master/FGO-py/fgoTeamupDialog.ui"
    click fgo_fuse "https://github.com/hgjazhgj/fgo-py/blob/master/FGO-py/fgoFuse.py"
    click fgo_ocr "https://github.com/hgjazhgj/fgo-py/blob/master/FGO-py/fgoOcr.py"
    click fgo_reishift "https://github.com/hgjazhgj/fgo-py/blob/master/FGO-py/fgoReishift.py"
    click fgo_device "https://github.com/hgjazhgj/fgo-py/blob/master/FGO-py/fgoDevice.py"
    click fgo_image_listener "https://github.com/hgjazhgj/fgo-py/blob/master/FGO-py/fgoImageListener.py"
    click fgo_kernel "https://github.com/hgjazhgj/fgo-py/blob/master/FGO-py/fgoKernel.py"
    click fgo_config "https://github.com/hgjazhgj/fgo-py/blob/master/FGO-py/fgoConfig.py"
    click fgo_i18n "https://github.com/hgjazhgj/fgo-py/blob/master/FGO-py/fgoI18n.en.qm"
    click fgo_image "https://github.com/hgjazhgj/fgo-py/tree/master/FGO-py/fgoImage"
    click fgo_logging "https://github.com/hgjazhgj/fgo-py/blob/master/FGO-py/fgoLogging.py"
    click fgo_log "https://github.com/hgjazhgj/fgo-py/tree/master/FGO-py/fgoLog"
    click fgo_metadata "https://github.com/hgjazhgj/fgo-py/blob/master/FGO-py/fgoMetadata.py"
    click fgo_webserver "https://github.com/hgjazhgj/fgo-py/blob/master/FGO-py/fgoWebServer.py"
    click fgo_webui "https://github.com/hgjazhgj/fgo-py/tree/master/FGO-py/fgoWebUI"
    click deploy_node "https://github.com/hgjazhgj/fgo-py/tree/master/deploy"
```
