# jolav/roguelike-online architecture

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

- Interactive diagram: https://gitdiagram.com/jolav/roguelike-online
- Repository: https://github.com/jolav/roguelike-online

## Overview

##### Project type and purpose
- This is a full-stack, browser-based roguelike game (“Prologue Online”).
- The client is a lightweight JavaScript/HTML/CSS application under `__prologue_client`.
- The server is a Go-based game engine and HTTP API under `__prologue_server`.
- The `www` folder holds static assets and the production entry point that ties the two together.

##### File structure
A. Top-level folders
- `__prologue_client/` – the front-end game code (controls, rendering, UI panels, HTTP client).
- `__prologue_server/` – the back-end game logic (ECS, action queue, map generator, FOV, HTTP server).
- `www/` – static site output (HTML, images, CSS) for hosting the client.
B. Key subdirectories in the server
- `action/` – definitions of user actions, movement, queueing, tests.
- `ecs/` – entity-component-system manager and component packages (health, position, info).
- `mapa/` – map generation modules (tiles, levels, shelters).
- `lib/` – shared utilities (network responses, math, random, sets).
- configuration (`conf/conf.json`), build scripts (`makefile`), module file (`go.mod`).
C. Key files in the client
- `index.html` – game canvas container.
- `assets/index.css` – styles.
- `controls.js`, `game.js`, `render_ascii.js` – UI and rendering logic.
- `http.js` – REST/JSON wrapper for communicating with the server.

##### Insights from README
- Implements a turn-based system (Prologue 0.13) with history, camera, FOV, AI.
- Client-server handshake, authentication, and seedable reproducible runs.
- Future features: save/load, inventory, lighting, persistence.

##### Detail without over-splitting
- Logical unit: client rendering vs. client input vs. HTTP wrapper.
- Don’t forget the configuration file and possible persistence layers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Browser Client" 
        direction TB
        Entry["Index.html"]:::frontend
        Bootstrap["Client Bootstrap"]:::frontend
        Controls["Controls Module"]:::frontend
        GameLogic["Game Logic"]:::frontend
        HTTPWrapper["HTTP Wrapper"]:::frontend
        ASCIIRenderer["ASCII Renderer"]:::frontend
        Panel["UI Panel"]:::frontend
        AuxLib["Auxiliary Lib"]:::frontend
    end

    %% Static Hosting Layer
    subgraph "Static Asset Host" 
        direction TB
        HTMLHost["www/index.html"]:::static
        CSSAssets["www/assets/"]:::static
        ImagesIcons["www/_public/images & icons"]:::static
        Fallback["404, robots.txt, sitemap"]:::static
    end

    %% Game Server Layer
    subgraph "Game Server (Go)" 
        direction TB
        HTTPAPI["HTTP API Handler"]:::backend
        Auth["Authentication / Run Init"]:::backend
        ActionQueue["Action Queue"]:::backend
        ECSManager["ECS Manager"]:::backend
        MapGen["Map Generator"]:::backend
        FOV["Field of View"]:::backend
        History["Turn History"]:::backend
        RunMgr["Run Lifecycle"]:::backend
        Config["Server Config"]:::backend
        Utils["Shared Utilities"]:::backend
    end

    %% Future Persistence
    Persist(("Future Persistence")):::future

    %% Connections
    Entry -->|"loads assets"| HTMLHost
    HTMLHost -->|serves| Entry
    HTMLHost -->|serves| CSSAssets
    HTMLHost -->|serves| ImagesIcons
    HTMLHost -->|serves| Fallback

    Entry -->|boots| Bootstrap
    Bootstrap --> Controls
    Bootstrap --> GameLogic
    Bootstrap --> ASCIIRenderer
    Bootstrap --> Panel
    Bootstrap --> HTTPWrapper
    Bootstrap --> AuxLib

    HTTPWrapper -->|HTTP/JSON| HTTPAPI
    HTTPAPI --> Auth
    Auth --> ActionQueue
    ActionQueue --> ECSManager
    ECSManager --> MapGen
    ECSManager --> FOV
    ECSManager --> History
    ECSManager --> RunMgr
    Config --- HTTPAPI
    Utils --- HTTPAPI
    Persist -.-> History

    HTTPAPI -->|JSON state| HTTPWrapper
    HTTPWrapper -->|update UI| GameLogic

    %% Click Events
    click Entry "https://github.com/jolav/roguelike-online/blob/main/__prologue_client/index.html"
    click Controls "https://github.com/jolav/roguelike-online/blob/main/__prologue_client/client/controls.js"
    click GameLogic "https://github.com/jolav/roguelike-online/blob/main/__prologue_client/client/game.js"
    click HTTPWrapper "https://github.com/jolav/roguelike-online/blob/main/__prologue_client/client/http.js"
    click ASCIIRenderer "https://github.com/jolav/roguelike-online/blob/main/__prologue_client/client/render_ascii.js"
    click Panel "https://github.com/jolav/roguelike-online/blob/main/__prologue_client/client/panel.js"
    click AuxLib "https://github.com/jolav/roguelike-online/blob/main/__prologue_client/client/lib/aux.js"
    click Bootstrap "https://github.com/jolav/roguelike-online/blob/main/__prologue_client/client/index.js"
    click HTMLHost "https://github.com/jolav/roguelike-online/blob/main/www/index.html"
    click CSSAssets "https://github.com/jolav/roguelike-online/tree/main/www/assets/"
    click ImagesIcons "https://github.com/jolav/roguelike-online/tree/main/www/_public/images"
    click Fallback "https://github.com/jolav/roguelike-online/blob/main/www/404.html"
    click HTTPAPI "https://github.com/jolav/roguelike-online/blob/main/__prologue_server/httpServer.go"
    click Auth "https://github.com/jolav/roguelike-online/blob/main/__prologue_server/clientData.go"
    click ActionQueue "https://github.com/jolav/roguelike-online/blob/main/__prologue_server/action/queue.go"
    click ECSManager "https://github.com/jolav/roguelike-online/blob/main/__prologue_server/ecs/manager.go"
    click MapGen "https://github.com/jolav/roguelike-online/blob/main/__prologue_server/mapa/tile.go"
    click FOV "https://github.com/jolav/roguelike-online/blob/main/__prologue_server/fov.go"
    click History "https://github.com/jolav/roguelike-online/blob/main/__prologue_server/history.go"
    click RunMgr "https://github.com/jolav/roguelike-online/blob/main/__prologue_server/run.go"
    click Config "https://github.com/jolav/roguelike-online/blob/main/__prologue_server/conf/conf.json"
    click Utils "https://github.com/jolav/roguelike-online/blob/main/__prologue_server/lib/network.go"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef backend fill:#d4edda,stroke:#333,stroke-width:1px
    classDef static fill:#e2e3e5,stroke:#333,stroke-width:1px
    classDef future fill:#f8d7da,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
```
