# adnyropast/nss architecture

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

- Interactive diagram: https://gitdiagram.com/adnyropast/nss
- Repository: https://github.com/adnyropast/nss

## Overview

##### Main Components
- Game Loop & Entry Points:
- Files like index.js, gameStart.js, and gameloops.js serve as entry points and the main loop controller.
- User Input & Controls:
- Game Entities and Actions:
- The entities folder (e.g., PlayableCharacter.js, Enemy.js, Dummy.js) represents the game’s actors.
- The actions directory encapsulates various actions (Jump, Movement, Teleport, etc.) that modify the state or behavior of these entities.
- Rendering & Drawable Components:
- Physics & Interactions:
- The interactions folder includes multiple interaction patterns (AirStateGranter/Receiver, GravityActor/Recipient, etc.) that manage collisions, movement, and physics effects.
- Battle System:
- The battle directory (Battler.js, Move.js) handles the turn-based battle elements described in the README.
- World/Level Data:
- The chapters and maps directories hold level-specific logic and map data (.ttt files) to represent different environments or chapters.
- Utility and Core Framework:
- Assets:
- The images directory organizes all graphical assets like backgrounds, characters, and item images.

##### Establish Relationships and Interactions
- The core loop (index.js, gameStart.js, gameloops.js) initiates the game, manages update cycles, and directs input events.
- Input from the user (via draft-menu.js and control scripts) is received, then forwarded to update actions (in the actions folder) that affect game entities.
- Entities (in the entities directory) are updated based on both player input and automated interactions (from files in the interactions folder) such as physics responses (gravity, collision, etc.).
- When a battle is triggered, control shifts to the battle module where Battler.js and Move.js orchestrate turn-based combat mechanics.
- Utility libraries provide shared functionality across components (scaling, event handling, etc.), ensuring consistency and keeping the code DRY.

##### Architectural Patterns and Design Principles
- Modularization: The system is segmented into clear domains (actions, entities, rendering, interactions), each encapsulated in its own directory.
- Separation of Concerns: Input, game logic, rendering, and physics interactions are maintained in separate modules.
- Event-Driven Updates: The use of events and imp interfaces in the util/imps directory suggests an event-driven architecture for object updates and inter-component communication.

##### Relevant Technologies and Libraries
- JavaScript is the primary language with node package manifest (package.json) indicating common libraries and build scripts.
- Use of CSS (nss.css) and image assets for visual presentation.
- Potential handling of custom file formats (e.g., .ttt maps) to manage level definitions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Subgraph: Game Loop & Entry Points
    subgraph "Game Loop & Entry Points"
        GL["Game Loop Controller"]:::core
        index["index.js"]:::core
        gs["gameStart.js"]:::core
        gloops["gameloops.js"]:::core
        GL --> index
        GL --> gs
        GL --> gloops
    end

    %% Subgraph: User Input & Controls
    subgraph "User Input & Controls"
        UI["User Input & Controls"]:::input
        dcontrollers["draft-controllers.js"]:::input
        dcontrols["draft-controls.js"]:::input
        dmenu["draft-menu.js"]:::input
        UI --> dcontrollers
        UI --> dcontrols
        UI --> dmenu
    end

    %% Subgraph: Game Entities and Actions
    subgraph "Game Entities & Actions"
        GE["Game Entities & Actions"]:::entities
        pc["PlayableCharacter.js"]:::entities
        enemy["Enemy.js"]:::entities
        dummy["Dummy.js"]:::entities
        act["Actions (directory)"]:::entities
        GE --> pc
        GE --> enemy
        GE --> dummy
        GE --> act
    end

    %% Subgraph: Physics & Interactions
    subgraph "Physics & Interactions"
        PI["Physics & Interactions"]:::physics
        inter["Interactions (directory)"]:::physics
        PI --> inter
    end

    %% Subgraph: Rendering System
    subgraph "Rendering & Drawable Components"
        RS["Rendering System"]:::render
        draw["Drawables (directory)"]:::render
        view["View (directory)"]:::render
        RS --> draw
        RS --> view
    end

    %% Subgraph: Battle System
    subgraph "Battle System"
        BS["Battle System"]:::battle
        battler["Battler.js"]:::battle
        move["Move.js"]:::battle
        BS --> battler
        BS --> move
    end

    %% Subgraph: World/Level Data
    subgraph "World/Level Data"
        WL["World/Level Data"]:::world
        chapters["Chapters (directory)"]:::world
        maps["Maps (directory)"]:::world
        WL --> chapters
        WL --> maps
    end

    %% Subgraph: Utility & Core Framework
    subgraph "Utility & Core Framework"
        UT["Utility & Core Framework"]:::utility
        util["Utility (directory)"]:::utility
        shapes["Shapes (directory)"]:::utility
        UT --> util
        UT --> shapes
    end

    %% Subgraph: Assets
    subgraph "Assets"
        AS["Assets"]:::assets
        images["Images (directory)"]:::assets
        css["nss.css"]:::assets
        AS --> images
        AS --> css
    end

    %% Establish Relationships Between Major Components (Vertical Flow)
    GL -->|"triggers"| UI
    GL -->|"initiates"| GE
    UI -->|"sends input to"| GE
    GE <-->|"physics updates"| PI
    GE -->|"renders state"| RS
    GE -->|"battle trigger"| BS
    WL -->|"configures"| GE
    
    %% Utility supports all modules (dotted arrows)
    UT ---|"supports"| GL
    UT ---|"supports"| UI
    UT ---|"supports"| GE
    UT ---|"supports"| PI
    UT ---|"supports"| RS
    UT ---|"supports"| BS
    UT ---|"supports"| WL

    %% Assets provide visual resources to Rendering System
    AS -->|"assets feed"| RS

    %% Class Definitions for Color Coding
    classDef core fill:#ffccaa,stroke:#cc6600,stroke-width:2px;
    classDef input fill:#ccffcc,stroke:#339933,stroke-width:2px;
    classDef entities fill:#cce5ff,stroke:#005cbf,stroke-width:2px;
    classDef physics fill:#ffe6cc,stroke:#ff9933,stroke-width:2px;
    classDef render fill:#e6ccff,stroke:#a64dff,stroke-width:2px;
    classDef battle fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef world fill:#ccffff,stroke:#009999,stroke-width:2px;
    classDef utility fill:#f2f2f2,stroke:#999999,stroke-width:2px;
    classDef assets fill:#ffffcc,stroke:#cccc00,stroke-width:2px;

    %% Click Events for Game Loop & Entry Points
    click index "https://github.com/adnyropast/nss/blob/master/index.js"
    click gs "https://github.com/adnyropast/nss/blob/master/gameStart.js"
    click gloops "https://github.com/adnyropast/nss/blob/master/gameloops.js"

    %% Click Events for User Input & Controls
    click dcontrollers "https://github.com/adnyropast/nss/blob/master/draft-controllers.js"
    click dcontrols "https://github.com/adnyropast/nss/blob/master/draft-controls.js"
    click dmenu "https://github.com/adnyropast/nss/blob/master/draft-menu.js"

    %% Click Events for Game Entities and Actions
    click pc "https://github.com/adnyropast/nss/blob/master/entities/PlayableCharacter.js"
    click enemy "https://github.com/adnyropast/nss/blob/master/entities/Enemy.js"
    click dummy "https://github.com/adnyropast/nss/blob/master/entities/Dummy.js"
    click act "https://github.com/adnyropast/nss/tree/master/actions/"

    %% Click Events for Physics & Interactions
    click inter "https://github.com/adnyropast/nss/tree/master/interactions/"

    %% Click Events for Rendering & Drawable Components
    click draw "https://github.com/adnyropast/nss/tree/master/drawables/"
    click view "https://github.com/adnyropast/nss/tree/master/view/"

    %% Click Events for Battle System
    click battler "https://github.com/adnyropast/nss/blob/master/battle/Battler.js"
    click move "https://github.com/adnyropast/nss/blob/master/battle/Move.js"

    %% Click Events for World/Level Data
    click chapters "https://github.com/adnyropast/nss/tree/master/chapters/"
    click maps "https://github.com/adnyropast/nss/tree/master/maps/"

    %% Click Events for Utility & Core Framework
    click util "https://github.com/adnyropast/nss/tree/master/util/"
    click shapes "https://github.com/adnyropast/nss/tree/master/shapes/"

    %% Click Events for Assets
    click images "https://github.com/adnyropast/nss/tree/master/images/"
    click css "https://github.com/adnyropast/nss/blob/master/nss.css"
```
