# juannbel/duck-game architecture

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

- Interactive diagram: https://gitdiagram.com/juannbel/duck-game
- Repository: https://github.com/juannbel/duck-game

## Overview

##### Project type and purpose
- This is a C++‐based 2D multiplayer shooter game (“Duck Game”) with three main executables:
- duck_game_server – runs the authoritative game logic and networking
- duck_game_client – the game client with rendering, input, audio
- duck_game_editor – a Qt5‐based level editor for creating YAML map files
- It also provides a shared “common” library of utilities (sockets, threading, config, DTOs).

##### File structure
- Top‐level directories:
- client/ – source for the client, broken into networking (client_protocol, sender/receiver), rendering (renderables, animation, textures_provider), input (controls_config, joystick_manager), UI screens (lobby, pre_lobby), audio (sound_manager), main loop (constant_looper)
- server/ – source for the server, includes acceptor/receiver/sender modules, game loop and game logic (game, game_loop, game_operator, managers for bullets/collectables), entity definitions (duck_player, bullet_entity, gun_entity), map loader, YAML maps under server/maps/
- common/ – shared headers and implementations: socket, resolver, threading, config, blocking_queue, commands, DTOs (map_dto, snapshot), shared constants
- editor/ – Qt5 UI (mainwindow.ui) and logic to open, edit, save YAML maps
- tests/ – unit tests for client_protocol and server_protocol
- Build system uses CMake and Makefiles, dependencies: SDL2 (image, mixer, ttf), Qt5, YAML‐cpp.

##### README for additional insights
- Confirms client-server architecture, network protocol (custom commands.h) over sockets
- Game loop on server enforces rules and broadcasts snapshots
- Clients render snapshots, send input commands
- Editor reads/writes same map YAML files that server loads

a. Main components
- Server Process
– Network Stack (Acceptor, Receiver, Sender)
– Game Loop & Logic (game_loop, game_operator, managers, entities)
– Map Loader (reads YAML maps)
- Client Process(es)
– Network Stack (client_receiver, client_sender, client_protocol)
– Input Layer (camera, joystick_manager, controls_config)
– UI Layer (pre_lobby, lobby screens)
– Rendering Engine (SDL2: textures_provider, renderables, animation_data_provider)
– Audio Engine (sound_manager, mixer)
– Main Loop (constant_looper)
- Editor Process
– Qt5 UI (mainwindow)
– Map Serialization (YAML‐cpp)
- Shared Library (common/)
- External Dependencies (SDL2, Qt5, YAML‐cpp)
b. Relationships and interactions
- Clients ↔ Server: TCP/UDP sockets, protocol defined in common/commands.h and client_protocol/server_protocol
- Server loads maps from disk, updates game state, pushes snapshots to all connected clients
- Clients send input commands (move, shoot) to server
- Editor reads/writes the same YAML map files that server consumes
- common/ library code linked by both client and server
c. Architectural patterns & principles
- Layered Architecture: Network layer, game logic layer (server), application layer (client, editor)
- Model‐View‐Controller (MVC)-like separation in client: input (controller), game state (model from server), rendering & UI (view)
- Publisher/Subscriber style: server publishes state snapshots, clients subscribe to updates
- Plugin-style asset providers: textures_provider, animation_data_provider load data from filesystem at runtime
d. Key technologies & frameworks
- SDL2 (rendering, image, audio, TTF)
- Qt5 (editor UI)
- YAML-cpp (map serialization)
- CMake/Make for cross‐platform build
- STL threading + custom blocking_queue

##### Detail
- Protocols by referencing the common/commands.h definitions
- Data flows—map loading, snapshot broadcast, input sending—are represented

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Dependencies
    subgraph "External Dependencies"
        SDL2["SDL2 (image, mixer, ttf)"]:::dep
        Qt5["Qt5"]:::dep
        YAMLcpp["YAML-cpp"]:::dep
    end

    %% Shared Library
    subgraph "Common Library" 
        direction TB
        COMMON["common/"]:::common
    end

    %% Editor Process
    subgraph "Editor Application" 
        direction TB
        EDIT_ENTRY["Main (editor/main.cpp)"]:::editor
        EDIT_UI["UI (mainwindow.ui)"]:::editor
        EDIT_LOGIC["Map Serialization"]:::editor
    end

    %% Server Process
    subgraph "Server Process" 
        direction TB
        subgraph "Network Stack" 
            direction TB
            ACC["Acceptor"]:::server
            RCV["Receiver"]:::server
            SND["Sender"]:::server
        end
        subgraph "Game Logic" 
            direction TB
            LOOP["Game Loop"]:::server
            OPERATOR["Game Operator & Managers"]:::server
            ENTITIES["Entities & Types"]:::server
        end
        subgraph "Map Loader"
            direction TB
            MAPLDR["YAML Map Loader"]:::server
            MAPFILES["YAML Maps"]:::storage
        end
    end

    %% Network Cloud
    NET["Network"]:::network

    %% Client Process
    subgraph "Client Process" 
        direction TB
        subgraph "Network Layer"
            direction TB
            C_RCV["Client Receiver"]:::client
            C_SND["Client Sender"]:::client
            C_PROTO["Client Protocol"]:::client
        end
        subgraph "Input Layer"
            direction TB
            CONTROLLER["Controls & Joystick"]:::client
            CAMERA["Camera"]:::client
        end
        subgraph "Rendering & Audio"
            direction TB
            RENDER["Renderables & Animation"]:::client
            TEXTURES["Textures Provider"]:::client
            AUDIO["Sound Manager"]:::client
        end
        MAINLOOP["Main Loop"]:::client
        UI_SCREENS["Lobby & Pre-lobby UI"]:::client
    end

    %% Connections
    SDL2 --> RENDER
    SDL2 --> AUDIO
    Qt5 --> EDIT_UI
    YAMLcpp --> EDIT_LOGIC
    COMMON --> ACC
    COMMON --> RCV
    COMMON --> SND
    COMMON --> C_PROTO
    COMMON --> MAPLDR

    EDIT_ENTRY --> EDIT_UI
    EDIT_UI --> EDIT_LOGIC
    EDIT_LOGIC --> MAPFILES

    MAPFILES --> MAPLDR
    MAPLDR --> LOOP

    ACC --> NET
    RCV --> NET
    SND --> NET

    NET --> C_RCV
    C_SND --> NET

    LOOP --> OPERATOR
    OPERATOR --> ENTITIES
    OPERATOR --> SND

    C_RCV --> MAINLOOP
    MAINLOOP --> RENDER
    MAINLOOP --> AUDIO
    MAINLOOP --> CONTROLLER
    CONTROLLER --> C_SND
    UI_SCREENS --> MAINLOOP

    %% Click Events
    click ACC "https://github.com/juannbel/duck-game/blob/main/server/acceptor.cpp"
    click RCV "https://github.com/juannbel/duck-game/blob/main/server/receiver.cpp"
    click SND "https://github.com/juannbel/duck-game/blob/main/server/sender.cpp"
    click LOOP "https://github.com/juannbel/duck-game/blob/main/server/game_loop.cpp"
    click OPERATOR "https://github.com/juannbel/duck-game/blob/main/server/game/game_operator.cpp"
    click ENTITIES "https://github.com/juannbel/duck-game/blob/main/server/game/duck_player.cpp"
    click MAPFILES "https://github.com/juannbel/duck-game/tree/main/server/maps/"
    click C_RCV "https://github.com/juannbel/duck-game/blob/main/client/client_receiver.cpp"
    click C_SND "https://github.com/juannbel/duck-game/blob/main/client/client_sender.cpp"
    click C_PROTO "https://github.com/juannbel/duck-game/blob/main/client/client_protocol.cpp"
    click MAINLOOP "https://github.com/juannbel/duck-game/blob/main/client/constant_looper.cpp"
    click CONTROLLER "https://github.com/juannbel/duck-game/blob/main/client/joystick_manager.cpp"
    click UI_SCREENS "https://github.com/juannbel/duck-game/blob/main/client/pre_lobby/prelobbymainwindow.ui"
    click RENDER "https://github.com/juannbel/duck-game/tree/main/client/renderables/"
    click TEXTURES "https://github.com/juannbel/duck-game/blob/main/client/textures_provider.cpp"
    click AUDIO "https://github.com/juannbel/duck-game/blob/main/client/sound_manager.cpp"
    click COMMON "https://github.com/juannbel/duck-game/tree/main/common/"
    click EDIT_ENTRY "https://github.com/juannbel/duck-game/blob/main/editor/main.cpp"
    click EDIT_UI "https://github.com/juannbel/duck-game/blob/main/editor/mainwindow.ui"

    %% Styles
    classDef server fill:#a8d5ba,stroke:#333,stroke-width:1px
    classDef client fill:#a0c4ff,stroke:#333,stroke-width:1px
    classDef common fill:#cccccc,stroke:#333,stroke-width:1px
    classDef editor fill:#ffb478,stroke:#333,stroke-width:1px
    classDef dep fill:#e8e8e8,stroke:#777,stroke-width:1px
    classDef storage fill:#f1e4b3,stroke:#333,stroke-width:1px
    classDef network fill:#dddddd,stroke-dasharray: 5 5,stroke:#666,stroke-width:1px
```
