# bricksigma/cardioid-simulation architecture

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

- Interactive diagram: https://gitdiagram.com/bricksigma/cardioid-simulation
- Repository: https://github.com/bricksigma/cardioid-simulation

## Overview

##### Project's main aspects
- Type: A small-scale, single-binary desktop simulation application.
- Key technologies: Rust (for overall logic and performance) and Macroquad (for rendering and handling graphical input).

##### File structure as it relates to architecture
- The top-level structure is minimalistic:
- Cargo.toml & Cargo.lock define the project dependencies and build configuration.
- src/main.rs contains the entire application logic – including the event loop, simulation computations, and rendering code.
- images directory holds static assets (screenshots), which might also be useful for documentation or asset loading if the simulation were extended.

##### Break down the main components
a. Main Simulation Loop:
- Represents the heart of the application.
- Includes input handling (keyboard events), simulation logic (calculating cardioid geometry based on parameters), and rendering via Macroquad.
b. Input Manager:
- Feeds update signals into the simulation state.
c. Simulation Engine:
- Computes the cardioid geometry dynamically adjusting the number of divisions and factors.
- Updates of simulation parameters based on user input.
d. Rendering Engine (Macroquad):
- Renders computed simulation states to the screen.
- Manages graphical output and translates simulation data into visuals.
e. Configuration/Build Component:
- Although minimal, Cargo.toml shows dependency configuration and serves as the build instructions guide.

##### Relationships and interactions
- The Input Manager feeds updates into the Simulation Engine.
- The Simulation Engine processes these inputs to update the state of the cardioid simulation.
- The updated state is handed off each frame to the Rendering Engine, which draws the new visual representation.
- A feedback loop continuously runs this process inside the Main Simulation Loop.

##### Architectural patterns
- Event-Driven Loop: The application's loop waits for and responds to events (key presses).
- MVC-Like Separation (conceptually):
- View: Rendering handled by Macroquad.
- Controller: Input handling that adjusts model parameters.
- That while everything is implemented in a single file, understanding these functional separations is key when diagramming the system.

## Diagram (Mermaid)

```mermaid
graph TD
    E["Configuration/Build: Cargo.toml"]:::config
    A["Main Simulation Loop: Runs continuous event-driven process"]:::mainLoop
    B["Input Manager: Handles keyboard events (arrows,Shift,C)"]:::input
    C["Simulation Engine: Computes cardioid geometry"]:::engine
    D["Rendering Engine (Macroquad): Draws simulation on-screen"]:::render

    E -->|"configures"| A
    A -->|"handle_input"| B
    B -->|"process_input"| C
    C -->|"update_simulation"| D
    D -->|"render_frame_feedback"| A

    click A "https://github.com/bricksigma/cardioid-simulation/blob/main/src/main.rs"
    click B "https://github.com/bricksigma/cardioid-simulation/blob/main/src/main.rs"
    click C "https://github.com/bricksigma/cardioid-simulation/blob/main/src/main.rs"
    click D "https://github.com/bricksigma/cardioid-simulation/blob/main/src/main.rs"
    click E "https://github.com/bricksigma/cardioid-simulation/blob/main/Cargo.toml"

    classDef mainLoop fill:#ffcc00,stroke:#000,stroke-width:2px;
    classDef input fill:#66ccff,stroke:#000,stroke-width:2px;
    classDef engine fill:#66ff66,stroke:#000,stroke-width:2px;
    classDef render fill:#cc99ff,stroke:#000,stroke-width:2px;
    classDef config fill:#cccccc,stroke:#000,stroke-width:2px;
```
