# yagestudios/bitecs architecture

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

- Interactive diagram: https://gitdiagram.com/yagestudios/bitecs
- Repository: https://github.com/yagestudios/bitecs

## Overview

##### Main Components

a) Core ECS Components:
- World Manager (World.js)
- Entity Manager (Entity.js)
- Component Manager (Component.js)
- Query System (Query.js)
- System Manager (System.js)

b) Supporting Systems:
- Serialization Layer (Serialize.js)
- Storage Management (Storage.js)
- Utilities (Util.js)

**┌─ Application Layer ─────────────────────┐**
- (User Systems & Components)           │
- ┬───────────────────────┬─┘

**┌───────────────▼───────────────────────▼─┐**
- Core ECS Layer               │
- ┤
- ┌─────────┐  ┌──────────┐  ┌─────────┐ │
- World   │──│ Entity   │──│Component│ │
- ┘  └──────────┘  └─────────┘ │

- ┌─────────┐  ┌──────────┐  ┌─────────┐ │
- Query   │──│ System   │──│ Storage │ │
- ┘  └──────────┘  └─────────┘ │
- ┬───────────────────────┬─┘

**┌───────────────▼───────────────────────▼─┐**
- Infrastructure Layer            │
- (Serialization, TypedArrays)         │
- ┘

##### Important Relationships

a) Data Flow:
- World contains Entities
- Entities reference Components
- Queries filter Entities/Components
- Systems process Query results

b) Key Interactions:
- How TypedArrays are used for component storage
- Query system's relationship with components
- Demonstrate system pipeline flow

##### Implementation Details

Use these symbols and notations:
- Double lines for containment relationships
- Diamond endings for composition relationships

##### Performance Aspects

Performance-critical paths:
- Component data access patterns
- Query execution paths
- System update cycles

##### Additional Elements

- Component type definitions
- System pipeline structure
- Query definition patterns

Remember to:
- Keep the main ECS architecture clear and central
- Data-oriented nature of the design
- Functional and minimal approach
- TypeScript support indicators

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef storage fill:#2ecc71,stroke:#27ae60,color:white
    classDef query fill:#e67e22,stroke:#d35400,color:white
    classDef infra fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef app fill:#9b59b6,stroke:#8e44ad,color:white
    
    %% Application Layer
    subgraph AppLayer["Application Layer"]
        UserSys["User Systems"]
        UserComp["User Components"]
    end

    %% Core ECS Layer
    subgraph CoreLayer["Core ECS Layer"]
        World["World Manager"]:::core
        Entity["Entity Manager"]:::core
        Component["Component Manager"]:::core
        Query["Query System"]:::query
        System["System Manager"]:::core
        Storage["Storage Management"]:::storage
    end

    %% Infrastructure Layer
    subgraph InfraLayer["Infrastructure Layer"]
        Serial["Serialization"]:::infra
        TypeArrays["TypedArrays"]:::infra
        Utils["Utilities"]:::infra
        Constants["Constants"]:::infra
    end

    %% Relationships
    World --> Entity
    World --> Component
    World --> System
    Entity --> Component
    Component --> Storage
    Query --> Entity
    Query --> Component
    System --> Query
    Storage --> TypeArrays
    Serial --> Storage
    
    %% Application Interactions
    UserSys --> System
    UserComp --> Component
    
    %% Infrastructure Support
    Utils --> World
    Utils --> Entity
    Constants --> World
    Constants --> Component

    %% Click Events
    click World "https://github.com/YageStudios/bitECS/blob/master/src/World.js"
    click Entity "https://github.com/YageStudios/bitECS/blob/master/src/Entity.js"
    click Component "https://github.com/YageStudios/bitECS/blob/master/src/Component.js"
    click Query "https://github.com/YageStudios/bitECS/blob/master/src/Query.js"
    click System "https://github.com/YageStudios/bitECS/blob/master/src/System.js"
    click Serial "https://github.com/YageStudios/bitECS/blob/master/src/Serialize.js"
    click Storage "https://github.com/YageStudios/bitECS/blob/master/src/Storage.js"
    click Utils "https://github.com/YageStudios/bitECS/blob/master/src/Util.js"
    click Constants "https://github.com/YageStudios/bitECS/blob/master/src/Constants.js"

    %% Legend
    subgraph Legend["Legend"]
        L1["Core Components"]:::core
        L2["Storage Elements"]:::storage
        L3["Query Components"]:::query
        L4["Infrastructure"]:::infra
        L5["Application"]:::app
    end
```
