# ninjabrain1/ninjabrain-bot architecture

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

- Interactive diagram: https://gitdiagram.com/ninjabrain1/ninjabrain-bot
- Repository: https://github.com/ninjabrain1/ninjabrain-bot

## Overview

##### Project Type and Purpose
- The project is a full-fledged desktop Java application that provides an accurate stronghold calculator for Minecraft speedrunning. Its purpose is to compute stronghold locations by handling user input (via measuring ender eye angles) and applying triangulation algorithms. It additionally manages adjustments (such as subpixel accuracy), overlays (for OBS), and configurable preferences.
- The README emphasizes features like error correction, calibration of standard deviation, OBS overlay integration, and advanced statistical computations – all indicative of a high-accuracy, performance-critical tool.

##### File Structure
- The project is structured as a Maven Java project with a conventional source tree (src/main/java) under the package “ninjabrainbot.”
- Key directories include:
- /ninjabrainbot/gui: Contains many sub-packages for visual components (frames, panels, components, input fields, labels, splash screens, theme editor, etc.). This clearly represents the user interface layer.
- /ninjabrainbot/event: Contains various event-related classes and interfaces (Observable, IObservableList, Subscription, etc.), which implies an event-driven (observer) architecture.
- /ninjabrainbot/io: Handles input/output operations. It includes sub-packages for clipboard reading, API handling, Minecraft instance interactions, overlay processing, preferences management, and update checking. This indicates external communication and integration with both Minecraft and external services.
- /ninjabrainbot/model: Contains packages for the core logic – actions, data state management (including triangulation mathematics and statistical estimation), domain model, calibration, and input handling – representing the central computational engine of the app.
- /ninjabrainbot/util: Provides utility classes (logging, assertions, coordinate handling, etc.).
- There’s also a rich test suite under src/test covering integration, unit tests, and simulations that validate various components of the system.

##### Key Components and Their Role (
a. Main Application Entry:
– Main.java initiates the system, setting up the necessary components and bootstrapping the application.
b. User Interface (GUI) Layer:
– Several packages under /gui manage everything from frames (windows/dialogs) to UI components (buttons, panels, input fields, labels, splash screens, theme editors).
– This layer is responsible for user interaction, displaying results (e.g., stronghold coordinates and direction), and handling user adjustments (like subpixel refinement).
c. Event Handling and Observer System:
– The event package (with Observable, Subscription, and various interfaces) implements an observer pattern that manages communication between modules. This allows decoupling (for example, UI events updating model state, or model changes updating the GUI).
d. Core Model and Algorithm Engine:
– A large portion of the project lies in the /model directory (actions, data states, domain model, etc.), where the triangulation algorithm and statistical models reside.
– This layer processes the measurements (ender eye throws), applies correctness calibration (via standard deviation settings), and calculates the stronghold position.
e. IO and External Integrations:
– The /io sub-packages are responsible for reading inputs (e.g., F3 + C events, clipboard data, key presses via KeyboardListener), managing preferences (user settings, calibration data), and interacting with APIs (see ApiV1HttpHandler, NinjabrainBotHttpServer).
– Overlay related work (OBS overlay handling) is managed here, facilitating external display features.
f. Preferences and Configuration:
– The project includes dedicated support for user preferences (configuration files, GUI-based settings adjustments) ensuring customizable behavior.
g. Update Checking and External Communications:
– Classes in the updatechecker package periodically check for new versions of the software, ensuring the application remains up-to-date.

##### Relationships and Data Flow
- The GUI layer collects user input (e.g., key presses for calibration, mouse and keyboard events) and then sends these events via the event bus to the core model.
- The CORE MODEL processes these inputs through the triangulation/simulation engine. It then updates its internal state (DataState) which is observed by the GUI (via observable properties).
- IO components feed data into the model (for example, via reading from the clipboard or from a Minecraft instance) and also output results or overlays.
- API components (HTTP server) allow external systems or integrations (such as remote triggers or logging) to interact with the application.
- Preferences are loaded and saved by dedicated IO modules, feeding configuration parameters into GUI and model components.
- The design follows an MVC or observer-based pattern, where state changes in the model instantly propagate to the view, and user actions trigger model updates.

##### Architectural Patterns/Technologies
- Observer Pattern: Evidenced by the event package (IObservable, ISubscribable, ObservableField, etc.), enabling decoupled communication.
- Modular Design: Clearly separates concerns like GUI, IO, model, and event handling.
- MVC or similar: The User Interface (view), Model (data & logic), and Controller (input handling and event dispatch) are all separated.
- Java/Maven conventions and JUnit tests for unit/integration testing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Main Application Bootstrapping (Main.java)"]:::bootstrap
    B["User Interface (GUI)"]:::gui
    C["Event Handling & Observer System"]:::event
    D["Core Model & Calculation Engine"]:::model
    E["IO & External Integrations"]:::io
    F["Preferences & Configuration"]:::prefs
    G["API Server & Queries"]:::update
    H["Update Checker"]:::update
    I["Overlay Integration"]:::update

    A --> B
    A --> C
    A --> D
    A --> E
    B -->|"user_events"| C
    C -->|"dispatch_events"| D
    D -->|"view_updates"| B
    E -->|"data_input"| D
    E -->|"prefs_sync"| F
    F -->|"config_updates"| D
    E -->|"serves_API"| G
    E -->|"checks_updates"| H
    E -->|"manages_overlay"| I

    click A "https://github.com/ninjabrain1/ninjabrain-bot/blob/main/src/main/java/ninjabrainbot/Main.java"
    click B "https://github.com/ninjabrain1/ninjabrain-bot/tree/main/src/main/java/ninjabrainbot/gui"
    click C "https://github.com/ninjabrain1/ninjabrain-bot/tree/main/src/main/java/ninjabrainbot/event"
    click D "https://github.com/ninjabrain1/ninjabrain-bot/tree/main/src/main/java/ninjabrainbot/model"
    click E "https://github.com/ninjabrain1/ninjabrain-bot/tree/main/src/main/java/ninjabrainbot/io"
    click F "https://github.com/ninjabrain1/ninjabrain-bot/tree/main/src/main/java/ninjabrainbot/io/preferences"
    click G "https://github.com/ninjabrain1/ninjabrain-bot/tree/main/src/main/java/ninjabrainbot/io/api"
    click H "https://github.com/ninjabrain1/ninjabrain-bot/tree/main/src/main/java/ninjabrainbot/io/updatechecker"
    click I "https://github.com/ninjabrain1/ninjabrain-bot/tree/main/src/main/java/ninjabrainbot/io/overlay"

    classDef bootstrap fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef gui fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef event fill:#fffacd,stroke:#000,stroke-width:2px;
    classDef model fill:#dda0dd,stroke:#000,stroke-width:2px;
    classDef io fill:#ffcc80,stroke:#000,stroke-width:2px;
    classDef prefs fill:#f08080,stroke:#000,stroke-width:2px;
    classDef update fill:#87cefa,stroke:#000,stroke-width:2px;
```
