# meyfa/cobolcraft architecture

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

- Interactive diagram: https://gitdiagram.com/meyfa/cobolcraft
- Repository: https://github.com/meyfa/cobolcraft

## Overview

##### Main Components

a) Core Server Components:
- Network Layer (Socket Management)
- Game Logic Layer
- World Management
- Player Management
- Command System
- Data Storage

b) External Dependencies:
- CBL_GC_SOCKET Library
- C++ Utilities
- Minecraft Protocol Interface

**┌─────────────────────────────────────────────────────────┐**
- Client Connection Layer                 │
- (CBL_GC_SOCKET Library + Network Protocol Handlers)    │
- ┘
- ↕
**┌─────────────────────────────────────────────────────────┐**
- Packet Processing Layer                  │
- (Encoders/Decoders, NBT, JSON, Protocol Logic)       │
- ┘
- ↕
**┌─────────────────────────────────────────────────────────┐**
- Game Logic Layer                      │
- (World, Players, Blocks, Items, Commands, Chat)        │
- ┘
- ↕
**┌─────────────────────────────────────────────────────────┐**
- Data Storage Layer                      │
- (Region Files, World Data, Player Data, Config)     │
- ┘

##### Component Details

a) Core Components (Rectangles):
- Server (main.cob, server.cob)
- World Management (world.cob)
- Player Management (players.cob)
- Block System (blocks/*.cob)
- Item System (items/*.cob)

b) Support Systems (Hexagons):
- Command Processor (commands/*.cob)
- Chat System (chat.cob)
- Whitelist Management (whitelist.cob)

- NBT Encoder/Decoder
- JSON Parser/Encoder
- Packet Handlers
- Region File Manager

d) External Interfaces (Clouds):
- Socket Library
- C++ Utilities
- Minecraft Protocol

##### Data Flow Indicators

- Network communication flow
- Data persistence operations
- Command processing flow
- Game state updates

##### Additional Elements

Annotations for:
- Maximum player count (10)
- Supported Minecraft version (1.21.4)
- Key file formats (NBT, JSON)
- Configuration options

- The modular nature of the system
- Clear separation between network, game logic, and storage
- The relationship between COBOL components and C++ utilities
- How the packet processing pipeline works
- The integration with Minecraft's protocol and file formats

Remember to maintain a balance between detail and clarity, focusing on the architectural relationships while avoiding overwhelming technical specifics.

This design should reflect the unique aspects of CobolCraft, such as its use of COBOL for game server implementation and its interaction with modern gaming protocols.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and Classes
    classDef interface fill:#b3d1ff,stroke:#333
    classDef gamelogic fill:#b3ffb3,stroke:#333
    classDef dataproc fill:#ffd9b3,stroke:#333
    classDef storage fill:#d9b3ff,stroke:#333
    classDef crosscut fill:#e6e6e6,stroke:#333
    
    %% Server Interface Layer
    subgraph NetworkLayer
        Socket["Socket Management"]:::interface
        Protocol["Protocol Handlers"]:::interface
        ClientState["Client State Manager"]:::interface
        
        Socket --> Protocol
        Protocol --> ClientState
    end
    
    %% Game Logic Layer
    subgraph GameLogic
        CmdProc["Command Processor"]:::gamelogic
        WorldMgr["World Manager"]:::gamelogic
        PlayerMgr["Player Manager"]:::gamelogic
        BlockMgr["Block Manager"]:::gamelogic
        ItemSys["Item System"]:::gamelogic
        ChatSys["Chat System"]:::gamelogic
        
        subgraph CommandSubsystem
            GameMode["Gamemode Commands"]:::gamelogic
            Help["Help Commands"]:::gamelogic
            Save["Save Commands"]:::gamelogic
            
            CmdProc --> GameMode
            CmdProc --> Help
            CmdProc --> Save
        end
        
        WorldMgr --> BlockMgr
        PlayerMgr --> ItemSys
        PlayerMgr --> ChatSys
    end
    
    %% Data Processing Layer
    subgraph DataProcessing
        NBTProc["NBT Processing"]:::dataproc
        JSONProc["JSON Processing"]:::dataproc
        PacketProc["Packet Processing"]:::dataproc
        
        subgraph DataFormats
            NBTEncode["NBT Encoder"]:::dataproc
            NBTDecode["NBT Decoder"]:::dataproc
            JSONEncode["JSON Encoder"]:::dataproc
            JSONParse["JSON Parser"]:::dataproc
            PacketEncode["Packet Encoder"]:::dataproc
            PacketDecode["Packet Decoder"]:::dataproc
        end
        
        NBTProc --> NBTEncode
        NBTProc --> NBTDecode
        JSONProc --> JSONEncode
        JSONProc --> JSONParse
        PacketProc --> PacketEncode
        PacketProc --> PacketDecode
    end
    
    %% Storage Layer
    subgraph Storage
        RegionMgr["Region File Manager"]:::storage
        ConfigMgr["Configuration Manager"]:::storage
        WhitelistMgr["Whitelist Manager"]:::storage
        WorldData["World Data Storage"]:::storage
        PlayerData["Player Data Storage"]:::storage
    end
    
    %% Cross-Cutting Concerns
    subgraph CrossCutting
        Registry["Registry System"]:::crosscut
        Utils["Utility Functions"]:::crosscut
        Callbacks["Callback System"]:::crosscut
    end
    
    %% Inter-layer Connections
    NetworkLayer --> GameLogic
    GameLogic --> DataProcessing
    DataProcessing --> Storage
    CrossCutting --> NetworkLayer
    CrossCutting --> GameLogic
    CrossCutting --> DataProcessing
    CrossCutting --> Storage
    
    %% Click Events
    click Socket "https://github.com/meyfa/CobolCraft/blob/main/src/socket.cob"
    click Protocol "https://github.com/meyfa/CobolCraft/tree/main/src/packets/"
    click ClientState "https://github.com/meyfa/CobolCraft/blob/main/src/copybooks/DD-CLIENT-STATES.cpy"
    click CmdProc "https://github.com/meyfa/CobolCraft/tree/main/src/commands/"
    click GameMode "https://github.com/meyfa/CobolCraft/blob/main/src/commands/gamemode.cob"
    click Help "https://github.com/meyfa/CobolCraft/blob/main/src/commands/help.cob"
    click Save "https://github.com/meyfa/CobolCraft/blob/main/src/commands/save.cob"
    click PlayerMgr "https://github.com/meyfa/CobolCraft/blob/main/src/players.cob"
    click ChatSys "https://github.com/meyfa/CobolCraft/blob/main/src/chat.cob"
    click WorldMgr "https://github.com/meyfa/CobolCraft/blob/main/src/world.cob"
    click BlockMgr "https://github.com/meyfa/CobolCraft/tree/main/src/blocks/"
    click ItemSys "https://github.com/meyfa/CobolCraft/tree/main/src/items/"
    click NBTEncode "https://github.com/meyfa/CobolCraft/blob/main/src/nbt-encode.cob"
    click NBTDecode "https://github.com/meyfa/CobolCraft/blob/main/src/nbt-decode.cob"
    click JSONEncode "https://github.com/meyfa/CobolCraft/blob/main/src/json-encode.cob"
    click JSONParse "https://github.com/meyfa/CobolCraft/blob/main/src/json-parse.cob"
    click PacketEncode "https://github.com/meyfa/CobolCraft/blob/main/src/encode.cob"
    click PacketDecode "https://github.com/meyfa/CobolCraft/blob/main/src/decode.cob"
    click RegionMgr "https://github.com/meyfa/CobolCraft/blob/main/src/region.cob"
    click ConfigMgr "https://github.com/meyfa/CobolCraft/blob/main/src/server-properties.cob"
    click WhitelistMgr "https://github.com/meyfa/CobolCraft/blob/main/src/whitelist.cob"
    click Registry "https://github.com/meyfa/CobolCraft/blob/main/src/registries.cob"
    click Utils "https://github.com/meyfa/CobolCraft/blob/main/cpp/cobolcraft_util.cpp"
    click Callbacks "https://github.com/meyfa/CobolCraft/blob/main/src/callbacks.cob"
```
