# faris90/ogariivercel architecture

> Architecture diagram of the GitHub repository faris90/ogariivercel, 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/faris90/ogariivercel
- Repository: https://github.com/faris90/ogariivercel

## Overview

##### Project Overview and Main Purpose
- This project is a game server aimed at recreating Agar.io private servers.
- It is built in Node.js and utilizes WebSockets (via uWebSockets) for fast and efficient real-time communication.
- The project includes multiple modules that handle game logic, network communication, various game entities (cells, bots), gamemodes, and commands for server control.

##### File Structure
- Top-level Files: Files like index.js, package.json, and configuration files (.gitignore, vercel.json) indicate standard Node.js project metadata and build/deployment logic.
- CLI Directory: Contains executable scripts (cli/index.js, cli/log-handler.js) designed to start and control the server as well as manage logging and settings configuration.
- src Directory: The heart of the application. Key subdirectories include:
- bots – Classes representing different types of bots (PlayerBot, Minion, Bot)
- cells – Classes representing various cell types (Cell, EjectedCell, Mothercell, Pellet, PlayerCell, Virus)
- commands – Provides a command API (CommandList, DefaultCommands)
- gamemodes – Contains definitions for various game modes (FFA, LastManStanding, Teams) and a base Gamemode class
- protocols – Defines the different network protocols (LegacyProtocol, ModernProtocol, and their management)
- sockets – Network-related classes for chat channels, connection handling, and routing
- worlds – Manages game world aspects (Matchmaker, Player, World)
- primitives – Low-level utilities like Logger, QuadTree, and Ticker that support core functionalities
- Other files like ServerHandle.js and Settings.js indicate the central orchestration functions of the server.

##### Key Components and Their Interactions
- CLI Layer:
- Contains the entry-point (cli/index.js) that starts the server.
- Responsible for ingesting configuration from files like settings.json and log-settings.json.
- Core Server (ServerHandle):
- Acts as the central manager that wires up all modules.
- Interfaces with the CLI and serves as the bridge to all internal components.
- Game Entities and Mechanics:
- Bots (players made up of AI logic) and Cells (representing in-game entities) are the building blocks of the game arena.
- Commands and Gamemodes allow a high degree of customization for gameplay.
- Network and Communication:
- Protocols and Sockets are used to manage client connections, exchanging game data, chat messages, and state updates.
- The project supports several protocol versions to cater to different Agar.io client versions.
- World Management:
- The Worlds module manages the different game realms or “servers,” handling matchmaking and individual world updates.
- Utility and Support Modules:
- Primitives such as Logger, QuadTree, and Ticker help maintain performance and manage the internal game state efficiently.

##### Architectural Patterns and Design Principles
- Modular Design: Clear separation between modules (bots, cells, commands, etc.) makes it easy to extend and maintain.
- Component-Based Architecture: Each sub-directory represents a logical component of the server.
- Abstraction & Extensibility: The use of abstract classes and registration methods (e.g., for gamemodes and commands) suggests that new functionalities can be added without modifying core classes.

##### Final Touches
- Avoid overcomplicating the visual; ensure that all critical components and their relationships are captured without unnecessary clutter.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "OgarII WebSockets Edition"
        
        subgraph "CLI Layer"
            CLI_Index["cli/index.js"]:::cli
            CLI_Log["cli/log-handler.js"]:::cli
        end
        
        subgraph "Server Core"
            ServerHandle["ServerHandle (Main)"]:::server
            Settings["Settings"]:::server
        end
        
        subgraph "Game Logic Modules"
            Bots["Bots (Game Entities)"]:::game
            Cells["Cells (Game Entities)"]:::game
            Commands["Commands API"]:::game
            Gamemodes["Gamemodes"]:::game
        end
        
        subgraph "Network Modules"
            Protocols["Protocols"]:::network
            Sockets["Sockets"]:::network
        end
        
        WorldManagement["World Management"]:::world
        Utilities["Utilities/Primitives"]:::utility
    end

    %% Connections
    CLI_Index -->|"bootstrap"| ServerHandle
    CLI_Log -->|"bootstrap"| ServerHandle
    ServerHandle -->|"Initialize"| Bots
    ServerHandle -->|"Initialize"| Cells
    ServerHandle -->|"RegisterCommands"| Commands
    ServerHandle -->|"RegisterGamemodes"| Gamemodes
    ServerHandle -->|"DataExchange"| Protocols
    ServerHandle -->|"EventTrigger"| Sockets
    ServerHandle -->|"ManageWorlds"| WorldManagement
    ServerHandle -->|"Support"| Utilities

    %% Class Definitions for Colors
    classDef cli fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef server fill:#ffebcc,stroke:#cc6600,stroke-width:2px;
    classDef game fill:#cce5ff,stroke:#3366ff,stroke-width:2px;
    classDef network fill:#d4edda,stroke:#2eb82e,stroke-width:2px;
    classDef world fill:#e2e3e5,stroke:#969696,stroke-width:2px;
    classDef utility fill:#f8d7da,stroke:#e60073,stroke-width:2px;

    %% Click Events
    click CLI_Index "https://github.com/faris90/ogariivercel/blob/master/cli/index.js"
    click CLI_Log "https://github.com/faris90/ogariivercel/blob/master/cli/log-handler.js"
    click ServerHandle "https://github.com/faris90/ogariivercel/blob/master/src/ServerHandle.js"
    click Settings "https://github.com/faris90/ogariivercel/blob/master/src/Settings.js"
    click Bots "https://github.com/faris90/ogariivercel/tree/master/src/bots"
    click Cells "https://github.com/faris90/ogariivercel/tree/master/src/cells"
    click Commands "https://github.com/faris90/ogariivercel/tree/master/src/commands"
    click Gamemodes "https://github.com/faris90/ogariivercel/tree/master/src/gamemodes"
    click Protocols "https://github.com/faris90/ogariivercel/tree/master/src/protocols"
    click Sockets "https://github.com/faris90/ogariivercel/tree/master/src/sockets"
    click WorldManagement "https://github.com/faris90/ogariivercel/tree/master/src/worlds"
    click Utilities "https://github.com/faris90/ogariivercel/tree/master/src/primitives"
```
