# worldwalker2000/sand architecture

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

- Interactive diagram: https://gitdiagram.com/worldwalker2000/sand
- Repository: https://github.com/worldwalker2000/sand

## Overview

##### Project type and purpose
- This is a small desktop “falling sand” simulation game written in C, using the raylib library for windowing, input, and rendering.
- The README confirms it’s a monolithic, real-time physics/rendering application.

##### File structure
- Top level:
- Makefile / build scripts
- LICENSE, .gitignore, README.md
- src/main.c – all logic in a single translation unit
- No separate folders for “engine,” “rendering,” “input,” etc., so the code is currently organized as one combined module.

##### README for additional insights
- Minimal description: “Basic version of those falling sand games written in C with raylib.”

##### Main components
a. Application Core (“main.c”)
b. Physics / Simulation Engine
- Grid or particle system that computes sand movement and interactions
c. Input Manager
- Captures mouse/keyboard via raylib, feeds commands into the simulation (e.g., add new grains)
d. Renderer
e. Resource / Asset Loader (optional)
f. External Library
g. Operating System / GPU (runtime environment)

##### Relationships & interactions
- The Application Core drives the loop:
1) Input Manager reads events from raylib → passes to Simulation
2) Simulation updates particle states
- Data flows in one direction each frame, then loops back.

##### Architectural patterns & design principles
- Game Loop pattern (single-threaded)
- Separation of concerns (input vs. simulation vs. rendering)
- Layered dependency: Core → {Input, Physics, Rendering} → raylib → OS/GPU

##### Technologies & frameworks
- C (compiled with Makefile)
- raylib (external, statically or dynamically linked)
- POSIX/Windows layer (abstracted by raylib)

##### Detailed breakdown to capture all elements
- Application Core (main.c)
- init(): raylib InitWindow(), Setup simulation grid
- loop:
- handleInput(): raylib PollInput() → brush placement
- update(): compute sand physics on a 2D array
- cleanup(): CloseWindow()
- External lib: raylib – window & graphics API
- Runtime: GPU driver, OS windowing

[ App Core (main.c) ]
├─> Input Manager ──(events)──> [Simulation Engine]
├─> Simulation Engine ──(state)──> [Renderer]
└─> [OS/GPU]

## Diagram (Mermaid)

```mermaid
graph TD
    %% Application Core and Internal Modules
    subgraph "Application Core"
        direction TB
        AppCore["Application Core"]:::core
        InputManager["Input Manager"]:::core
        Simulation["Simulation Engine"]:::core
        Renderer["Renderer"]:::core
    end

    %% External Libraries and Runtime
    raylib["raylib Library"]:::external
    OS["OS / GPU"]:::os

    %% Project Files
    subgraph "Project Files"
        direction TB
        Makefile["Makefile"]:::artifact
        README["README.md"]:::artifact
        License["LICENSE"]:::artifact
    end

    %% Connections
    AppCore -->|"init(), loop, cleanup()"| InputManager
    AppCore -->|"init(), loop, cleanup()"| Simulation
    AppCore -->|"init(), loop, cleanup()"| Renderer
    InputManager -->|"events"| Simulation
    Simulation -->|"state"| Renderer
    Renderer -->|"draw calls"| raylib
    raylib -->|"windowing & rendering"| OS

    %% Click Events
    click AppCore "https://github.com/worldwalker2000/sand/blob/main/src/main.c"
    click InputManager "https://github.com/worldwalker2000/sand/blob/main/src/main.c"
    click Simulation "https://github.com/worldwalker2000/sand/blob/main/src/main.c"
    click Renderer "https://github.com/worldwalker2000/sand/blob/main/src/main.c"
    click Makefile "https://github.com/worldwalker2000/sand/tree/main/Makefile"
    click README "https://github.com/worldwalker2000/sand/blob/main/README.md"
    click License "https://github.com/worldwalker2000/sand/tree/main/LICENSE"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef external fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef os fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef artifact fill:#FFFACD,stroke:#000,stroke-width:1px;
```
