# lwrcs/turnarchist architecture

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

- Interactive diagram: https://gitdiagram.com/lwrcs/turnarchist
- Repository: https://github.com/lwrcs/turnarchist

## Overview

##### Main Components
- Game Engine / Main Loop: The heart of the project is the game loop (game.ts/game.js) that orchestrates all other subsystems.
- Input Manager: Managed by input.ts which processes keyboard/mouse events.
- Renderer / Drawable: Based on files like drawable.ts and the HTML files (index.html, help.html), the game renders visual elements on a canvas or via the DOM.
- Entity Component System: Entities include players, enemies (enemy folder), items (item folder), projectiles (projectile folder), and weapons (weapon folder). Each has its own module, making them clear “component” blocks.
- World / Level Manager: Modules like level.ts, levelConstants.ts, levelGenerator.ts, and map.ts represent the game world structure.
- Tile & Map System: The “tile” modules (both in src and js) indicate the breakdown of the game grid – different tile types like floor, wall, door, etc.
- Particle & Effects System: Files in the “particle” subdirectories handle visual effects such as death particles, dash particles, and text particles.
- Audio / Sound System: The sound.ts file and the “res/SFX” folder point to a dedicated sound and audio management subsystem.
- Resource Manager: Resources in “res” (music, sound effects, images if present) are likely managed/loaded by specific utility functions.
- Build/Deployment Tools: The webpack config, TypeScript configuration, and shell scripts (e.g., dropbox_update.sh) represent the build and deployment pipeline.

##### Relationships and Interactions
- The Game Engine (main loop) is at the center. It imports and calls the Input Manager to handle player actions.
- The Input Manager feeds directly into the Game Engine to update game states.
- The Entity Manager contains player, enemy, and item components. They interact with the World Manager which is defined by level and map modules.
- The Audio System is triggered by game events (collisions, attacks, item pickups), and this flows from the Game Engine to the Sound Manager.
- The Particle System is used for visual feedback and effects during events (enemy death, spell effects, etc.).
- The Build tools ensure that TypeScript source in “src” is correctly transpiled into the “js” distribution used by the HTML files.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The project cleanly distinguishes between game logic, rendering, input handling, and resource management.
- Modular Design: With distinct folders for enemy, item, tile, particle, and weapon, the architecture is broken into well-defined, loosely coupled modules.

##### What
– Game Engine / Main Loop
– Input Manager
– Renderer / Drawable Layer
– Entity Manager (with subcomponents: Player, Enemy, Items, Projectiles, Weapons)
– World / Level Manager and Map/Tile System
– Particle/Effects System
– Audio/Sound System
– Resource/Asset Manager
– Build/Deployment Pipeline (as a supporting component)
- Simple annotations that indicate important actions (e.g., “handles keyboard events”, “renders frame”, “loads assets”).

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Game Core
    subgraph "Game Core"
        GE_TS["Game Engine (TS)"]
        GE_JS["Game Engine (JS)"]
        IM_TS["Input Manager (TS)"]
        IM_JS["Input Manager (JS)"]
    end

    %% Rendering Layer
    subgraph "Rendering"
        R_TS["Renderer (TS)"]
        HTML1["index.html"]
        HTML2["help.html"]
    end

    %% Entity Manager with its Components
    subgraph "Entity Manager"
        EM["Entity Manager"]
        subgraph "Components"
            subgraph "Player"
                P_TS["Player (TS)"]
                P_JS["Player (JS)"]
            end
            subgraph "Enemy"
                E_TS["Enemy (TS)"]
                E_JS["Enemy (JS)"]
            end
            subgraph "Item"
                I_TS["Item (TS)"]
                I_JS["Item (JS)"]
            end
            subgraph "Projectile"
                Pr_TS["Projectile (TS)"]
                Pr_JS["Projectile (JS)"]
            end
            subgraph "Weapon"
                W_TS["Weapon (TS)"]
            end
        end
    end

    %% World & Map Layer
    subgraph "World & Map"
        WM["World Manager"]
        subgraph "Components"
            subgraph "Level Manager"
                L_TS["Level Manager (TS)"]
                L_JS["Level Manager (JS)"]
            end
            subgraph "Map"
                M_TS["Map (TS)"]
                M_JS["Map (JS)"]
            end
            subgraph "Tile System"
                T_TS["Tile System (TS)"]
                T_JS["Tile System (JS)"]
            end
        end
    end

    %% Effects System
    subgraph "Effects"
        PS_TS["Particle System (TS)"]
        PS_JS["Particle System (JS)"]
    end

    %% Audio System
    subgraph "Audio"
        A_TS["Audio (TS)"]
        A_JS["Audio (JS)"]
        SFX["SFX Folder"]
    end

    %% Resources / Assets
    subgraph "Resources"
        Res["Resources (res)"]
    end

    %% Build / Deployment Pipeline
    subgraph "Build/Deployment"
        WP["webpack.config.js"]
        TSConfig["tsconfig.json"]
        DB["dropbox_update.sh"]
        PKG["package.json"]
    end

    %% Relationships & Data Flow
    %% Input Manager feeds Game Engine
    IM_TS --> GE_TS
    IM_JS --> GE_JS

    %% Entity Manager affects Game Engine and Rendering
    EM --> GE_TS
    EM --> R_TS

    %% World & Map informs Game Engine and Rendering
    WM --> GE_TS
    WM --> R_TS

    %% Game Engine drives Rendering, Audio and Effects
    GE_TS --> R_TS
    GE_JS --> R_TS
    GE_TS --> A_TS
    GE_JS --> A_TS
    GE_TS --> PS_TS
    GE_JS --> PS_TS

    %% Build/Deployment pipeline produces distribution files for various modules (using webpack.config.js as representative)
    WP --> GE_JS
    WP --> R_TS
    WP --> P_JS
    WP --> L_JS
    WP --> PS_JS
    WP --> A_JS

    %% Resources supply assets to Rendering
    Res --> R_TS

    %% Click Events
    click GE_TS "https://github.com/lwrcs/turnarchist/blob/master/src/game.ts"
    click GE_JS "https://github.com/lwrcs/turnarchist/blob/master/js/game.js"
    click IM_TS "https://github.com/lwrcs/turnarchist/blob/master/src/input.ts"
    click IM_JS "https://github.com/lwrcs/turnarchist/blob/master/js/input.js"
    click R_TS "https://github.com/lwrcs/turnarchist/blob/master/src/drawable.ts"
    click HTML1 "https://github.com/lwrcs/turnarchist/blob/master/index.html"
    click HTML2 "https://github.com/lwrcs/turnarchist/blob/master/help.html"
    click P_TS "https://github.com/lwrcs/turnarchist/blob/master/src/player.ts"
    click P_JS "https://github.com/lwrcs/turnarchist/blob/master/js/player.js"
    click E_TS "https://github.com/lwrcs/turnarchist/blob/master/src/enemy/enemy.ts"
    click E_JS "https://github.com/lwrcs/turnarchist/blob/master/js/enemy/enemy.js"
    click I_TS "https://github.com/lwrcs/turnarchist/blob/master/src/item/item.ts"
    click I_JS "https://github.com/lwrcs/turnarchist/blob/master/js/item/item.js"
    click Pr_TS "https://github.com/lwrcs/turnarchist/blob/master/src/projectile/projectile.ts"
    click Pr_JS "https://github.com/lwrcs/turnarchist/blob/master/js/projectile/projectile.js"
    click W_TS "https://github.com/lwrcs/turnarchist/blob/master/src/weapon/weapon.ts"
    click L_TS "https://github.com/lwrcs/turnarchist/blob/master/src/level.ts"
    click L_JS "https://github.com/lwrcs/turnarchist/blob/master/js/level.js"
    click M_TS "https://github.com/lwrcs/turnarchist/blob/master/src/map.ts"
    click M_JS "https://github.com/lwrcs/turnarchist/blob/master/js/map.js"
    click T_TS "https://github.com/lwrcs/turnarchist/blob/master/src/tile/tile.ts"
    click T_JS "https://github.com/lwrcs/turnarchist/blob/master/js/tile/tile.js"
    click PS_TS "https://github.com/lwrcs/turnarchist/blob/master/src/particle/particle.ts"
    click PS_JS "https://github.com/lwrcs/turnarchist/blob/master/js/particle/particle.js"
    click A_TS "https://github.com/lwrcs/turnarchist/blob/master/src/sound.ts"
    click A_JS "https://github.com/lwrcs/turnarchist/blob/master/js/sound.js"
    click SFX "https://github.com/lwrcs/turnarchist/tree/master/res/SFX"
    click Res "https://github.com/lwrcs/turnarchist/tree/master/res"
    click WP "https://github.com/lwrcs/turnarchist/blob/master/webpack.config.js"
    click TSConfig "https://github.com/lwrcs/turnarchist/blob/master/tsconfig.json"
    click DB "https://github.com/lwrcs/turnarchist/blob/master/dropbox_update.sh"
    click PKG "https://github.com/lwrcs/turnarchist/blob/master/package.json"

    %% Styles
    classDef gameCore fill:#f8b400,stroke:#333,stroke-width:2px;
    classDef rendering fill:#8bc34a,stroke:#333,stroke-width:2px;
    classDef entity fill:#03a9f4,stroke:#333,stroke-width:2px;
    classDef world fill:#ffeb3b,stroke:#333,stroke-width:2px;
    classDef effects fill:#e91e63,stroke:#333,stroke-width:2px;
    classDef audio fill:#9c27b0,stroke:#333,stroke-width:2px;
    classDef resources fill:#ff5722,stroke:#333,stroke-width:2px;
    classDef build fill:#607d8b,stroke:#333,stroke-width:2px;

    %% Apply Classes
    class GE_TS,GE_JS,IM_TS,IM_JS gameCore;
    class R_TS,HTML1,HTML2 rendering;
    class EM,P_TS,P_JS,E_TS,E_JS,I_TS,I_JS,Pr_TS,Pr_JS,W_TS entity;
    class WM,L_TS,L_JS,M_TS,M_JS,T_TS,T_JS world;
    class PS_TS,PS_JS effects;
    class A_TS,A_JS,SFX audio;
    class Res resources;
    class WP,TSConfig,DB,PKG build;
```
