# bolknote/gopnik2 architecture

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

- Interactive diagram: https://gitdiagram.com/bolknote/gopnik2
- Repository: https://github.com/bolknote/gopnik2

## Overview

##### Project type and purpose
- This is a monolithic, text-based Hack & Slash RPG written in C++ (“Gopnik-2”).
- It provides a game engine, command interpreter (player actions), hero/enemy modeling, and platform abstraction for Linux/Windows.

##### File structure
- Top-level:
- CMakeLists.txt – build definition with cmake
- src/ – all C++ source code
- / – public headers (gopnik2 API)
- tests/ – unit/integration tests
- Inside src/:
- main.cpp – program entry point, game loop setup
- game.cpp/h – central Game class, loop tick, state manager
- hero.cpp, hero_type.cpp – player and NPC data models
- comm/ – ~80 command handler source files (one per in-game action) + generic command dispatcher (_sv.cpp, _clsc.cpp, etc.)
- pltl/ – custom template/utility library (pltl0-2.cpp)
- utils.cpp – miscellaneous helpers (logging, parsing, RNG)
- /gopnik2/: mirrors src/ layout; platform.h abstracts OS specifics.

##### README for additional insights
- Confirms it is a port of an older text-only RPG, upgraded balance and complexity.
- Build instructions rely on cmake and standard compilers.
- No external services, purely local execution.

a. Main components:
1. Entry Point (main.cpp): initializes configuration, logger, Game instance.
2. Game Engine (Game class): manages game loop, state transitions, difficulty, random encounters.
3. Command Processor:
– Command Dispatcher (in src/comm/_*.cpp)
– Individual Command Handlers (a.cpp, b.cpp, …, z.cpp)
4. Data Models: Hero, HeroType, Inventory, Stats, Enemy, World.
5. Utilities & Platform Abstraction (pltl, utils, platform.h)
6. Build & Test System (CMake, tests/test.cpp)
b. Relationships & interactions:
- main → Game: bootstraps engine
- Game ↔ Command Processor: on each tick, Game passes player input to Dispatcher, which calls a specific Handler
- Handlers → Game/Data Models: modify state (hero stats, inventory, world)
- Game → Output: prints to console, reads input
- Utilities support Game and Commands (randomness, string parsing)
c. Architectural patterns and principles:
- Modular command-handler pattern: decouples parsing and action logic
- Single-responsibility: each .cpp in comm/ addresses one action
- Abstraction layer for platform differences
- Layered structure: entry → core engine → domain logic → utilities
d. Key technologies:
- C++17 (or later), STL
- CMake for build orchestration
- pltl: custom template library
- Standard console I/O

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry Layer
    main["Entry Point\nmain.cpp"]:::entry
    mainH["Entry Header\nmain.h"]:::entry

    %% Presentation Layer
    Presentation["Console I/O"]:::presentation

    %% Core Engine Layer
    Game["Game Engine\nGame Class"]:::core

    %% Command Layer
    subgraph "Command Processor"
        Ae["_ae.cpp"]:::command
        Clsc["_clsc.cpp"]:::command
        Sv["_sv.cpp"]:::command
        commH["comm.h"]:::command
        gop2["gop2_st.h"]:::command
        Handlers["Command Handlers\n(a.cpp…x.cpp)"]:::command
    end

    %% Data Models Layer
    hero["Hero Model"]:::data
    heroType["HeroType Model"]:::data
    list["Generic List"]:::data

    %% Utilities & Platform Layer
    Utils["Utilities"]:::utils
    pl0["pltl0.cpp"]:::utils
    pl1["pltl1.cpp"]:::utils
    pl2["pltl2.cpp"]:::utils
    pltlH["pltl.h"]:::utils
    Platform["Platform Abstraction"]:::utils

    %% Build & Test Pipeline
    CMake["CMakeLists.txt"]:::build
    Binary["Game Binary"]:::build
    Test["tests/test.cpp"]:::build

    %% Connections
    main -->|"initialize"| Game
    mainH --> main

    Game -->|"render()/input()"| Presentation
    Game -->|"loop tick"| Ae
    Game -->|"loop tick"| Clsc
    Game -->|"loop tick"| Sv
    Game -->|"state transition"| Game

    Ae -->|"dispatch()"| Handlers
    Clsc -->|"dispatch()"| Handlers
    Sv -->|"dispatch()"| Handlers
    commH --> Ae
    commH --> Clsc
    commH --> Sv
    gop2 --> Ae
    gop2 --> Clsc
    gop2 --> Sv

    Handlers -->|"execute(command)"| Game
    Handlers -->|"updateState()"| hero
    Handlers -->|"updateState()"| heroType
    Handlers -->|"updateState()"| list

    Utils --> Game
    Utils --> Handlers
    pl0 --> Utils
    pl1 --> Utils
    pl2 --> Utils
    pltlH --> Utils
    Platform --> Game

    CMake -->|"build"| Binary
    Binary -->|"run tests"| Test

    %% Click Events
    click main "https://github.com/bolknote/gopnik2/blob/main/src/main.cpp"
    click mainH "https://github.com/bolknote/gopnik2/blob/main/include/gopnik2/main.h"
    click Ae "https://github.com/bolknote/gopnik2/blob/main/src/comm/_ae.cpp"
    click Clsc "https://github.com/bolknote/gopnik2/blob/main/src/comm/_clsc.cpp"
    click Sv "https://github.com/bolknote/gopnik2/blob/main/src/comm/_sv.cpp"
    click commH "https://github.com/bolknote/gopnik2/blob/main/include/gopnik2/comm/comm.h"
    click gop2 "https://github.com/bolknote/gopnik2/blob/main/include/gopnik2/comm/gop2_st.h"
    click Handlers "https://github.com/bolknote/gopnik2/tree/main/src/comm"
    click hero "https://github.com/bolknote/gopnik2/blob/main/src/hero.cpp"
    click hero "https://github.com/bolknote/gopnik2/blob/main/include/gopnik2/hero.h"
    click heroType "https://github.com/bolknote/gopnik2/blob/main/src/hero_type.cpp"
    click heroType "https://github.com/bolknote/gopnik2/blob/main/include/gopnik2/hero_type.h"
    click list "https://github.com/bolknote/gopnik2/blob/main/src/list.cpp"
    click list "https://github.com/bolknote/gopnik2/blob/main/include/gopnik2/list.h"
    click Utils "https://github.com/bolknote/gopnik2/blob/main/src/utils.cpp"
    click Utils "https://github.com/bolknote/gopnik2/blob/main/include/gopnik2/utils.h"
    click pl0 "https://github.com/bolknote/gopnik2/blob/main/src/pltl/pltl0.cpp"
    click pl1 "https://github.com/bolknote/gopnik2/blob/main/src/pltl/pltl1.cpp"
    click pl2 "https://github.com/bolknote/gopnik2/blob/main/src/pltl/pltl2.cpp"
    click pltlH "https://github.com/bolknote/gopnik2/blob/main/include/gopnik2/pltl/pltl.h"
    click Platform "https://github.com/bolknote/gopnik2/blob/main/include/gopnik2/platform.h"
    click Platform "https://github.com/bolknote/gopnik2/blob/main/include/platform.h"
    click CMake "https://github.com/bolknote/gopnik2/blob/main/CMakeLists.txt"
    click Test "https://github.com/bolknote/gopnik2/blob/main/tests/test.cpp"

    %% Styles
    classDef entry fill:#f9c2ff,stroke:#333,stroke-width:1px;
    classDef presentation fill:#d1c4e9,stroke:#333,stroke-width:1px;
    classDef core fill:#bbdefb,stroke:#333,stroke-width:1px;
    classDef command fill:#c8e6c9,stroke:#333,stroke-width:1px;
    classDef data fill:#fff9c4,stroke:#333,stroke-width:1px;
    classDef utils fill:#e0e0e0,stroke:#333,stroke-width:1px;
    classDef build fill:#ffe0b2,stroke:#333,stroke-width:1px;
```
