# hugbrl09/chat-tcp-multiusuario architecture

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

- Interactive diagram: https://gitdiagram.com/hugbrl09/chat-tcp-multiusuario
- Repository: https://github.com/hugbrl09/chat-tcp-multiusuario

## Overview

This is a Java Swing multi-user TCP chat with a central server for nickname login, presence, public/private messages, and P2P file-transfer signaling; file bytes travel directly between clients. The workflow is connect and log in, exchange chat or presence updates through the server, then optionally negotiate and accept a direct file transfer. Server concurrency and its synchronized client registry are shown as an internal layer. Edges reflect excerpts or README claims; the receiver-side P2P socket details are not sampled.

Main entry points: [`ChatTCPCliente/src/main/java/com/mycompany/chattcpcliente/TelaChat.java`](https://github.com/hugbrl09/chat-tcp-multiusuario/blob/main/ChatTCPCliente/src/main/java/com/mycompany/chattcpcliente/TelaChat.java) (Chat interface), [`ChatTCPServidor/src/main/java/com/mycompany/chattcpservidor/ServidorChatApp.java`](https://github.com/hugbrl09/chat-tcp-multiusuario/blob/main/ChatTCPServidor/src/main/java/com/mycompany/chattcpservidor/ServidorChatApp.java) (TCP acceptor and pool), [`ChatTCPServidor/src/main/java/com/mycompany/chattcpservidor/ThreadCliente.java`](https://github.com/hugbrl09/chat-tcp-multiusuario/blob/main/ChatTCPServidor/src/main/java/com/mycompany/chattcpservidor/ThreadCliente.java) (Per-client protocol handler), [`ChatTCPCliente/src/main/java/com/mycompany/chattcpcliente/ServidorArquivoP2P.java`](https://github.com/hugbrl09/chat-tcp-multiusuario/blob/main/ChatTCPCliente/src/main/java/com/mycompany/chattcpcliente/ServidorArquivoP2P.java) (Temporary file sender)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Swing Client"]
  node_ui["Chat interface<br/>[TelaChat.java]"]
  node_client_socket["Chat TCP connection<br/>[TelaChat.java]"]
end

subgraph group_server["Central Chat Server"]
  node_server_app["TCP acceptor and pool"]
  node_client_worker["Per-client protocol handler<br/>[ThreadCliente.java]"]
  node_registry[("Active client registry")]
end

subgraph group_protocol["Message Protocol"]
  node_client_msg["Client message DTO<br/>[Mensagem.java]"]
  node_server_msg["Server message DTO<br/>[Mensagem.java]"]
end

subgraph group_p2p["Direct File Transfer"]
  node_p2p_sender["Temporary file sender"]
  node_p2p_receiver["File recipient<br/>[TelaChat.java]"]
end

node_user(("Chat user"))
node_peer(("Other chat participant"))
node_central_server["Chat server service"]

node_user -->|"uses"| node_ui
node_ui -->|"creates and encodes"| node_client_msg
node_ui -->|"sends chat commands"| node_client_socket
node_client_socket -->|"opens TCP connection"| node_server_app
node_server_app -->|"dispatches clients"| node_client_worker
node_client_worker -->|"decodes and encodes"| node_server_msg
node_client_worker -->|"manages presence and routing"| node_registry
node_server_app -->|"listens for clients"| node_central_server
node_central_server -.->|"returns chat updates"| node_client_socket
node_ui -->|"starts file sender"| node_p2p_sender
node_ui -->|"signals transfer invitation"| node_central_server
node_central_server -->|"forwards invitation"| node_peer
node_peer -->|"accepts or refuses"| node_p2p_receiver
node_p2p_receiver -.->|"connects directly"| node_p2p_sender

click node_ui "https://github.com/hugbrl09/chat-tcp-multiusuario/blob/main/ChatTCPCliente/src/main/java/com/mycompany/chattcpcliente/TelaChat.java"
click node_client_msg "https://github.com/hugbrl09/chat-tcp-multiusuario/blob/main/ChatTCPCliente/src/main/java/com/mycompany/chattcpcliente/Mensagem.java"
click node_client_socket "https://github.com/hugbrl09/chat-tcp-multiusuario/blob/main/ChatTCPCliente/src/main/java/com/mycompany/chattcpcliente/TelaChat.java"
click node_server_app "https://github.com/hugbrl09/chat-tcp-multiusuario/blob/main/ChatTCPServidor/src/main/java/com/mycompany/chattcpservidor/ServidorChatApp.java"
click node_client_worker "https://github.com/hugbrl09/chat-tcp-multiusuario/blob/main/ChatTCPServidor/src/main/java/com/mycompany/chattcpservidor/ThreadCliente.java"
click node_registry "https://github.com/hugbrl09/chat-tcp-multiusuario/blob/main/ChatTCPServidor/src/main/java/com/mycompany/chattcpservidor/GerenciadorClientes.java"
click node_server_msg "https://github.com/hugbrl09/chat-tcp-multiusuario/blob/main/ChatTCPServidor/src/main/java/com/mycompany/chattcpservidor/Mensagem.java"
click node_p2p_sender "https://github.com/hugbrl09/chat-tcp-multiusuario/blob/main/ChatTCPCliente/src/main/java/com/mycompany/chattcpcliente/ServidorArquivoP2P.java"
click node_p2p_receiver "https://github.com/hugbrl09/chat-tcp-multiusuario/blob/main/ChatTCPCliente/src/main/java/com/mycompany/chattcpcliente/TelaChat.java"

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_ui,node_client_socket,node_user toneBlue
class node_server_app,node_client_worker,node_registry toneAmber
class node_client_msg,node_server_msg,node_central_server toneMint
class node_p2p_sender,node_p2p_receiver toneRose
class node_peer toneIndigo
```

## Components

### Swing Client

- [Chat interface](https://github.com/hugbrl09/chat-tcp-multiusuario/blob/main/ChatTCPCliente/src/main/java/com/mycompany/chattcpcliente/TelaChat.java): `ChatTCPCliente/src/main/java/com/mycompany/chattcpcliente/TelaChat.java`
- [Chat TCP connection](https://github.com/hugbrl09/chat-tcp-multiusuario/blob/main/ChatTCPCliente/src/main/java/com/mycompany/chattcpcliente/TelaChat.java): `ChatTCPCliente/src/main/java/com/mycompany/chattcpcliente/TelaChat.java`

### Central Chat Server

- [TCP acceptor and pool](https://github.com/hugbrl09/chat-tcp-multiusuario/blob/main/ChatTCPServidor/src/main/java/com/mycompany/chattcpservidor/ServidorChatApp.java): `ChatTCPServidor/src/main/java/com/mycompany/chattcpservidor/ServidorChatApp.java`
- [Per-client protocol handler](https://github.com/hugbrl09/chat-tcp-multiusuario/blob/main/ChatTCPServidor/src/main/java/com/mycompany/chattcpservidor/ThreadCliente.java): `ChatTCPServidor/src/main/java/com/mycompany/chattcpservidor/ThreadCliente.java`
- [Active client registry](https://github.com/hugbrl09/chat-tcp-multiusuario/blob/main/ChatTCPServidor/src/main/java/com/mycompany/chattcpservidor/GerenciadorClientes.java): `ChatTCPServidor/src/main/java/com/mycompany/chattcpservidor/GerenciadorClientes.java`

### Message Protocol

- [Client message DTO](https://github.com/hugbrl09/chat-tcp-multiusuario/blob/main/ChatTCPCliente/src/main/java/com/mycompany/chattcpcliente/Mensagem.java): `ChatTCPCliente/src/main/java/com/mycompany/chattcpcliente/Mensagem.java`
- [Server message DTO](https://github.com/hugbrl09/chat-tcp-multiusuario/blob/main/ChatTCPServidor/src/main/java/com/mycompany/chattcpservidor/Mensagem.java): `ChatTCPServidor/src/main/java/com/mycompany/chattcpservidor/Mensagem.java`

### Direct File Transfer

- [Temporary file sender](https://github.com/hugbrl09/chat-tcp-multiusuario/blob/main/ChatTCPCliente/src/main/java/com/mycompany/chattcpcliente/ServidorArquivoP2P.java): `ChatTCPCliente/src/main/java/com/mycompany/chattcpcliente/ServidorArquivoP2P.java`
- [File recipient](https://github.com/hugbrl09/chat-tcp-multiusuario/blob/main/ChatTCPCliente/src/main/java/com/mycompany/chattcpcliente/TelaChat.java): `ChatTCPCliente/src/main/java/com/mycompany/chattcpcliente/TelaChat.java`

### Other components

- **Chat user**
- **Other chat participant**
- **Chat server service**

## Connections

- Chat user → Chat interface: uses (evidence: `README.md`)
- Chat interface → Client message DTO: creates and encodes (evidence: `ChatTCPCliente/src/main/java/com/mycompany/chattcpcliente/TelaChat.java`)
- Chat interface → Chat TCP connection: sends chat commands (evidence: `ChatTCPCliente/src/main/java/com/mycompany/chattcpcliente/TelaChat.java`)
- Chat TCP connection → TCP acceptor and pool: opens TCP connection (evidence: `README.md`)
- TCP acceptor and pool → Per-client protocol handler: dispatches clients (evidence: `ChatTCPServidor/src/main/java/com/mycompany/chattcpservidor/ServidorChatApp.java`)
- Per-client protocol handler → Server message DTO: decodes and encodes (evidence: `ChatTCPServidor/src/main/java/com/mycompany/chattcpservidor/ThreadCliente.java`)
- Per-client protocol handler → Active client registry: manages presence and routing (evidence: `ChatTCPServidor/src/main/java/com/mycompany/chattcpservidor/ThreadCliente.java`)
- TCP acceptor and pool → Chat server service: listens for clients (evidence: `ChatTCPServidor/src/main/java/com/mycompany/chattcpservidor/ServidorChatApp.java`)
- Chat server service → Chat TCP connection: returns chat updates (evidence: `README.md`)
- Chat interface → Temporary file sender: starts file sender (evidence: `ChatTCPCliente/src/main/java/com/mycompany/chattcpcliente/TelaChat.java`)
- Chat interface → Chat server service: signals transfer invitation (evidence: `README.md`)
- Chat server service → Other chat participant: forwards invitation (evidence: `README.md`)
- Other chat participant → File recipient: accepts or refuses (evidence: `ChatTCPCliente/src/main/java/com/mycompany/chattcpcliente/TelaChat.java`)
- File recipient → Temporary file sender: connects directly (evidence: `README.md`)
