# renzaccio/3dsand architecture

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

- Interactive diagram: https://gitdiagram.com/renzaccio/3dsand
- Repository: https://github.com/renzaccio/3dsand
- Video tour (about a minute): https://gitdiagram.com/renzaccio/3dsand/video

## Overview

3DSand is a desktop 3D falling-sand simulation. The main loop handles camera movement and user controls, advances and spawns voxel sand, refreshes visibility, then draws the scene and status UI. The world layer owns voxel storage, movement, visibility, and block counting; camera controls, UI widgets, and small coordinate/counter helpers support it. Raylib and its math/graphics headers provide the framework surface. Source excerpts show the main orchestration and key world behavior, but not every draw or statistics call, so uncertain links are omitted.

Main entry points: [`main.cpp`](https://github.com/renzaccio/3dsand/blob/main/main.cpp) (Simulation loop), [`i3dspace.hpp`](https://github.com/renzaccio/3dsand/blob/main/i3dspace.hpp) (Voxel world), [`include/raylib.h`](https://github.com/renzaccio/3dsand/blob/main/include/raylib.h) (Raylib API), [`camera.hpp`](https://github.com/renzaccio/3dsand/blob/main/camera.hpp) (Camera controls)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application loop"]
  node_main["Simulation loop<br/>[main.cpp]"]
end

subgraph group_simulation["Voxel simulation"]
  node_world["Voxel world<br/>[i3dspace.hpp]"]
  node_blocks["Block types<br/>[blocks.hpp]"]
  node_vector["Grid coordinates<br/>[i3dvector.hpp]"]
end

subgraph group_interaction["Controls and UI"]
  node_camera["Camera controls<br/>[camera.hpp]"]
  node_ui["Button UI<br/>[ui.hpp]"]
  node_counter["Layout counter<br/>[counter.hpp]"]
end

subgraph group_framework["Graphics framework"]
  node_raylib["Raylib API<br/>[raylib.h]"]
  node_raymath["Raymath<br/>[raymath.h]"]
  node_rlgl["RLGL graphics<br/>[rlgl.h]"]
end

node_user(("Player"))

node_user -->|"operates"| node_main
node_main -->|"moves camera"| node_camera
node_main -->|"steps and spawns"| node_world
node_main -->|"checks buttons"| node_ui
node_main -->|"positions text"| node_counter
node_main -->|"draws and polls"| node_raylib
node_world -->|"uses block types"| node_blocks
node_world -->|"uses coordinates"| node_vector
node_world -->|"draws voxels"| node_raylib
node_camera -->|"reads input"| node_raylib
node_camera -->|"uses vector math"| node_raymath
node_ui -->|"draws and tests"| node_raylib
node_vector -->|"uses math types"| node_raymath

click node_main "https://github.com/renzaccio/3dsand/blob/main/main.cpp"
click node_world "https://github.com/renzaccio/3dsand/blob/main/i3dspace.hpp"
click node_blocks "https://github.com/renzaccio/3dsand/blob/main/blocks.hpp"
click node_vector "https://github.com/renzaccio/3dsand/blob/main/i3dvector.hpp"
click node_camera "https://github.com/renzaccio/3dsand/blob/main/camera.hpp"
click node_ui "https://github.com/renzaccio/3dsand/blob/main/ui.hpp"
click node_counter "https://github.com/renzaccio/3dsand/blob/main/counter.hpp"
click node_raylib "https://github.com/renzaccio/3dsand/blob/main/include/raylib.h"
click node_raymath "https://github.com/renzaccio/3dsand/blob/main/include/raymath.h"
click node_rlgl "https://github.com/renzaccio/3dsand/blob/main/include/rlgl.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main toneBlue
class node_world,node_blocks,node_vector toneAmber
class node_camera,node_ui,node_counter toneMint
class node_raylib,node_raymath,node_rlgl toneRose
class node_user toneIndigo
```

## Components

### Application loop

- [Simulation loop](https://github.com/renzaccio/3dsand/blob/main/main.cpp): `main.cpp`

### Voxel simulation

- [Voxel world](https://github.com/renzaccio/3dsand/blob/main/i3dspace.hpp): `i3dspace.hpp`
- [Block types](https://github.com/renzaccio/3dsand/blob/main/blocks.hpp): `blocks.hpp`
- [Grid coordinates](https://github.com/renzaccio/3dsand/blob/main/i3dvector.hpp): `i3dvector.hpp`

### Controls and UI

- [Camera controls](https://github.com/renzaccio/3dsand/blob/main/camera.hpp): `camera.hpp`
- [Button UI](https://github.com/renzaccio/3dsand/blob/main/ui.hpp): `ui.hpp`
- [Layout counter](https://github.com/renzaccio/3dsand/blob/main/counter.hpp): `counter.hpp`

### Graphics framework

- [Raylib API](https://github.com/renzaccio/3dsand/blob/main/include/raylib.h): `include/raylib.h`
- [Raymath](https://github.com/renzaccio/3dsand/blob/main/include/raymath.h): `include/raymath.h`
- [RLGL graphics](https://github.com/renzaccio/3dsand/blob/main/include/rlgl.h): `include/rlgl.h`

### Other components

- **Player**

## Connections

- Player → Simulation loop: operates (evidence: `main.cpp`)
- Simulation loop → Camera controls: moves camera (evidence: `main.cpp`)
- Simulation loop → Voxel world: steps and spawns (evidence: `main.cpp`)
- Simulation loop → Button UI: checks buttons (evidence: `main.cpp`)
- Simulation loop → Layout counter: positions text (evidence: `main.cpp`)
- Simulation loop → Raylib API: draws and polls (evidence: `main.cpp`)
- Voxel world → Block types: uses block types (evidence: `i3dspace.hpp`)
- Voxel world → Grid coordinates: uses coordinates (evidence: `i3dspace.hpp`)
- Voxel world → Raylib API: draws voxels (evidence: `i3dspace.hpp`)
- Camera controls → Raylib API: reads input (evidence: `camera.hpp`)
- Camera controls → Raymath: uses vector math (evidence: `camera.hpp`)
- Button UI → Raylib API: draws and tests (evidence: `ui.hpp`)
- Grid coordinates → Raymath: uses math types (evidence: `i3dvector.hpp`)
