# iw4x/iw4x-client architecture

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

## Overview

##### Main Components
- Client Core & Game Logic:
- Under the “src/Game” directory, you have game-specific files (client, server, game engine, file systems, scripting). These files form the core game logic, handling gameplay functions, engine integration, and player interaction.
- Modular Components:
- The “src/Components” folder shows a number of modules. Each sub-module (AssetInterfaces, GSC scripts, Discord integration, console, renderer, network, etc.) constitutes a distinct component that extends or hooks into the game’s behavior.
- Steam Integration:
- The “src/Steam” directory shows interfaces for SteamFriends, SteamMatchmaking, and other Steam services, which are critical for integrating platform features.
- Utility & Support Libraries:
- “src/Utils” includes a range of helper functions (e.g., JSON, compression, thread utilities) that offer supplementary functionality to the main components.
- External Dependencies:
- The “deps” folder (with sub-folders for libraries like GSL, Discord-RPC, mongoose, and more) should be featured as external libraries that support internal modules. Also note the “tools” directory which contains premade executables for premake and protoc, emphasizing the build-infrastructure.

##### Relationships and Interactions
- How the client core (from “src/Game”) interacts with the modular components which implement specific game behaviors like network handling, asset loading, UI interactions, etc.
- Integration with Steam and external services: how calls from the game core or modules (such as authentication, matchmaking, logging) invoke services in “src/Steam”.
- How utilities (in “src/Utils”) support both game logic and the components by providing cross-cutting functionalities for logging, thread handling, and file I/O.
- Dependencies on external libraries (listed in “deps”) and the build configuration files (premake5.lua, generate.bat) as necessary parts of the build/integration pipeline.

##### Architectural Patterns & Design Principles
- Modularity: The design follows a loosely coupled modular approach in the “src/Components” folder where each module (ex.: Auth, Ban system, Discord integration) serves a specific cross-cutting concern.
- Hooking and Interception: There is a use of hooks (see “src/Utils/Hooking.cpp”) that modify or extend game behavior at runtime.
- Multi-layered architecture:
- Lower-level engine and file handling code in “src/Game/Engine” and “src/Game/FileSystem” supports higher-level game logic housed in “src/Game” and “src/Components”.
- Clear separation between core game functionality, modular enhancements, and underlying utility libraries.
- Build & Configuration Management: The use of Premake scripts (premake5.lua, scripts and deps/premake) indicates automated build generation and a consistent project setup.

##### Relevant Technologies, Frameworks, and Libraries
- C++ (primary programming language)
- Premake for build configuration
- Direct integration with Steam APIs
- External libraries such as mongoose (HTTP server), libtomcrypt, libtommath, pdcurses for cross-platform UI elements, and more.
- Support for modding through script interfaces (e.g., GSC code in “src/Components/Modules/GSC”).

##### Elements to be Included
- Clear labels for each component, such as “Game Core”, “Modular Components”, “Steam Integration”, “Utility Libraries”, and “External Dependencies”.
- Core game engine components
- A dedicated area showing build/configuration phases – linking components such as “premake5.lua”, “generate.bat”, and “Visual Studio solution” to your project’s build process.

##### Final Advice
- Architectural layering is visible: game engine at the core, extended by components and then utilities, all while interfacing to external services.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Layer
    subgraph "Core Layer"
        GC["Game Core"]:::core
    end

    %% Modular Layer
    subgraph "Modular Layer"
        MC["Modular Components"]:::module
        SI["Steam Integration"]:::steam
    end

    %% Support Layer
    subgraph "Support Layer"
        UT["Utility & Support Libraries"]:::utility
    end

    %% External & Build Layer
    subgraph "External & Build Layer"
        ED["External Dependencies"]:::external
        BC["Build & Config"]:::build
    end

    %% Relationships
    GC -->|"uses"| MC
    MC -->|"calls"| SI
    GC ---|"supports"| UT
    MC ---|"supports"| UT
    GC -.->|"depends"| ED
    MC -.->|"depends"| ED
    SI -.->|"depends"| ED
    BC -->|"builds"| GC
    BC -->|"builds"| MC
    BC -->|"builds"| SI

    %% Click Events
    click GC "https://github.com/iw4x/iw4x-client/tree/develop/src/Game"
    click MC "https://github.com/iw4x/iw4x-client/tree/develop/src/Components"
    click SI "https://github.com/iw4x/iw4x-client/tree/develop/src/Steam"
    click UT "https://github.com/iw4x/iw4x-client/tree/develop/src/Utils"
    click ED "https://github.com/iw4x/iw4x-client/tree/develop/deps"

    %% Styling Classes
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef module fill:#90EE90,stroke:#333,stroke-width:2px,rx:5,ry:5;
    classDef steam fill:#FFA500,stroke:#333,stroke-width:2px;
    classDef utility fill:#FFFF99,stroke:#333,stroke-width:2px;
    classDef external fill:#FFC0CB,stroke:#333,stroke-width:2px;
    classDef build fill:#DDA0DD,stroke:#333,stroke-width:2px;
```
