# nguyenmanhcuong-huster/chat-application-using-sockets architecture

> Architecture diagram of the GitHub repository nguyenmanhcuong-huster/chat-application-using-sockets, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nguyenmanhcuong-huster/chat-application-using-sockets
- Repository: https://github.com/nguyenmanhcuong-huster/chat-application-using-sockets

## Overview

##### Project type and purpose
- This is a simple Java‐based chat application built with two separate modules:
- ClientApp – a Swing GUI that connects to a chat server over TCP sockets
- ServerApp – a headless server that accepts socket connections and broadcasts messages
- The README (“Chat‐application‐using‐sockets”) confirms it’s a socket‐based real-time messaging tool.

##### File structure
- Top‐level directories:
- ClientApp/ – contains NetBeans project for the client GUI
- ServerApp/ – contains NetBeans project for the server
- Under each:
- src/ – Java source (e.g. ClientApp.java, ChatServer.java, ClientHandler.java)
- nbproject/ & build.xml – NetBeans and Ant build scripts
- dist/ – compiled JARs and libs (AbsoluteLayout.jar for GUI layout)
- No persistence layer, no external services—pure client/server over TCP.

##### README for additional insights
- Client launches a Swing WindowClient, uses ClientListener to read from socket
- Server launches ChatServer on a port, spins off ClientHandler per connection

a. Main components:
– ClientApp GUI
– ClientListener (message‐send/receive logic)
– TCP Socket (network link)
– ChatServer (listener/thread acceptor)
– ClientHandler threads (per‐client message broker)
b. Relationships and interactions:
– User types text in GUI → ClientListener sends via Socket → ChatServer.accept()
– ChatServer hands socket to new ClientHandler → broadcasts to all other handlers → data travels back over TCP → ClientListener updates GUI
c. Architectural patterns/design principles:
– 1:N server threading model (listener + per‐client handler threads)
– MVC-style separation in ClientApp (WindowClient as View/Controller, ClientListener as Model/network layer)
– Single responsibility (ChatServer only accepts connections; ClientHandler only routes messages)
d. Key technologies/frameworks:
– Java SE 8+ (java.net.Socket, java.net.ServerSocket)
– Swing for GUI (WindowClient.form, AbsoluteLayout.jar)
– Ant/NetBeans build scripts

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Client Side"
        WindowClient["WindowClient\n(View/Controller)"]:::client
        WindowClientForm["WindowClient.form\n(GUI Layout)"]:::client
        ClientListener["ClientListener\n(Network I/O)"]:::client
        ClientAppMain["ClientApp\n(Application Launcher)"]:::client
    end

    subgraph "Network Layer"
        Socket["TCP Socket\n(port 12345)"]:::network
    end

    subgraph "Server Side"
        ServerAppMain["ServerApp\n(Application Launcher)"]:::server
        ChatServer["ChatServer\n(Main Listener)"]:::server
        ClientHandlerPool["ClientHandler\n(per-client Thread)"]:::server
    end

    ClientAppMain -->|"launch()"| WindowClient
    WindowClient -->|"userInput"| ClientListener
    ClientListener -->|"sendMessage()"| Socket
    Socket -->|"accept()"| ChatServer
    ChatServer -->|"spawn()"| ClientHandlerPool
    ClientHandlerPool -->|"broadcast(msg)"| Socket
    Socket -->|"receive()"| ClientListener
    ClientListener -->|"updateGUI()"| WindowClient

    click WindowClient "https://github.com/nguyenmanhcuong-huster/chat-application-using-sockets/blob/main/ClientApp/src/clientapp/WindowClient.java"
    click WindowClientForm "https://github.com/nguyenmanhcuong-huster/chat-application-using-sockets/blob/main/ClientApp/src/clientapp/WindowClient.form"
    click ClientListener "https://github.com/nguyenmanhcuong-huster/chat-application-using-sockets/blob/main/ClientApp/src/clientapp/ClientListener.java"
    click ClientAppMain "https://github.com/nguyenmanhcuong-huster/chat-application-using-sockets/blob/main/ClientApp/src/clientapp/ClientApp.java"
    click ChatServer "https://github.com/nguyenmanhcuong-huster/chat-application-using-sockets/blob/main/ServerApp/src/serverapp/ChatServer.java"
    click ClientHandlerPool "https://github.com/nguyenmanhcuong-huster/chat-application-using-sockets/blob/main/ServerApp/src/serverapp/ClientHandler.java"
    click ServerAppMain "https://github.com/nguyenmanhcuong-huster/chat-application-using-sockets/blob/main/ServerApp/src/serverapp/ServerApp.java"

    classDef client fill:#D0E8FF,stroke:#0055AA,stroke-width:1px
    classDef server fill:#D0FFD0,stroke:#339933,stroke-width:1px
    classDef network fill:#EEEEEE,stroke:#666666,stroke-width:1px
```
