# mazino2d/socket-chat architecture

> Architecture diagram of the GitHub repository mazino2d/socket-chat, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mazino2d/socket-chat
- Repository: https://github.com/mazino2d/socket-chat

## Overview

This project is a Java-based socket chat system that implements a client-server architecture for a computer networks course assignment at HCMUT. The application is divided into two main parts—the client and the server—with a shared protocol layer that handles data encoding/decoding and message structures. The project also includes graphical user interfaces (GUIs) for chatting, file browsing/sending, login, menus, and server control.

##### Main Components
- Client Application: Contains all the GUI components (ChatGUI, LoginGUI, MenuGUI, etc.) and the core chat functionalities (Chat, Menu) that interact with users.
- Server Application: Includes the server logic (Server, ServerGUI) that handles connections, message broadcast, and file transfers.
- Protocol Layer: Found in the “protocol” package, this layer is responsible for the encoding, decoding, and structuring of messages and file data (classes like Decode, Encode, FileData, Peer, and Tags).
- Testing Infrastructure: Although not part of the production flow, note that test classes are included (under src/test/java/kraken) to validate the protocol and possibly other system functionality.
- CI/CD & Deployment: Elements like the Dockerfile, Maven build files (pom.xml, client.xml, server.xml) as well as GitHub workflow configurations indicate an environment for continuous integration and container-based builds.

##### Relationships and Interactions
- How both client and server rely on the shared Protocol Layer to encode/decode messages.
- Annotations showing the communication flow to illustrate actions such as login, file transfer, and chat messaging.
- Testing Infrastructure as an environment used during development and CI/CD pipelines, even if it is auxiliary to the live system.

##### Important Architectural Patterns and Technologies
- Client-Server Communication: Emphasize that this is a real-time socket-based communication system.
- Layered Architecture: Represent the separation between the User Interface (GUI components) and the backend business logic.
- Use of Maven: Reflect how the build and dependency management is handled.
- Docker & CI/CD: Indicate that a Docker container can be built and that GitHub workflows are configured to support automated builds (pointed by the Dockerfile and the .github directory).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Runtime System Subgraph
    subgraph "Runtime System"
        A1["Client Application (Chat GUI & Core Chat)"]:::client
        A2["Protocol Layer (Encode/Decode, FileData, etc.)"]:::protocol
        A3["Server Application (Server Logic & GUI)"]:::server
        A1 -->|"sendsMessage"| A2
        A2 -->|"forwardsMessage"| A3
        A3 -->|"sendsResponse"| A2
        A2 -->|"forwardsResponse"| A1
    end

    %% DevOps & Testing Subgraph
    subgraph "DevOps & Testing"
        B1["Testing Infrastructure"]:::testing
        B2["CI/CD & Deployment"]:::cicd
    end

    %% Connections between DevOps and Runtime
    B2 ---|"buildsDeploysClient"| A1
    B2 ---|"buildsDeploysServer"| A3
    B1 ---|"validatesProtocol"| A2

    %% Click Events
    click A1 "https://github.com/mazino2d/socket-chat/tree/master/src/main/java/client"
    click A3 "https://github.com/mazino2d/socket-chat/tree/master/src/main/java/server"
    click A2 "https://github.com/mazino2d/socket-chat/tree/master/src/main/java/protocol"
    click B1 "https://github.com/mazino2d/socket-chat/tree/master/src/test/java/kraken"
    click B2 "https://github.com/mazino2d/socket-chat/tree/master/Dockerfile"

    %% Styles
    classDef client fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef server fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef protocol fill:#ffa500,stroke:#000,stroke-width:2px;
    classDef testing fill:#ffb6c1,stroke:#000,stroke-width:2px;
    classDef cicd fill:#d3d3d3,stroke:#000,stroke-width:2px;
```
