# inavflight/inav-configurator architecture

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

- Interactive diagram: https://gitdiagram.com/inavflight/inav-configurator
- Repository: https://github.com/inavflight/inav-configurator

## Overview

##### Main High-Level Components
- Application Shell & Build System
– Electron main process and rendering processes (indicated by usage of Node.js, npm/yarn commands, and the inclusion of both HTML and JavaScript files).
– Build and packaging scripts (forge.config.js, package.json, various CI workflows under .github/workflows) that drive cross-platform builds.
- User Interface (UI) Layer
– HTML files (index.html, pages in the "tabs" and "wizard" directories) and associated CSS (located in src/css and tabs directories) which form the front-end.
– Client-side JavaScript files that control UI behavior (e.g., js/gui.js, js/main.js, and the many tab-related JS files).
- Communication & Connection Framework
– The “js/connection” folder clearly segregates connection types (connection.js, connectionBle.js, connectionSerial.js, connectionTcp.js, connectionUdp.js) indicating a Factory/Strategy pattern to manage various communication protocols.
– Additional protocol handling found in “js/protocols” (stm32, stm32usbdfu) and MSP related modules in “js/msp”.
- Data & Configuration Management
– Modules handling configuration, settings, defaults and global variables (e.g., js/settings.js, js/globalSettings.js, js/configurator_main.js, js/localization.js).
– Data storage and status updating components (js/data_storage.js, js/periodicStatusUpdater.js).
- External Services Integration
– Map provider integration: components for map configuration (indirectly referenced in the README along with MapProxy and Bing Maps API integration) should be incorporated.
– Asset management for fonts, images, and models stored in “assets”, “images”, and “resources” directories (including OSD fonts and 3D model files).
- Additional Libraries & Utilities
– Third-party libraries (CanvasRenderer, Projector, Three.js, jQuery-related scripts, Switchery, etc.) are housed under "js/libraries" and clearly play roles in rendering and UI interactions.
– Helper utilities for debugging, filtering, and event handling such as js/debug_trace.js, js/helpers.js, and filtering scripts.

##### Relationships & Interactions
- The UI layer (renderers created from index.html and various tab pages) drives user interactions. It sends commands, configuration updates, and requests to the underlying connection/communication layer.
- The Connection Manager (or the “js/connection” subsystem) abstracts the details of communicating with hardware (serial, BLE, TCP/UDP). This layer uses a factory pattern so that the UI doesn’t need to know the specifics.
- The Configuration Engine (modules like js/configurator_main.js, js/settings.js) bridges UI commands to data storage, applying changes to the INAV firmware parameters and settings.
- Communication between these layers happens via event-driven mechanisms (using callbacks, event listeners, or even web workers as seen in the js/workers directory).
- The Build & Packaging subsystem coordinates cross-platform packaging (WiX for Windows, deb/rpm for Linux, DMG for Mac) and interacts with external services (Map providers configuration, API keys for Bing Maps) as described in the README.

##### Important Architectural Patterns & Design Principles
- Modularization: Clear separation into directories for connection types, UI logic (tabs, wizard), and external libraries, which allows focused development and easier scalability.
- Abstraction & Factories: Especially in connection modules (using a connectionFactory.js to manage different hardware protocols).
- Event-Driven Programming: Given the number of event listeners, debug modules, and asynchronous UI updates, this becomes central to how data flows within the application.
- Cross-Platform Packaging: Emphasize that the tool is built with cross-platform compatibility in mind using Electron alongside platform-specific build scripts and assets.
- Separation of Concerns: Distinct directories for resources, assets, and logic components (UI, protocol, settings, etc.) ensure a clean architecture.

## Diagram (Mermaid)

```mermaid
flowchart TD

    subgraph "Application Shell & Build System"
        BS1["forge.config.js"]
        BS2["package.json (+ package-lock.json)"]
        BS3[".github/workflows"]
    end

    subgraph "User Interface (UI) Layer"
        UI1["index.html"]
        UI2["tabs directory"]
        UI3["src/css directory"]
    end

    subgraph "Communication & Connection Framework"
        COMM1["js/connection"]
        COMM2["js/protocols"]
        COMM3["js/msp"]
    end

    subgraph "Data & Configuration Management"
        DATA1["js/configurator_main.js"]
        DATA2["js/settings.js & js/globalSettings.js"]
        DATA3["js/data_storage.js"]
        DATA4["js/localization.js"]
    end

    subgraph "External Services Integration"
        EXT1["MAPPROXY.md"]
        EXT2["assets directory"]
        EXT3["images directory"]
        EXT4["resources directory"]
    end

    subgraph "Additional Libraries & Utilities"
        LIB1["js/libraries"]
        LIB2["js/helpers.js"]
        LIB3["js/debug_trace.js"]
        LIB4["js/workers"]
    end

    %% Main Flow Connections
    BS2 -->|"triggers"| UI1
    UI1 -->|"sends commands"| COMM1
    COMM1 -->|"routes data"| DATA1
    DATA1 -->|"updates"| EXT1

    %% Additional Libraries support
    LIB1 -->|"enhances"| UI1
    LIB1 -->|"assists"| COMM1
    LIB2 -->|"debugs"| DATA1

    %% Styles
    classDef build fill:#ffcccc,stroke:#990000,stroke-width:2px;
    classDef ui fill:#ccffcc,stroke:#009900,stroke-width:2px;
    classDef comm fill:#ccccff,stroke:#000099,stroke-width:2px;
    classDef config fill:#ffffcc,stroke:#999900,stroke-width:2px;
    classDef external fill:#ffebcc,stroke:#cc6600,stroke-width:2px;
    classDef libs fill:#e6ccff,stroke:#660099,stroke-width:2px;

    %% Assign Classes
    class BS1,BS2,BS3 build;
    class UI1,UI2,UI3 ui;
    class COMM1,COMM2,COMM3 comm;
    class DATA1,DATA2,DATA3,DATA4 config;
    class EXT1,EXT2,EXT3,EXT4 external;
    class LIB1,LIB2,LIB3,LIB4 libs;

    %% Click Events
    click BS1 "https://github.com/inavflight/inav-configurator/blob/master/forge.config.js"
    click BS2 "https://github.com/inavflight/inav-configurator/blob/master/package.json"
    click BS3 "https://github.com/inavflight/inav-configurator/tree/master/.github/workflows"
    click UI1 "https://github.com/inavflight/inav-configurator/blob/master/index.html"
    click UI2 "https://github.com/inavflight/inav-configurator/tree/master/tabs"
    click UI3 "https://github.com/inavflight/inav-configurator/tree/master/src/css"
    click COMM1 "https://github.com/inavflight/inav-configurator/tree/master/js/connection"
    click COMM2 "https://github.com/inavflight/inav-configurator/tree/master/js/protocols"
    click COMM3 "https://github.com/inavflight/inav-configurator/tree/master/js/msp"
    click DATA1 "https://github.com/inavflight/inav-configurator/blob/master/js/configurator_main.js"
    click DATA2 "https://github.com/inavflight/inav-configurator/blob/master/js/settings.js"
    click DATA3 "https://github.com/inavflight/inav-configurator/blob/master/js/data_storage.js"
    click DATA4 "https://github.com/inavflight/inav-configurator/blob/master/js/localization.js"
    click EXT1 "https://github.com/inavflight/inav-configurator/blob/master/MAPPROXY.md"
    click EXT2 "https://github.com/inavflight/inav-configurator/tree/master/assets"
    click EXT3 "https://github.com/inavflight/inav-configurator/tree/master/images"
    click EXT4 "https://github.com/inavflight/inav-configurator/tree/master/resources"
    click LIB1 "https://github.com/inavflight/inav-configurator/tree/master/js/libraries"
    click LIB2 "https://github.com/inavflight/inav-configurator/blob/master/js/helpers.js"
    click LIB3 "https://github.com/inavflight/inav-configurator/blob/master/js/debug_trace.js"
    click LIB4 "https://github.com/inavflight/inav-configurator/tree/master/js/workers"
```
