# ron0studios/orbitsim architecture

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

- Interactive diagram: https://gitdiagram.com/ron0studios/orbitsim
- Repository: https://github.com/ron0studios/orbitsim

## Overview

##### Project type and purpose
- OrbitSim is a native C++ desktop application for simulating and visualizing N-body gravitational systems using the Barnes-Hut treecode.
- It integrates a multithreaded simulation core with a real-time GUI and rendering engine based on ImGui and SFML/OpenGL.

##### File structure
- Top-level “src” contains the simulation engine (Simulator.cpp/.h), data structures (Body, QuadTree), shaders (fragment.frag, shader.frag), threading header (ctpl.h), and the application entry point (main.cpp).
- “cmake_modules” and CMakeLists.txt define a cross-platform build, pulling in dependencies like ImGui-SFML and SFML.
- Runtime assets and settings (imgui.ini) and build/ dependency folders reflect the use of CMake with external-project/subbuild for ImGui and SFML.

##### README insights
- The README emphasizes the Barnes-Hut algorithm, a linear/quadtree storage for speed, multithreading for force updates, and ImGui-SFML for the GUI overlay.

## Diagram (Mermaid)

```mermaid
flowchart TD
    main["Application Launcher\n(main)"] 
    subgraph "Simulation Engine"
        BM["Body Manager\n(Body objects)"]:::compute
        QT["Barnes-Hut Tree Builder\n(QuadTree)"]:::compute
        PU["Physics Updater\n(force calc & timestep)"]:::compute
        TP["Thread Pool\n(ctpl)"]:::compute
    end
    subgraph "Rendering Subsystem"
        SFML["SFML Window & Context"]:::render
        Shader["OpenGL Shader Pipeline"]:::render
    end
    subgraph "GUI Layer"
        IMGUI["ImGui Context & Widgets"]:::ui
        Controls["User Controls"]:::ui
    end
    subgraph "External Dependencies"
        IMGSFML["ImGui-SFML"]:::external
        SFMLLib["SFML Libraries"]:::external
        GD["Global Definitions & Config"]:::external
        Build["Build Orchestration\n(CMake)"]:::external
    end

    main -->|initializes| BM
    main -->|initializes| PU
    main -->|initializes| SFML
    main -->|initializes| IMGUI
    Controls -->|commands| PU
    PU -->|dispatch jobs| TP
    TP -->|build tree| QT
    QT -->|compute forces| PU
    PU -->|update bodies| BM
    BM -->|body data| SFML
    SFML -->|render call| Shader
    Shader -->|draws scene| SFML
    SFML -->|frame ready| IMGUI
    IMGUI -->|overlay widgets| SFML
    IMGSFML -->|provides| IMGUI
    SFMLLib -->|provides| SFML
    Build -->|configures| main
    GD -->|used by| PU

    click main "https://github.com/ron0studios/orbitsim/blob/main/src/main.cpp"
    click BM "https://github.com/ron0studios/orbitsim/blob/main/src/Body.cpp"
    click QT "https://github.com/ron0studios/orbitsim/blob/main/src/QuadTree.cpp"
    click PU "https://github.com/ron0studios/orbitsim/blob/main/src/Simulator.cpp"
    click TP "https://github.com/ron0studios/orbitsim/blob/main/src/ctpl.h"
    click Shader "https://github.com/ron0studios/orbitsim/blob/main/src/fragment.frag"
    click GD "https://github.com/ron0studios/orbitsim/blob/main/src/globals.h"
    click Build "https://github.com/ron0studios/orbitsim/blob/main/CMakeLists.txt"

    classDef compute fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef render fill:#90EE90,stroke:#000,stroke-width:1px
    classDef ui fill:#FFA500,stroke:#000,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px
```
