# prajwal-kr-12/chat-application architecture

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

- Interactive diagram: https://gitdiagram.com/prajwal-kr-12/chat-application
- Repository: https://github.com/prajwal-kr-12/chat-application

## Overview

This is a small terminal chat application: a user chooses a nickname and types messages in a client, which connects to a central TCP server; the server manages connected clients and broadcasts messages to other participants. On the client, separate receive and write loops handle incoming messages and user input. On the server, the accept loop registers clients and starts a handler per connection; handlers forward messages to the broadcaster, which also handles failed sends and disconnections. The map follows the README and the two excerpted source files.

Main entry points: [`server.py`](https://github.com/prajwal-kr-12/chat-application/blob/main/server.py) (Message broadcaster), [`client.py`](https://github.com/prajwal-kr-12/chat-application/blob/main/client.py) (TCP client connection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Chat client"]
  node_client_connection["TCP client connection<br/>[client.py]"]
  node_client_receive["Receive loop<br/>[client.py]"]
  node_client_write["Write loop<br/>[client.py]"]
end

subgraph group_server["Chat server"]
  node_server_accept["Accept and register<br/>[server.py]"]
  node_client_registry[("Client registry<br/>[server.py]")]
  node_client_handler["Client handler<br/>[server.py]"]
  node_broadcaster["Message broadcaster<br/>[server.py]"]
end

node_user(("Terminal user"))

node_user -->|"chooses nickname"| node_client_connection
node_client_connection -->|"connects by TCP"| node_server_accept
node_server_accept -->|"stores client"| node_client_registry
node_server_accept -->|"starts thread"| node_client_handler
node_server_accept -->|"announces arrival"| node_broadcaster
node_user -->|"types messages"| node_client_write
node_client_write -->|"sends messages"| node_client_connection
node_client_connection -->|"receives data"| node_client_receive
node_client_handler -->|"forwards messages"| node_broadcaster
node_broadcaster -->|"reads recipients"| node_client_registry
node_broadcaster -->|"broadcasts messages"| node_client_connection
node_broadcaster -->|"removes failed clients"| node_client_registry

click node_client_connection "https://github.com/prajwal-kr-12/chat-application/blob/main/client.py"
click node_client_receive "https://github.com/prajwal-kr-12/chat-application/blob/main/client.py"
click node_client_write "https://github.com/prajwal-kr-12/chat-application/blob/main/client.py"
click node_server_accept "https://github.com/prajwal-kr-12/chat-application/blob/main/server.py"
click node_client_registry "https://github.com/prajwal-kr-12/chat-application/blob/main/server.py"
click node_client_handler "https://github.com/prajwal-kr-12/chat-application/blob/main/server.py"
click node_broadcaster "https://github.com/prajwal-kr-12/chat-application/blob/main/server.py"

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_connection,node_client_receive,node_client_write,node_user toneBlue
class node_server_accept,node_client_registry,node_client_handler,node_broadcaster toneAmber
```

## Components

### Chat client

- [TCP client connection](https://github.com/prajwal-kr-12/chat-application/blob/main/client.py): `client.py`
- [Receive loop](https://github.com/prajwal-kr-12/chat-application/blob/main/client.py): `client.py`
- [Write loop](https://github.com/prajwal-kr-12/chat-application/blob/main/client.py): `client.py`

### Chat server

- [Accept and register](https://github.com/prajwal-kr-12/chat-application/blob/main/server.py): `server.py`
- [Client registry](https://github.com/prajwal-kr-12/chat-application/blob/main/server.py): `server.py`
- [Client handler](https://github.com/prajwal-kr-12/chat-application/blob/main/server.py): `server.py`
- [Message broadcaster](https://github.com/prajwal-kr-12/chat-application/blob/main/server.py): `server.py`

### Other components

- **Terminal user**

## Connections

- Terminal user → TCP client connection: chooses nickname (evidence: `README.md`)
- TCP client connection → Accept and register: connects by TCP (evidence: `README.md`)
- Accept and register → Client registry: stores client (evidence: `server.py`)
- Accept and register → Client handler: starts thread (evidence: `server.py`)
- Accept and register → Message broadcaster: announces arrival (evidence: `server.py`)
- Terminal user → Write loop: types messages (evidence: `README.md`)
- Write loop → TCP client connection: sends messages (evidence: `client.py`)
- TCP client connection → Receive loop: receives data (evidence: `client.py`)
- Client handler → Message broadcaster: forwards messages (evidence: `server.py`)
- Message broadcaster → Client registry: reads recipients (evidence: `server.py`)
- Message broadcaster → TCP client connection: broadcasts messages (evidence: `README.md`)
- Message broadcaster → Client registry: removes failed clients (evidence: `server.py`)
