# singhdevhub-lovepreet/chatroomcpp architecture

> Architecture diagram of the GitHub repository singhdevhub-lovepreet/chatroomcpp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/singhdevhub-lovepreet/chatroomcpp
- Repository: https://github.com/singhdevhub-lovepreet/chatroomcpp

## Overview

##### Main Components
- Server Component:
– Responsible for accepting client connections.
– Uses Boost.Asio’s io_context and an acceptor for managing incoming sockets.
– Creates and maintains a “Room” for clients.
- Room Component:
– Manages the set of active client sessions (participants).
– Broadcasts messages to every participant.
- Session Component:
– Represents an individual client connection.
– Handles asynchronous reading (async_read) and writing (async_write) to the client socket.
– Inherits (or implements) an abstract Participant interface.
- Message Component:
– Encapsulates the logic for message encoding/decoding.
– Manages the message header, body, and calculates message length.
- Client Component:
– Runs with its own io_context and an additional dedicated thread to handle user input.
– Communicates with the server using asynchronous operations.
- Boost.Asio and Threading:
– Illustrate the role of Boost.Asio’s asynchronous I/O and thread models that support concurrency.
– Represent the separation of the IO thread (running io_context.run()) and the input thread on the client.

##### Relationships and Interactions
- That each Session holds a reference to the Room, indicating the dependency for message distribution.
- Session to Message with a relationship that indicates each session has its own queue of messages that it is responsible for sending.

##### Architectural Patterns and Design Principles
- Asynchronous I/O Pattern:
– Clearly annotate async_read and async_write operations.
– Mark the use of Boost.Asio’s completion handlers and post() for safe thread operations.
- Multi-threading:
– Emphasize the separation of the IO thread and input handling (especially in the client).
- Modularity:
– Show how the Session, Room, and Message components are individually responsible for their functionality.

##### Relevant Technologies and Frameworks
- Mention C++ as the implementation language and note any reliance on threading libraries from the standard library.
- (Optionally) Note that the project uses Makefile for building and GitHub Actions for CI/CD via the .github/workflows directory.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Server Side"
        S("Server"):::core
        R("Room"):::core
        Ss("Session"):::core
        M("Message"):::support
        SIO("Boost.Asio/io_context"):::support
        S -->|"manages"| Ss
        S -->|"creates"| R
        R -->|"broadcasts_to"| Ss
        Ss -->|"handles_message"| M
        S -->|"runs_on"| SIO
    end

    subgraph "Client Side"
        I("Input Thread"):::support
        C("Client"):::client
        CIO("Boost.Asio/io_context"):::support
        I -->|"triggers"| C
        CIO -->|"async_ops_on"| C
        C -->|"sends_to"| S
    end

    subgraph "Build & CI/CD"
        BM("Makefile"):::build
        GA("GitHub Actions"):::build
    end

    BM -.->|"builds"| S
    GA -.->|"builds"| S
    BM -.->|"builds"| C
    GA -.->|"builds"| C

    classDef core fill:#FFCCCC,stroke:#333,stroke-width:2px;
    classDef support fill:#CCFFFF,stroke:#333,stroke-width:2px;
    classDef client fill:#CCFFCC,stroke:#333,stroke-width:2px;
    classDef build fill:#FFFFCC,stroke:#333,stroke-width:2px;

    click S "https://github.com/singhdevhub-lovepreet/chatroomcpp/blob/main/chatRoom.cpp"
    click R "https://github.com/singhdevhub-lovepreet/chatroomcpp/blob/main/chatRoom.hpp"
    click Ss "https://github.com/singhdevhub-lovepreet/chatroomcpp/blob/main/chatRoom.hpp"
    click M "https://github.com/singhdevhub-lovepreet/chatroomcpp/blob/main/message.hpp"
    click C "https://github.com/singhdevhub-lovepreet/chatroomcpp/blob/main/client.cpp"
    click BM "https://github.com/singhdevhub-lovepreet/chatroomcpp/tree/main/Makefile"
    click GA "https://github.com/singhdevhub-lovepreet/chatroomcpp/blob/main/.github/workflows/c-cpp.yml"
```
