# stickyfingies/grove architecture

> Architecture diagram of the GitHub repository stickyfingies/grove, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/stickyfingies/grove
- Repository: https://github.com/stickyfingies/grove

## Overview

##### Main Components

a) Core Engine Layer:
- ECS (Entity Component System)
- Graphics Engine (Three.js)
- Physics Engine (Bullet)
- Asset Loading System

b) Threading Architecture:
- Main Thread (Scene Graph Management)
- Render Thread (WebGL/Three.js)
- Physics Thread (Bullet Engine)

c) Game Systems:
- Game Scripts
- Entity Management
- Asset Management
- User Interface
- Input Handling

**┌─ Game Layer ──────────────────────────┐**
- Game Scripts                        │
- Entity Behaviors                    │
- UI Components                       │
- ┬─────────────────────────┘

**┌──────────────▼─────────────────────────┐**
- Engine Core                            │
- ┌─────────────┐ ┌────────────┐        │
- ECS World │ │Asset Loader│        │
- ┘ └────────────┘        │
- ┬─────────────────────────┘

**┌──────────────▼─────────────────────────┐**
- Parallel Processing Layer              │
- ┌─────────┐ ┌─────────┐ ┌───────────┐ │
- Main   │ │ Render  │ │ Physics   │ │
- Thread  │ │ Thread  │ │ Thread    │ │
- ┘ └─────────┘ └───────────┘ │
- ┘

##### Communication Flows

- Shared memory communication between threads
- Entity component updates
- Asset loading pipelines
- Input handling flow
- Scene graph updates

##### Important Details to Highlight

a) Thread Communication:
- Shared memory buffers
- WASM boundaries
- Write-once read-many data flows

b) ECS Architecture:
- Component storage
- System execution order
- Entity lifecycle management

c) Asset Pipeline:
- glTF loading process
- Resource management
- Memory allocation

##### Implementation Notes

- Thread synchronization mechanisms
- Memory management strategies
- Performance optimization points
- System initialization sequence

##### Technology Stack Indicators

Areas utilizing:
- Three.js (Graphics)
- TypeScript
- WebGL
- WebAssembly
- Shared Array Buffers

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Game_Layer
        GameScripts["Game Scripts"]:::game
        EntityBehaviors["Entity Behaviors"]:::game
        UIComponents["User Interface"]:::game
        InputHandling["Input Handling"]:::game
        Movement["Movement System"]:::game
        Combat["Combat System"]:::game
        Health["Health System"]:::game
    end

    subgraph Engine_Core
        ECSWorld["ECS World"]:::core
        AssetLoader["Asset Loading System"]:::core
        SceneManager["Scene Management"]:::core
        CoreEngine["Core Engine"]:::core
    end

    subgraph Parallel_Processing
        MainThread["Main Thread"]:::thread
        RenderThread["Render Thread"]:::thread
        PhysicsThread["Physics Thread"]:::thread
    end

    %% Connections between layers
    GameScripts --> ECSWorld
    EntityBehaviors --> ECSWorld
    UIComponents --> CoreEngine
    InputHandling --> CoreEngine
    Movement --> ECSWorld
    Combat --> ECSWorld
    Health --> ECSWorld

    ECSWorld --> MainThread
    AssetLoader --> MainThread
    SceneManager --> MainThread
    CoreEngine --> MainThread

    MainThread <--> RenderThread
    MainThread <--> PhysicsThread

    %% Shared Memory and Communication
    SharedMemory{{"Shared Memory Buffer"}}:::memory
    MainThread <--> SharedMemory
    RenderThread <--> SharedMemory
    PhysicsThread <--> SharedMemory

    %% Styling
    classDef core fill:#2374ab
    classDef game fill:#57a773
    classDef thread fill:#ffc857
    classDef memory fill:#ed254e

    %% Click events
    click ECSWorld "https://github.com/stickyfingies/grove/blob/master/src/ecs/src/entity-manager.ts"
    click RenderThread "https://github.com/stickyfingies/grove/blob/master/src/graphics/src/worker.ts"
    click PhysicsThread "https://github.com/stickyfingies/grove/blob/master/src/physics/src/worker.ts"
    click MainThread "https://github.com/stickyfingies/grove/blob/master/src/grove/src/main.ts"
    click AssetLoader "https://github.com/stickyfingies/grove/blob/master/src/grove/src/game/load.ts"
    click UIComponents "https://github.com/stickyfingies/grove/blob/master/src/grove/src/game/userInterface.ts"
    click InputHandling "https://github.com/stickyfingies/grove/blob/master/src/grove/src/game/keyboardControls.ts"
    click Movement "https://github.com/stickyfingies/grove/blob/master/src/grove/src/game/movement.ts"
    click Combat "https://github.com/stickyfingies/grove/blob/master/src/grove/src/game/attack.ts"
    click Health "https://github.com/stickyfingies/grove/blob/master/src/grove/src/game/health.ts"
    click SceneManager "https://github.com/stickyfingies/grove/blob/master/src/grove/src/game/scene.ts"
    click CoreEngine "https://github.com/stickyfingies/grove/blob/master/src/engine/src/engine.ts"
```
