# marcvivas/n-body architecture

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

- Interactive diagram: https://gitdiagram.com/marcvivas/n-body
- Repository: https://github.com/marcvivas/n-body

## Overview

##### Main Components
● Command-Line Interface & Argument Parsing:
▸ Represent the entry point (src/main/main.cpp) where the simulation is configured.
▸ The ArgumentsParser reads program arguments (like -v, -i, -n, etc.) to select the simulation version and initialization.

● Simulation Engine:
▸ Include the ParticleSystem and ParticleSimulation components.
▸ Identify the ParticleSolver interface (and its many implementations—for CPU, GPU, hybrid, octree versions) as a plug-in-like module. Split these out (e.g., ParticleSolverBHutCPUHybrid, ParticleSolverGPU, etc.) to show the strategy pattern in use.
▸ Also add ParticleSystemInitializer classes (for ball, cube, disk, etc.) that set initial particle configurations.

● Graphics & Rendering:
▸ Represent the RenderLoop which drives the simulation update and rendering.
▸ Show shader management modules (Abstract Shader, VertexFragmentShader, ComputeShader, etc.) that bridge application logic to OpenGL compute and rendering shader pipelines.

● Data Structures & Algorithms:
▸ Highlight support for spatial data structures like Octree (with variations on CPU and GPU versions) and Grid.
▸ Illustrate additional components such as Bucket, Bloom effects, and the RenderTimer for frame timing.

● External Tools and Testing:
▸ Include a Benchmark module (benchmark/ folder) which runs performance tests and generates plots.
▸ Show the Validation suite (validation/ folder) for unit and integration testing of the simulation algorithms.

##### Relationships and Interactions
● Begin with the “User / CLI” block that sends input parameters to the ArgumentsParser.
● From the ArgumentsParser, branch out into the Simulation Engine where the selected ParticleSolver and ParticleSystemInitializer are instantiated based on user input.
● Optionally, illustrate feedback from the user (i.e., controls for bloom activation, zoom, etc.) feeding into Camera and Input Manager components, which in turn affect the RenderLoop.

##### Architectural Patterns and Design Principles
● Modular Architecture: Emphasize how different algorithms (versions) are isolated via the ParticleSolver interface enabling easy extensibility.
● Separation of Concerns: Clear division between simulation logic (calculations, initialization, solver strategies) and rendering (OpenGL window, shaders, input, and output).
● Strategy Pattern: Show how new versions of simulation solvers and initializers can be added without disrupting the overall architecture (integrated via the ArgumentsParser).
● Parallel Processing: Highlight the use of OpenMP and GPU compute shaders; indicate parallelism in both CPU multithreading and GPU offloading.

##### Final Advice for the Principal Software Engineer
● Be as detailed as possible—list each component and its submodules.
● Don’t shy away from separating even small modules; the finer the separation, the easier it will be to understand how new simulation versions or initializers can be added (as outlined in the README).

## Diagram (Mermaid)

```mermaid
flowchart TD
    U["User/CLI"]:::cli

    subgraph "Command-Line Interface & Argument Parsing"
        A1["Entry Point (main.cpp)"]:::cli
        A2["Arguments Parser"]:::cli
    end

    subgraph "Simulation Engine"
        B1["Particle System"]:::simulation
        B2["Particle Simulation"]:::simulation
        B3["ParticleSolver Interface"]:::simulation
        B4["ParticleSolver Implementations"]:::simulation
        B5["Particle System Initializers"]:::simulation
    end

    subgraph "Graphics & Rendering"
        C1["Render Loop Management"]:::rendering
        C2["Window Management"]:::rendering
        C3["Camera"]:::rendering
        C4["Shader Management"]:::rendering
        C5["Particle Drawing"]:::rendering
    end

    subgraph "Data Structures & Algorithms"
        D1["Octree Support"]:::datastruct
        D2["Grid Support"]:::datastruct
        D3["Bucket Data Structure"]:::datastruct
        D4["Bloom Effects"]:::datastruct
        D5["Frame Timing"]:::datastruct
    end

    subgraph "External Tools & Testing"
        E1["Benchmark Module"]:::testing
        E2["Validation Suite"]:::testing
    end

    %% Relationships
    U -->|"sendsArgs"| A2
    A1 -->|"initializes"| A2
    A2 -->|"configures"| B3
    A2 -->|"initSimulation"| B1
    B3 -->|"selects"| B4
    B3 -->|"initializerSetup"| B5
    B5 -->|"initParticles"| B1
    B1 -->|"simulationData"| B2
    B2 -->|"state"| C1
    B2 -->|"dataBucket"| D3
    B4 -->|"uses"| D1
    B4 -->|"uses"| D2
    C1 -->|"shaderUpdate"| C4
    C4 -->|"render"| C2
    C1 -->|"particleDraw"| C5
    U -->|"controlInput"| C3
    C3 -->|"viewUpdate"| C1
    C1 -->|"timing"| D5
    C4 -->|"bloomEffect"| D4
    E1 -->|"performanceTest"| B2
    E2 -->|"validation"| B2

    %% Click Events
    click A1 "https://github.com/marcvivas/n-body/blob/main/src/main/main.cpp"
    click A2 "https://github.com/marcvivas/n-body/tree/main/src/include/ArgumentsParser/"
    click B1 "https://github.com/marcvivas/n-body/tree/main/src/include/ParticleSystem/"
    click B2 "https://github.com/marcvivas/n-body/tree/main/src/include/ParticleSimulation/"
    click B3 "https://github.com/marcvivas/n-body/blob/main/src/include/ParticleSolver/interface/ParticleSolver.h"
    click B4 "https://github.com/marcvivas/n-body/tree/main/src/include/ParticleSolver/"
    click B5 "https://github.com/marcvivas/n-body/tree/main/src/include/ParticleSystemInitializer/"
    click C1 "https://github.com/marcvivas/n-body/tree/main/src/include/RenderLoop/"
    click C2 "https://github.com/marcvivas/n-body/blob/main/src/include/Window/Window.cpp"
    click C3 "https://github.com/marcvivas/n-body/tree/main/src/include/Camera/"
    click C4 "https://github.com/marcvivas/n-body/tree/main/src/include/Shader/"
    click C5 "https://github.com/marcvivas/n-body/tree/main/src/include/ParticleDrawer/"
    click D1 "https://github.com/marcvivas/n-body/tree/main/src/include/Octree/"
    click D2 "https://github.com/marcvivas/n-body/tree/main/src/include/Grid/"
    click D3 "https://github.com/marcvivas/n-body/tree/main/src/include/Bucket/"
    click D4 "https://github.com/marcvivas/n-body/tree/main/src/include/Bloom/"
    click D5 "https://github.com/marcvivas/n-body/tree/main/src/include/RenderTimer/"
    click E1 "https://github.com/marcvivas/n-body/tree/main/benchmark/"
    click E2 "https://github.com/marcvivas/n-body/tree/main/validation/"

    %% Styles
    classDef cli fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef simulation fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef rendering fill:#FFFACD,stroke:#000,stroke-width:2px;
    classDef datastruct fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef testing fill:#E6E6FA,stroke:#000,stroke-width:2px;
    
    class U,A1,A2 cli;
    class B1,B2,B3,B4,B5 simulation;
    class C1,C2,C3,C4,C5 rendering;
    class D1,D2,D3,D4,D5 datastruct;
    class E1,E2 testing;
```
