# ao-libre/ao-server architecture

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

- Interactive diagram: https://gitdiagram.com/ao-libre/ao-server
- Repository: https://github.com/ao-libre/ao-server

## Overview

##### Main Components
- Server Core & Game Engine: The heart of the system is in the “Codigo” folder. This comprises modules that handle game logic (e.g., GameLogic.bas), combat (SistemaCombate.bas), quests (modQuests.bas), NPCs, clan management and other in-game mechanics.
- Network Communication Module: Files like TCP.bas, Protocol.bas, and modSendData.bas indicate the presence of a network layer to handle client connections and messaging. Mark this as the “TCP/Protocol Module.”
- Data Management and Persistence: The “Dat” folder holds many configuration and game data files (Balance.dat, Map.dat, NPCs.dat, etc.), which are used by the server to load game content and state. Indicate a “Data Access Layer” that reads/writes these files.
- User and Account Management: Directories like “Account” and modules such as Cuentas.bas and modUserRecords.bas suggest dedicated components for account handling, user profiles, and character management.
- Administrative & Monitoring Interfaces: Forms like frmAdmin, frmCargando, and the “Logs” folder imply that there is a GUI component for administrators as well as logging mechanisms for error and event tracking.
- Library Dependencies & External Services: The “Librerias” folder contains necessary OCX/DLL files required by VB6, and the README describes integration with external APIs (ao-api-server for functions like emailing and backups) and automatic update functionality.
- Maps/Worlds Data: The “Mundos” directory stores the various map files that define the game world, highlighting a dedicated subsystem for world and terrain management.
- Miscellaneous Components: Additional directories such as “AntiCheats,” “Charfile,” “Foros,” and “Guilds” organize ancillary functionalities like anti-cheat mechanisms, chat logs or character files, forum integrations, and guilds management.

- “Administrative Interface” module (GUI forms) as interfacing with the core engine for server control and monitoring, also reading logs from the “Logs” repository.
- Integration with external services (e.g., the ao-api-server for email, backup, and version updates) as an external dependency that communicates with the core engine.
- If needed, illustrate a “Library/Dependency” component representing the pre-installed OCX/DLL libraries that the VB6 project relies on.

##### Architectural Patterns and Principles
- A layered architecture: separate network handling, business logic (game engine), and data management.
- Modular design – each physical .bas, .cls, or .frm file in “Codigo” typically plays a distinct role (e.g., processing events, managing queues, or handling security).
– From Clients (external user connections) → Network Module → Game Engine.
– Game Engine ↔ Data Access (read/write operations on .dat files).
– Administrative Interface ↔ Game Engine and Logging components.
– Game Engine → External API Services.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Components
    Client["External Clients"]:::client

    subgraph "Core Layers"
        GameEngine["Game Engine/Server Core"]:::core
    end

    subgraph "Network Layer"
        NetworkModule["TCP/Protocol Module"]:::network
    end

    subgraph "Data Layer"
        DataAccess["Data Access Layer (.dat files)"]:::data
    end

    subgraph "Account Layer"
        AccountManagement["User & Account Management"]:::account
    end

    subgraph "Administration"
        AdminInterface["Administrative Interface (GUI Forms)"]:::admin
        Logs["Logs Repository"]:::log
    end

    subgraph "External Services"
        ExternalAPI["External API/Update Module"]:::external
        Libraries["Library Dependencies"]:::library
    end

    subgraph "World Management"
        MapsData["Maps/World Data"]:::maps
    end

    subgraph "Miscellaneous Components"
        AntiCheat["AntiCheat Module"]:::misc
        Forum["Forum Integration"]:::misc
        Guilds["Guilds Management"]:::misc
        CharFile["Character Files"]:::misc
    end

    %% Connections
    Client -->|"requests"| NetworkModule
    NetworkModule -->|"forwards"| GameEngine
    GameEngine -->|"reads/writes"| DataAccess
    GameEngine -->|"handles"| AccountManagement
    AccountManagement -->|"accesses"| DataAccess
    AdminInterface -->|"commands"| GameEngine
    Logs -->|"monitors"| AdminInterface
    GameEngine -->|"calls"| ExternalAPI
    GameEngine -->|"uses"| Libraries
    GameEngine -->|"loads"| MapsData
    AccountManagement -->|"manages"| CharFile
    GameEngine -->|"integrates"| AntiCheat
    GameEngine -->|"integrates"| Forum
    GameEngine -->|"integrates"| Guilds

    %% Click Events
    click GameEngine "https://github.com/ao-libre/ao-server/tree/master/Codigo"
    click NetworkModule "https://github.com/ao-libre/ao-server/blob/master/Codigo/TCP.bas"
    click DataAccess "https://github.com/ao-libre/ao-server/tree/master/Dat"
    click AccountManagement "https://github.com/ao-libre/ao-server/tree/master/Account"
    click AdminInterface "https://github.com/ao-libre/ao-server/blob/master/Codigo/frmAdmin.frm"
    click Logs "https://github.com/ao-libre/ao-server/tree/master/Logs"
    click ExternalAPI "https://github.com/ao-libre/ao-server/tree/master/Librerias"
    click Libraries "https://github.com/ao-libre/ao-server/tree/master/Librerias"
    click MapsData "https://github.com/ao-libre/ao-server/tree/master/Mundos"
    click CharFile "https://github.com/ao-libre/ao-server/tree/master/Charfile"
    click AntiCheat "https://github.com/ao-libre/ao-server/tree/master/AntiCheats"
    click Forum "https://github.com/ao-libre/ao-server/tree/master/Foros"
    click Guilds "https://github.com/ao-libre/ao-server/tree/master/Guilds"

    %% Styles
    classDef core fill:#ffd1dc,stroke:#c2185b,stroke-width:2px;
    classDef network fill:#d1e8ff,stroke:#1976d2,stroke-width:2px;
    classDef data fill:#dcedc8,stroke:#558b2f,stroke-width:2px;
    classDef account fill:#fff9c4,stroke:#f9a825,stroke-width:2px;
    classDef admin fill:#ffe0b2,stroke:#ef6c00,stroke-width:2px;
    classDef log fill:#eeeeee,stroke:#757575,stroke-width:2px;
    classDef external fill:#ffcdd2,stroke:#c62828,stroke-width:2px;
    classDef library fill:#f0e68c,stroke:#b8860b,stroke-width:2px;
    classDef maps fill:#c5e1a5,stroke:#558b2f,stroke-width:2px;
    classDef misc fill:#d1c4e9,stroke:#5e35b1,stroke-width:2px;
    classDef client fill:#ffe082,stroke:#ff8f00,stroke-width:2px;
```
