# armaanusmani/chatroom-server architecture

> Architecture diagram of the GitHub repository armaanusmani/chatroom-server, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/armaanusmani/chatroom-server
- Repository: https://github.com/armaanusmani/chatroom-server

## Overview

chatRoomCpp is a small TCP chat application: a client connects to the server, sends line-oriented input, and displays incoming messages. The server accepts connections into sessions; sessions join a room, relay incoming messages to it, and write broadcasts to other participants. Message provides the server-side encoding and decoding helpers. The README describes asynchronous I/O and threading; the excerpts show asynchronous server socket operations and a client input thread. The graph follows the excerpts and documented capabilities; it does not assume unshown runtime wiring.

Main entry points: [`chatRoom.cpp`](https://github.com/armaanusmani/chatroom-server/blob/main/chatRoom.cpp) (Client session), [`client.cpp`](https://github.com/armaanusmani/chatroom-server/blob/main/client.cpp) (Client app), [`message.hpp`](https://github.com/armaanusmani/chatroom-server/blob/main/message.hpp) (Message framing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client"]
  node_client_app["Client app<br/>[client.cpp]"]
  node_client_input["Input thread<br/>[client.cpp]"]
  node_client_receive["Server receiver<br/>[client.cpp]"]
end

subgraph group_server["Server and sessions"]
  node_server["Server accept loop<br/>[chatRoom.cpp]"]
  node_session["Client session<br/>[chatRoom.cpp]"]
end

subgraph group_messaging["Room and messages"]
  node_room["Chat room<br/>[chatRoom.cpp]"]
  node_message["Message framing<br/>[message.hpp]"]
end

node_user(("Chat user"))
node_tcp{{"TCP connection"}}

node_user -->|"enters messages"| node_client_input
node_client_app -->|"starts thread"| node_client_input
node_client_app -->|"starts reading"| node_client_receive
node_client_app -->|"connects to"| node_tcp
node_client_input -->|"writes input"| node_tcp
node_tcp -->|"delivers replies"| node_client_receive
node_server -->|"accepts connections"| node_tcp
node_server -->|"creates session"| node_session
node_session -->|"joins room"| node_room
node_session -->|"constructs message"| node_message
node_session -->|"delivers message"| node_room
node_room -->|"dispatches broadcast"| node_session
node_session -->|"decodes body"| node_message
node_session -->|"reads and writes"| node_tcp

click node_client_app "https://github.com/armaanusmani/chatroom-server/blob/main/client.cpp"
click node_client_input "https://github.com/armaanusmani/chatroom-server/blob/main/client.cpp"
click node_client_receive "https://github.com/armaanusmani/chatroom-server/blob/main/client.cpp"
click node_server "https://github.com/armaanusmani/chatroom-server/blob/main/chatRoom.cpp"
click node_session "https://github.com/armaanusmani/chatroom-server/blob/main/chatRoom.cpp"
click node_room "https://github.com/armaanusmani/chatroom-server/blob/main/chatRoom.cpp"
click node_message "https://github.com/armaanusmani/chatroom-server/blob/main/message.hpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_client_app,node_client_input,node_client_receive,node_user toneBlue
class node_server,node_session toneAmber
class node_room,node_message toneMint
class node_tcp toneIndigo
```

## Components

### Client

- [Client app](https://github.com/armaanusmani/chatroom-server/blob/main/client.cpp): `client.cpp`
- [Input thread](https://github.com/armaanusmani/chatroom-server/blob/main/client.cpp): `client.cpp`
- [Server receiver](https://github.com/armaanusmani/chatroom-server/blob/main/client.cpp): `client.cpp`

### Server and sessions

- [Server accept loop](https://github.com/armaanusmani/chatroom-server/blob/main/chatRoom.cpp): `chatRoom.cpp`
- [Client session](https://github.com/armaanusmani/chatroom-server/blob/main/chatRoom.cpp): `chatRoom.cpp`

### Room and messages

- [Chat room](https://github.com/armaanusmani/chatroom-server/blob/main/chatRoom.cpp): `chatRoom.cpp`
- [Message framing](https://github.com/armaanusmani/chatroom-server/blob/main/message.hpp): `message.hpp`

### Other components

- **Chat user**
- **TCP connection**

## Connections

- Chat user → Input thread: enters messages (evidence: `client.cpp`)
- Client app → Input thread: starts thread (evidence: `client.cpp`)
- Client app → Server receiver: starts reading (evidence: `client.cpp`)
- Client app → TCP connection: connects to (evidence: `client.cpp`)
- Input thread → TCP connection: writes input (evidence: `client.cpp`)
- TCP connection → Server receiver: delivers replies (evidence: `client.cpp`)
- Server accept loop → TCP connection: accepts connections (evidence: `chatRoom.cpp`)
- Server accept loop → Client session: creates session (evidence: `chatRoom.cpp`)
- Client session → Chat room: joins room (evidence: `chatRoom.cpp`)
- Client session → Message framing: constructs message (evidence: `chatRoom.cpp`)
- Client session → Chat room: delivers message (evidence: `chatRoom.cpp`)
- Chat room → Client session: dispatches broadcast (evidence: `chatRoom.cpp`)
- Client session → Message framing: decodes body (evidence: `chatRoom.cpp`)
- Client session → TCP connection: reads and writes (evidence: `chatRoom.cpp`)
