# sumzer0-git/edapgui architecture

> Architecture diagram of the GitHub repository sumzer0-git/edapgui, 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/sumzer0-git/edapgui
- Repository: https://github.com/sumzer0-git/edapgui

## Overview

##### Main components
- User Interface & Main Controller: The EDAPGui.py file acts as the entry point, initializing the GUI and overall autopilot control.
- Assist Modules: There are different Python modules that encapsulate the various in-game assists (FSD Route Assist, Supercruise Assist, Waypoint Assist, Robigo Assist, and AFK Combat Assist). Although these may be spread over several files (e.g., ED_AP.py, EDafk_combat.py, NavRouteParser.py, etc.), represent them as separate “assist engines” under an Autopilot Manager.
- Computer Vision Engine: Core modules like OCR.py, Image_Templates.py, and Screen_Regions.py indicate that the system captures the game screen, performs template matching, and identifies key elements used to determine status.
- Input & Control Modules: Files such as directinput.py, MousePt.py, and EDKeys.py handle the simulation of keystrokes and mouse events. These are critical for interacting with Elite Dangerous externally.
- Configuration & Data Files: The configs folder (with baseline_ships.json, resolution.json, user_ships.json), the ships and waypoints folders, and the config file (config-AP.json mentioned in the README) represent the static data that tunes the behavior of the autopilot (for ship tuning or waypoint routes).
- Logging & Diagnostics: EDlogger.py, Test_Routines.py, and the verbose logging options (via autopilot.log) indicate modules developed for tracking behavior and debugging.

##### Relationships and interactions
- The EDAPGui (main entry module) connects to the Autopilot Manager, which spawns individual assist modules based on user input or hotkeys.
- The Autopilot Manager directs computer vision components to retrieve screenshots (using Screen.py and Screen_Regions.py) and then process these images by comparing them with templates (Image_Templates.py, OCR.py).
- Simultaneously, configuration files (from configs, ships, and waypoints) are loaded to provide parameters like ship-specific tuning, keybindings, and resolution data.
- When an assist is triggered (for example, FSD or Supercruise Assist), the control flow goes from the UI/Manager to the specific module that computes the next steps, and then to the Input & Control layer (via directinput.py) to send keystrokes/mouse events to the running Elite Dangerous window.
- Logging (EDlogger.py) and error handling feed back into the UI to update the user, and diagnostic messages are saved.
- There is also integration with external services such as TCE (Trade Computer Extension) and (optionally) Discord notifications for future extensibility.

##### Architectural patterns and design principles
- Modular design: The project is broken into multiple single-responsibility modules. For example, separate files for different autopilot assists and distinct modules for computer vision and direct input.
- Configuration-Driven: Much of the behavior (keybindings, ship parameters, screen resolution) is defined via JSON configuration files.
- Event-Driven & Asynchronous: The system uses threading and event-based triggers (hotkeys, screen events) to switch between different assists when required.
- External Integration: The project uses external libraries (e.g., mss for screen capture, pynput for keyboard interactions) to interface with the game externally.

##### Relevant technologies and frameworks
- Language: Python (targeting 3.11, though compatible with 3.9/3.10).
- Libraries/Frameworks: Likely mss (for screen capture), pynput (for keyboard input), and possibly OpenCV (for computer vision template matching).
- OS: Windows-specific integration (evidenced by direct input commands, Win32 API calls, and Windows-specific configuration files).

- The Main UI/Controller (EDAPGui)
- Autopilot Manager with sub-components for each assist (FSD Route Assist, Supercruise Assist, etc.)
- Computer Vision Processor (OCR, Template Matching)
- Input & Control Module (directinput and keystroke simulation)
- Configuration/Data Store (configs, ships, waypoints)
- Logging & Diagnostics System
- Data input from the screen (via Screen.py and OCR) flows into the Vision Processor.
- Vision outputs and configuration feed into the Autopilot Manager.
- The Manager sends commands to the Input Module that in turn interacts with the game.
- Logging feedback loops from each component back to a central logger.
- That the design is modular and configuration-driven.
- Mention the threading or event-driven aspects if applicable.

##### Final advice
- Gradually add layers to include specific modules (like EDKeys, EDlogger, etc.) as sub-components beneath the main blocks.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface Layer"
        UI["EDAPGui (Main Controller)"]:::ui
    end

    %% Control & Assist Layer
    subgraph "Control & Assist Layer"
        AM["Autopilot Manager"]:::assist
        subgraph "Assist Modules"
            EDAP["ED_AP"]:::assist
            EDAC["EDafk_combat"]:::assist
            NRP["NavRouteParser"]:::assist
            EWP["EDWayPoint"]:::assist
        end
    end

    %% Computer Vision Layer
    subgraph "Computer Vision Layer"
        CV["Computer Vision Engine"]:::vision
        OCR["OCR"]:::vision
        IT["Image Templates"]:::vision
        SR["Screen Regions"]:::vision
        SC["Screen"]:::vision
    end

    %% Input & Control Layer
    subgraph "Input & Control Layer"
        IC["Input & Control Module"]:::input
        DI["directinput"]:::input
        MP["MousePt"]:::input
        EK["EDKeys"]:::input
    end

    %% Configuration & Data Files
    subgraph "Configuration & Data"
        CF["Configuration & Data Files"]:::config
        CONF["configs"]:::config
        SHIPS["ships"]:::config
        WPTS["waypoints"]:::config
        CAP["config-AP.json"]:::config
    end

    %% Logging & Diagnostics
    subgraph "Logging & Diagnostics"
        LOG["Logging & Diagnostics"]:::log
        EL["EDlogger"]:::log
        TR["Test_Routines"]:::log
    end

    %% Documentation & Calibration
    subgraph "Documentation & Calibration"
        DOCS["docs"]:::docs
    end

    %% External System
    ED_EXTERNAL["Elite Dangerous (Game)"]:::external

    %% Relationships
    UI -->|"init_control"| AM
    AM -->|"spawn_assists"| EDAP
    AM -->|"spawn_assists"| EDAC
    AM -->|"spawn_assists"| NRP
    AM -->|"spawn_assists"| EWP
    AM -->|"process_vision"| CV
    CV -->|"output_vision"| AM
    AM -->|"trigger_input"| IC
    CF -->|"load_config"| AM
    CV -->|"capture_ocr"| OCR
    CV -->|"capture_templates"| IT
    CV -->|"capture_regions"| SR
    CV -->|"capture_screen"| SC
    IC -->|"simulate_input"| DI
    IC -->|"simulate_input"| MP
    IC -->|"simulate_input"| EK
    IC -->|"send_commands"| ED_EXTERNAL
    UI -->|"feedback"| LOG
    AM -->|"log_status"| LOG
    CV -->|"log_vision"| LOG
    IC -->|"log_input"| LOG

    %% Click Events for Component Mapping
    click UI "https://github.com/sumzer0-git/edapgui/blob/main/EDAPGui.py"
    click EDAP "https://github.com/sumzer0-git/edapgui/blob/main/ED_AP.py"
    click EDAC "https://github.com/sumzer0-git/edapgui/blob/main/EDafk_combat.py"
    click NRP "https://github.com/sumzer0-git/edapgui/blob/main/NavRouteParser.py"
    click EWP "https://github.com/sumzer0-git/edapgui/blob/main/EDWayPoint.py"
    click OCR "https://github.com/sumzer0-git/edapgui/blob/main/OCR.py"
    click IT "https://github.com/sumzer0-git/edapgui/blob/main/Image_Templates.py"
    click SR "https://github.com/sumzer0-git/edapgui/blob/main/Screen_Regions.py"
    click SC "https://github.com/sumzer0-git/edapgui/blob/main/Screen.py"
    click DI "https://github.com/sumzer0-git/edapgui/blob/main/directinput.py"
    click MP "https://github.com/sumzer0-git/edapgui/blob/main/MousePt.py"
    click EK "https://github.com/sumzer0-git/edapgui/blob/main/EDKeys.py"
    click CONF "https://github.com/sumzer0-git/edapgui/tree/main/configs/"
    click SHIPS "https://github.com/sumzer0-git/edapgui/tree/main/ships/"
    click WPTS "https://github.com/sumzer0-git/edapgui/tree/main/waypoints/"
    click CAP "https://github.com/sumzer0-git/edapgui/blob/main/config-AP.json"
    click EL "https://github.com/sumzer0-git/edapgui/blob/main/EDlogger.py"
    click TR "https://github.com/sumzer0-git/edapgui/blob/main/Test_Routines.py"
    click DOCS "https://github.com/sumzer0-git/edapgui/tree/main/docs/"

    %% Style Definitions
    classDef ui fill:#87CEFA,stroke:#0056b3,stroke-width:2px;
    classDef assist fill:#90EE90,stroke:#006400,stroke-width:2px;
    classDef vision fill:#FFD700,stroke:#B8860B,stroke-width:2px;
    classDef input fill:#FFB6C1,stroke:#C71585,stroke-width:2px;
    classDef config fill:#D3D3D3,stroke:#696969,stroke-width:2px;
    classDef log fill:#F5DEB3,stroke:#CD853F,stroke-width:2px;
    classDef docs fill:#E6E6FA,stroke:#9370DB,stroke-width:2px;
    classDef external fill:#FFE4B5,stroke:#A0522D,stroke-width:2px;
```
