# a327ex/snkrx architecture

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

- Interactive diagram: https://gitdiagram.com/a327ex/snkrx
- Repository: https://github.com/a327ex/snkrx

## Overview

##### Main Components
- Game Engine Core – This is housed primarily in the “engine” directory with its multiple submodules:
- Datastructures (graph, grid, string, table): used for handling internal data representations.
- Game logic (engine/game): handles flashes, game objects, physics, triggers, input, and state management.
- Graphics (engine/graphics): manages animation, camera, canvas, fonts, images, shaders, and tile sets.
- Math (engine/math): provides vector math, collision detection, randomization, and other geometric functions.
- External Libraries (engine/external): includes third-party tools (e.g., binser, clipper, mlib, ripple) that extend functionality.
- Management (engine/map): responsible for tilemaps and solid object definitions.
- Sound and System modules: control audio (engine/sound.lua) and overall system interactions.

- Game Bootstrap & Configuration:
- main.lua, conf.lua, and shared.lua are the entrypoints that initialize the game and global settings.
- arena.lua, buy_screen.lua, mainmenu.lua, enemies.lua, objects.lua, and player.lua are higher-level scripts orchestrating particular game scenarios and game object behaviors.

- Assets:
- All resource files (images, fonts, maps, shaders, sounds, media) found under the “assets” directory. They support the visual, audio, and environmental components of the game.

- Build & Deployment:
- Build scripts (build.sh, run.sh) and the “builds” directory (with platform-specific files for Windows) indicate how the project is built and packaged.
- engine/love contains platform-specific binaries and build scripts for deploying via the LÖVE framework.

##### Relationships and Interactions Between Components
- The LÖVE framework initializes via main.lua/conf.lua, which then boots up the custom engine.
- The engine’s core modules (graphics, game, math, etc.) interact to perform the game loop:
- Input from the user is processed via engine/game/input.lua.
- Game state changes flow from engine/game/state.lua and relate to object management (object.lua, gameobject.lua, group.lua, etc.).
- Physics and collisions are computed through engine/game/physics.lua (with additional modules like springs.lua and steering.lua).
- Rendering is handled by the graphics modules, which also use shaders defined in assets/shaders.
- The assets are loaded and managed to supply sprites, levels (maps), sounds, and other media.
- The main gameplay logic (arena, enemies, objects, player) ties into the core engine and influences game state, which is then updated and rendered.

##### Architectural Patterns and Design Principles
- Modularity: The engine’s breakdown into distinct directories (game, graphics, math, datastructures, etc.) promotes separation of concerns.
- Data-driven Design: The assets folder and external configuration files (e.g., engine/gamecontrollerdb.txt) indicate that much of the gameplay is defined by data (maps, sounds, shaders) rather than hard-coded values.
- Game Loop: A continuous loop handles input, updates game logic, applies physics, and renders output.
- External Integration: Integration with the LÖVE runtime means that the game is built on a well-established 2D game framework, leveraging its event-driven model.

##### Relevant Technologies, Frameworks, and Tools
- LÖVE Framework for Lua (as noted in engine/love and the README instructions).
- Custom-developed engine modules that handle game mechanics, physics, graphics, and math.
- A variety of external Lua libraries (binser, clipper, etc.) for extended processing within the game.
- Platform and build tools available via build scripts and platform-specific folders (e.g., builds/windows).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Layer 1: LÖVE Framework / Runtime
    LR["LÖVE Runtime"]:::love

    %% Layer 2: Game Bootstrap & Configuration
    subgraph "Game Bootstrap"
        GB1["main.lua"]:::bootstrap
        GB2["conf.lua"]:::bootstrap
        GB3["shared.lua"]:::bootstrap
    end

    %% Layer 3: Engine Core
    subgraph "Engine Core"
        DS["Datastructures"]:::engine
        GL["Game Logic"]:::engine
        GR["Graphics"]:::engine
        M["Math"]:::engine
        EX["External Libraries"]:::engine
        MM["Map Management"]:::engine
        SND["Sound"]:::engine
        SYS["System"]:::engine
    end

    %% Layer 4: Game Modules
    subgraph "Game Modules"
        A["arena.lua"]:::gamemod
        BS["buy_screen.lua"]:::gamemod
        MN["mainmenu.lua"]:::gamemod
        EN["enemies.lua"]:::gamemod
        OBJ["objects.lua"]:::gamemod
        PL["player.lua"]:::gamemod
    end

    %% Layer 5: Assets & Resources
    subgraph "Assets & Resources"
        AS["Assets"]:::assets
    end

    %% Layer 6: Build & Deployment
    subgraph "Build & Deployment"
        BSH["build.sh"]:::build
        RSH["run.sh"]:::build
        BLD["builds"]:::build
    end

    %% Relationships / Flow
    LR --> GB1
    LR --> GB2
    LR --> GB3

    GB1 --- GL
    GB2 --- GL
    GB3 --- GL

    DS --- GL
    M --- GL
    EX --- GL
    MM --- GL

    GL --> A
    GL --> BS
    GL --> MN
    GL --> EN
    GL --> OBJ
    GL --> PL

    AS --> GR
    AS --> SND

    GR --> GL

    GL --> SND
    GL --> SYS

    BSH --> BLD
    RSH --> BLD

    %% Click Events
    click LR "https://github.com/a327ex/snkrx/tree/master/engine/love"
    click DS "https://github.com/a327ex/snkrx/tree/master/engine/datastructures"
    click GL "https://github.com/a327ex/snkrx/tree/master/engine/game"
    click GR "https://github.com/a327ex/snkrx/tree/master/engine/graphics"
    click M "https://github.com/a327ex/snkrx/tree/master/engine/math"
    click EX "https://github.com/a327ex/snkrx/tree/master/engine/external"
    click MM "https://github.com/a327ex/snkrx/tree/master/engine/map"
    click SND "https://github.com/a327ex/snkrx/blob/master/engine/sound.lua"
    click SYS "https://github.com/a327ex/snkrx/blob/master/engine/system.lua"
    click GB1 "https://github.com/a327ex/snkrx/blob/master/main.lua"
    click GB2 "https://github.com/a327ex/snkrx/blob/master/conf.lua"
    click GB3 "https://github.com/a327ex/snkrx/blob/master/shared.lua"
    click A "https://github.com/a327ex/snkrx/blob/master/arena.lua"
    click BS "https://github.com/a327ex/snkrx/blob/master/buy_screen.lua"
    click MN "https://github.com/a327ex/snkrx/blob/master/mainmenu.lua"
    click EN "https://github.com/a327ex/snkrx/blob/master/enemies.lua"
    click OBJ "https://github.com/a327ex/snkrx/blob/master/objects.lua"
    click PL "https://github.com/a327ex/snkrx/blob/master/player.lua"
    click AS "https://github.com/a327ex/snkrx/tree/master/assets"
    click BSH "https://github.com/a327ex/snkrx/blob/master/build.sh"
    click RSH "https://github.com/a327ex/snkrx/blob/master/run.sh"
    click BLD "https://github.com/a327ex/snkrx/tree/master/builds"

    %% Styles
    classDef love fill:#FFDD57,stroke:#333,stroke-width:2px;
    classDef bootstrap fill:#CDE,stroke:#333,stroke-width:2px;
    classDef engine fill:#A2D5AB,stroke:#333,stroke-width:2px;
    classDef gamemod fill:#FFB347,stroke:#333,stroke-width:2px;
    classDef assets fill:#97C1A9,stroke:#333,stroke-width:2px;
    classDef build fill:#B39EB5,stroke:#333,stroke-width:2px;
```
