# conghung2302/caro architecture

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

- Interactive diagram: https://gitdiagram.com/conghung2302/caro
- Repository: https://github.com/conghung2302/caro

## Overview

##### Project type and purpose
- This is a Java-based networked multiplayer Caro (Gomoku) game with a standalone GUI client and a headless server.
- The client handles user interaction, rendering, AI, and voice chat. The server manages game rooms, matchmaking, persistence (MySQL), and voice-chat coordination (via Cling UPnP).

##### File structure
Top-level:
- Caro – Client — NetBeans project containing:
– src/… — packages AIGame (game engine + Minimax AI), Core (network protocol, JSON via Gson), Interface & Swing (UI forms), Assets (images/sounds), DropIcon/sweet_alert/sample (UI widgets)
– test/VoiceChat — standalone voice-chat client/server tests
– build.xml, nbproject/… — build definitions
– dist/… — packaged jars and dependency libs (TimingFramework, Gson, MigLayout)
- Caro – Server — NetBeans project containing:
– src/Core — ServerManager, Room, User, DBConnect (MySQL), VoiceChatServer
– src/Interface — Swing-based server control panel
– src/VoiceCOre — low-level voice chat using Cling (UPnP)
– lib/… — Cling jars, MySQL connector, TimingFramework
– build.xml, nbproject/…

Other files:
- carogame.sql, tictactoe.sql — schema scripts
- README.md — quick start: run server.jar then client.jar

##### README
- Confirms a simple deploy: unzip, cd to ./dist, launch server.jar, then client.jar, then PLAY.

##### Detail without overthinking
- Every package as a sub-component under its main module.
- External JAR dependencies only if they affect cross-component data flow (e.g., Gson, Cling).
- Reader can trace: “When user clicks → which class handles → which JSON message → which server class → which DB table.”

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Application Swimlane
    subgraph "Client Application"
        direction TB
        subgraph "UI Layer" 
            direction TB
            Interface["UI Layer"]:::client
            Swing["Swing Components"]:::client
            DropIcon["DropIcon Widgets"]:::client
            sample["Sample Widgets"]:::client
            sweet_alert["SweetAlert Dialogs"]:::client
        end
        GameEngine["Game Engine (AIGame + Minimax)"]:::client
        NetworkClient["Network Manager (ClientManager)"]:::client
        subgraph "Network Messages & Codes"
            ActionTypeC["ActionType"]:::client
            ResultC["Result"]:::client
            ResultCodeC["ResultCode"]:::client
        end
        VoiceChatClient["VoiceChatClient"]:::client
        AssetManager["Asset Manager"]:::client
    end

    %% Server Application Swimlane
    subgraph "Server Application"
        direction TB
        NetworkServer["Network Manager (ServerManager)"]:::server
        subgraph "Network Messages & Codes (Server)"
            ActionTypeS["ActionType"]:::server
            ResultCodeS["ResultCode"]:::server
        end
        subgraph "Room / Match Manager"
            Room["Room"]:::server
            User["User"]:::server
        end
        DBConnect["DBConnect (MySQL)"]:::server
        subgraph "Voice Chat Server"
            VoiceChatServer["VoiceChatServer"]:::server
            VoiceCOre["VoiceCOre"]:::server
        end
        subgraph "Admin UI"
            ServerForm["Server.form & Server.java"]:::server
            ServerGame["ServerGame"]:::server
        end
    end

    %% External Systems
    subgraph "External Systems"
        direction TB
        MySQL["MySQL Database"]:::external
        UPnP["UPnP / NAT Traversal (Cling)"]:::external
        TimingClient["TimingFramework (Client)"]:::external
        TimingServer["TimingFramework (Server)"]:::external
    end

    %% Relationships
    Interface -->|user input| GameEngine
    Swing -->|renders| GameEngine
    GameEngine -->|game state JSON| NetworkClient
    NetworkClient -->|sends JSON| NetworkServer
    NetworkServer -->|dispatches| Room
    Room --> User
    Room -->|match data| NetworkServer
    NetworkServer -->|queries| DBConnect
    DBConnect -->|SQL queries| MySQL
    NetworkServer -->|responses| NetworkClient
    NetworkClient -->|board updates| GameEngine
    VoiceChatClient <-->|voice packets| VoiceChatServer
    VoiceCOre -->|UPnP coordination| UPnP
    VoiceChatClient -->|UPnP coordination| UPnP
    AssetManager -->|media assets| Interface
    TimingClient -->|schedules| GameEngine
    TimingServer -->|schedules| NetworkServer

    %% Click Events for Client
    click Interface "https://github.com/conghung2302/caro/tree/main/Caro - Client/src/Interface"
    click Swing "https://github.com/conghung2302/caro/tree/main/Caro - Client/src/Swing"
    click DropIcon "https://github.com/conghung2302/caro/tree/main/Caro - Client/src/DropIcon"
    click sample "https://github.com/conghung2302/caro/tree/main/Caro - Client/src/sample"
    click sweet_alert "https://github.com/conghung2302/caro/tree/main/Caro - Client/src/sweet_alert"
    click GameEngine "https://github.com/conghung2302/caro/tree/main/Caro - Client/src/AIGame"
    click NetworkClient "https://github.com/conghung2302/caro/blob/main/Caro - Client/src/Core/ClientManager.java"
    click ActionTypeC "https://github.com/conghung2302/caro/blob/main/Caro - Client/src/Core/ActionType.java"
    click ResultC "https://github.com/conghung2302/caro/blob/main/Caro - Client/src/Core/Result.java"
    click ResultCodeC "https://github.com/conghung2302/caro/blob/main/Caro - Client/src/Core/ResultCode.java"
    click VoiceChatClient "https://github.com/conghung2302/caro/blob/main/Caro - Client/src/Core/VoiceChatClient.java"
    click AssetManager "https://github.com/conghung2302/caro/tree/main/Caro - Client/src/Assets"

    %% Click Events for Server
    click NetworkServer "https://github.com/conghung2302/caro/blob/main/Caro - Server/src/Core/ServerManager.java"
    click ActionTypeS "https://github.com/conghung2302/caro/blob/main/Caro - Server/src/Core/ActionType.java"
    click ResultCodeS "https://github.com/conghung2302/caro/blob/main/Caro - Server/src/Core/ResultCode.java"
    click Room "https://github.com/conghung2302/caro/blob/main/Caro - Server/src/Core/Room.java"
    click User "https://github.com/conghung2302/caro/blob/main/Caro - Server/src/Core/User.java"
    click DBConnect "https://github.com/conghung2302/caro/blob/main/Caro - Server/src/Core/DBConnect.java"
    click VoiceChatServer "https://github.com/conghung2302/caro/blob/main/Caro - Server/src/Core/VoiceChatServer.java"
    click VoiceCOre "https://github.com/conghung2302/caro/tree/main/Caro - Server/src/VoiceCOre"
    click ServerForm "https://github.com/conghung2302/caro/blob/main/Caro - Server/src/Interface/Server.form"
    click ServerForm "https://github.com/conghung2302/caro/blob/main/Caro - Server/src/Interface/Server.java"
    click ServerGame "https://github.com/conghung2302/caro/blob/main/Caro - Server/src/Interface/ServerGame.java"

    %% Styles
    classDef client fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef server fill:#d4edda,stroke:#333,stroke-width:1px
    classDef external fill:#e2e3e5,stroke:#333,stroke-width:1px
```
