# baby-blowfish/ball_game architecture

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

- Interactive diagram: https://gitdiagram.com/baby-blowfish/ball_game
- Repository: https://github.com/baby-blowfish/ball_game

## Overview

##### Main Components
- Server Component:
- Server Core (server.c, main.c)
- Client List Manager (client_list_manager.c/h): Manages client connections/disconnections
- Local Ball Manager (localballmanager.c/h and related files like loaclball.c, localball_list.c/h): Maintains the authoritative state of ball objects on the server
- Task Queue (task.c/h): Handles asynchronous processing of client commands
- Client Component:
- Client Core (client.c, main.c): Connects to the server
- Screen Ball Manager (screenballmanager.c/h): Manages display updates for balls
- Screen Ball List (screenball_list.c/h): Keeps track of ball objects for rendering
- Shared Component:
- Framebuffer Drawing (fbDraw.c/h): Contains low-level functions to render graphics on the framebuffer
- Logging (log.c/h): For logging events and errors

##### Relationships and Interactions
- From the Client to the Server: Commands (e.g., add, delete, modify ball operations)
- From the Server to the Clients: Game state updates and broadcasts
- On the client side, illustrate how the Screen Ball Manager receives updates and interacts with the Screen Ball List, while the actual rendering is done via the Shared Framebuffer Drawing module.

##### Architectural Patterns and Design Principles
- Client-Server Architecture: Make sure the division of responsibilities is clear—server mediates connections and game state while clients handle user interactions and rendering.
- Multi-threading: Emphasize the threaded architecture (particularly with the Task Queue) that allows for asynchronous command processing.
- Layered Design: The separation into “client,” “server,” and “shared” components follows a clear layered approach in code organization.
- Communication over sockets (not explicitly diagrammed as internals, but annotate that both client and server heavily depend on socket-based networking).

##### Technology and Framework Mentions
- C language and GCC compiler usage (implied by file extensions and makefile).
- pthread library usage for multi-threading.
- Linux environment with framebuffer support.
- Use of Doxygen for documentation (not part of the application runtime but indicates the strong documentation practice).

##### Essential Elements
- Clear node labels for each major module/component as described above.
- Client → Server: User commands
- Server → Client: Game state updates
- Internal flows (e.g., within the server: Task Queue triggering state updates)
- Annotations to explain key processes such as “Asynchronous Command Processing,” “Real-time Broadcast,” and “Framebuffer rendering.”

- Server Side: Showing sockets, multi-threading (Task Queue), ball management, and client connection handling.
- Client Side: Highlighting socket communication, screen ball management, and rendering on the framebuffer.
- Shared Libraries: Display nodes for framebuffer drawing, logging, and console enhancements that are used by both client and server.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Server Side Components
    subgraph "Server Side"
        server_core["Server Core"]:::server
        task_queue["Task Queue"]:::server
        client_list_manager["Client List Manager"]:::server
        local_ball_manager["Local Ball Manager"]:::server
    end

    %% Client Side Components
    subgraph "Client Side"
        client_core["Client Core"]:::client
        screen_ball_manager["Screen Ball Manager"]:::client
        screen_ball_list["Screen Ball List"]:::client
    end

    %% Shared Components
    subgraph "Shared"
        fb_drawing["Framebuffer Drawing"]:::shared
        logging["Logging"]:::shared
        console_color["Console Color"]:::shared
    end

    %% Interactions Between Client and Server
    client_core -->|"commands"| server_core
    server_core -->|"state_updates"| client_core

    %% Server Internal Interactions
    server_core -->|"async_processing"| task_queue
    task_queue -->|"update_game_state"| local_ball_manager
    task_queue -->|"manage_connections"| client_list_manager
    local_ball_manager -->|"broadcast_updates"| client_list_manager

    %% Client Internal Interactions
    client_core -->|"process_update"| screen_ball_manager
    screen_ball_manager -->|"render_ball"| screen_ball_list
    screen_ball_manager -->|"render_calls"| fb_drawing

    %% Shared Usage by Server and Client
    server_core -->|"log_events"| logging
    client_core -->|"log_events"| logging
    server_core -->|"console_output"| console_color
    client_core -->|"console_output"| console_color

    %% Styles
    classDef server fill:#FEC,stroke:#333,stroke-width:2px;
    classDef client fill:#CFF,stroke:#333,stroke-width:2px;
    classDef shared fill:#CFC,stroke:#333,stroke-width:2px;

    %% Click Events for Server Components
    click server_core "https://github.com/baby-blowfish/ball_game/blob/main/src/server/server.c"
    click client_list_manager "https://github.com/baby-blowfish/ball_game/blob/main/src/server/client_list_manager.c"
    click local_ball_manager "https://github.com/baby-blowfish/ball_game/blob/main/src/server/localballmanager.c"
    click task_queue "https://github.com/baby-blowfish/ball_game/blob/main/src/server/task.c"

    %% Click Events for Client Components
    click client_core "https://github.com/baby-blowfish/ball_game/blob/main/src/client/client.c"
    click screen_ball_manager "https://github.com/baby-blowfish/ball_game/blob/main/src/client/screenballmanager.c"
    click screen_ball_list "https://github.com/baby-blowfish/ball_game/blob/main/src/client/screenball_list.c"

    %% Click Events for Shared Components
    click fb_drawing "https://github.com/baby-blowfish/ball_game/blob/main/src/shared/fbDraw.c"
    click logging "https://github.com/baby-blowfish/ball_game/blob/main/src/shared/log.c"
    click console_color "https://github.com/baby-blowfish/ball_game/blob/main/include/shared/console_color.h"
```
