# tomaisthorpe/tedengine architecture

> Architecture diagram of the GitHub repository tomaisthorpe/tedengine, 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/tomaisthorpe/tedengine
- Repository: https://github.com/tomaisthorpe/tedengine

## Overview

##### Main Components

The system architecture should be divided into these major subsystems:

a. Core Engine Components:
- Core System (Actor, World, GameState management)
- Resource Management
- Event System
- Job Management

b. Graphics Pipeline:
- Renderer
- Shaders
- Graphics Components (Mesh, Texture, Materials)
- Canvas Management

c. Physics System:
- Physics World
- Colliders
- Worker-based Physics Processing

d. Input/Output Systems:
- Input Management (Keyboard, Mouse, Touch)
- Audio System
- Debug System

e. Scene Management:
- Actor Components
- Camera System
- Transform System

##### Relationship Flows

**[Core Engine Layer]**
- ↑↓
**[Graphics Pipeline] ←→ [Physics System]**
- ↑↓               ↑↓
**[Scene Management] ←→ [Input/Output]**
- ↑↓
**[UI Layer / Debug Tools]**

##### Specific Implementation Details

- Rounded rectangles for subsystems
- Hexagons for workers/async processes
- Diamonds for resource managers
- Circles for event handlers

- Blue: Core engine components
- Green: Graphics-related systems
- Red: Physics systems
- Yellow: Input/Output systems
- Purple: Debug/Development tools

##### Important Architectural Patterns to Highlight

- Component-based architecture (Actor Components)
- Event-driven communication (EventQueue)
- Worker-based physics processing
- Resource management system
- Job management system

##### Technical Details

Annotations for:
- WebGL rendering pipeline
- Physics worker communication
- Resource loading flow
- Event propagation paths
- Debug panel integration

##### Integration Points

Integration with:
- React-based UI components
- WebGL context
- Web Workers
- Browser APIs (Audio, Input)

##### The debug/development tools integration

This architecture should reflect the engine's focus on game jam development and learning purposes, while showing the professional structure of the various subsystems.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Core
        Actor["Actor System"]:::core
        World["World Management"]:::core
        Event["Event System"]:::core
        Resource["Resource Management"]:::diamond
        GameState["Game State Management"]:::core
        JobManager["Job Management"]:::core
    end

    subgraph Graphics
        Renderer["Renderer"]:::graphics
        Shaders["Shaders"]:::graphics
        GraphicsComp["Graphics Components"]:::graphics
        Materials["Materials"]:::graphics
        Canvas["Canvas"]:::graphics
    end

    subgraph Physics
        PhysicsWorld["Physics World"]:::physics
        Colliders["Colliders"]:::physics
        PhysicsWorker["Physics Worker"]:::worker
    end

    subgraph IO
        Input["Input Management"]:::io
        Keyboard["Keyboard Input"]:::io
        Mouse["Mouse Input"]:::io
        Touch["Touch Input"]:::io
        Audio["Audio System"]:::io
        Debug["Debug System"]:::debug
    end

    subgraph Scene
        Components["Actor Components"]:::scene
        Camera["Camera System"]:::scene
        Transform["Transform System"]:::scene
    end

    subgraph UI
        UIComponents["UI Components"]:::ui
        DebugPanel["Debug Panels"]:::ui
        GameControls["Game Controls"]:::ui
    end

    %% Core relationships
    Actor --> World
    World --> Event
    Event --> Resource
    Resource --> GameState
    JobManager --> World

    %% Graphics relationships
    Renderer --> Canvas
    Renderer --> Shaders
    Renderer --> Materials
    GraphicsComp --> Materials

    %% Physics relationships
    PhysicsWorld --> PhysicsWorker
    PhysicsWorld --> Colliders
    PhysicsWorker --> World

    %% Input relationships
    Input --> Keyboard
    Input --> Mouse
    Input --> Touch
    Input --> World

    %% Scene relationships
    Components --> Transform
    Camera --> Transform
    Scene --> World

    %% UI relationships
    Debug --> DebugPanel
    DebugPanel --> UIComponents
    GameControls --> UIComponents

    %% Cross-system relationships
    World --> Renderer
    World --> PhysicsWorld
    World --> Scene
    Scene --> Graphics
    Debug --> Core

    %% Click events
    click Actor "https://github.com/tomaisthorpe/tedengine/blob/main/packages/ted/src/core/actor.ts"
    click World "https://github.com/tomaisthorpe/tedengine/blob/main/packages/ted/src/core/world.ts"
    click Event "https://github.com/tomaisthorpe/tedengine/blob/main/packages/ted/src/core/event-queue.ts"
    click Resource "https://github.com/tomaisthorpe/tedengine/blob/main/packages/ted/src/core/resource-manager.ts"
    click GameState "https://github.com/tomaisthorpe/tedengine/blob/main/packages/ted/src/core/game-state-manager.ts"
    click JobManager "https://github.com/tomaisthorpe/tedengine/blob/main/packages/ted/src/jobs/job-manager.ts"
    click Renderer "https://github.com/tomaisthorpe/tedengine/blob/main/packages/ted/src/renderer/renderer.ts"
    click Shaders "https://github.com/tomaisthorpe/tedengine/tree/main/packages/ted/src/shaders/"
    click GraphicsComp "https://github.com/tomaisthorpe/tedengine/tree/main/packages/ted/src/graphics/"
    click Materials "https://github.com/tomaisthorpe/tedengine/blob/main/packages/ted/src/graphics/material.ts"
    click Canvas "https://github.com/tomaisthorpe/tedengine/blob/main/packages/ted/src/graphics/canvas.ts"
    click PhysicsWorld "https://github.com/tomaisthorpe/tedengine/blob/main/packages/ted/src/physics/physics-world.ts"
    click Colliders "https://github.com/tomaisthorpe/tedengine/tree/main/packages/ted/src/physics/colliders/"
    click PhysicsWorker "https://github.com/tomaisthorpe/tedengine/blob/main/packages/ted/src/physics/worker.ts"
    click Keyboard "https://github.com/tomaisthorpe/tedengine/blob/main/packages/ted/src/input/keyboard.ts"
    click Mouse "https://github.com/tomaisthorpe/tedengine/blob/main/packages/ted/src/input/mouse.ts"
    click Touch "https://github.com/tomaisthorpe/tedengine/blob/main/packages/ted/src/input/touch.ts"
    click Audio "https://github.com/tomaisthorpe/tedengine/blob/main/packages/ted/src/audio/audio.ts"
    click Debug "https://github.com/tomaisthorpe/tedengine/blob/main/packages/ted/src/debug/debug-panel.ts"
    click Components "https://github.com/tomaisthorpe/tedengine/tree/main/packages/ted/src/actor-components/"
    click Camera "https://github.com/tomaisthorpe/tedengine/tree/main/packages/ted/src/cameras/"
    click Transform "https://github.com/tomaisthorpe/tedengine/blob/main/packages/ted/src/math/transform.ts"
    click UIComponents "https://github.com/tomaisthorpe/tedengine/tree/main/packages/ted/src/ui/components/"
    click DebugPanel "https://github.com/tomaisthorpe/tedengine/blob/main/packages/ted/src/ui/components/DebugPanel.tsx"
    click GameControls "https://github.com/tomaisthorpe/tedengine/blob/main/packages/ted/src/ui/components/GameControls.tsx"

    %% Styles
    classDef core fill:#3498db
    classDef graphics fill:#2ecc71
    classDef physics fill:#e74c3c
    classDef io fill:#f1c40f
    classDef scene fill:#9b59b6
    classDef ui fill:#1abc9c
    classDef debug fill:#95a5a6
    classDef worker fill:#e67e22
    classDef diamond fill:#34495e
```
