# rayen03/swing-ai-chat architecture

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

- Interactive diagram: https://gitdiagram.com/rayen03/swing-ai-chat
- Repository: https://github.com/rayen03/swing-ai-chat

## Overview

##### Project type and purpose
- This is a Java-based full-stack chat application, composed of two Maven modules:
- client: a desktop UI client following an MVC pattern
- server: a backend providing authentication, session management, chat services, and persistence
- The goal is to let users log in, send/receive chat messages in real time, and persist chats and user data in a database.

##### File structure
- Top-level pom.xml ties together two submodules: client/ and server/.
- client/src/main/java/com/aichatapp/*
- views: ChatView, LoginView (UI layer)
- controllers: ClientController (handles user actions, serializes ChatMessage via GSON, calls network API)
- models: ChatMessage (data transfer object)
- server/src/main/java/com/aichatapp/*
- services: ChatService (broadcast and routing), UserService (auth, needs password hashing), SessionService (track active sessions)
- models: ChatMessage (shared DTO), DatabaseConnection (manages JDBC or ORM)
- Server.java: entry point that wires services, opens network endpoints (e.g. REST or socket listeners)
- Tests in both modules follow the same package layout.
- No Docker/Kubernetes manifests or external microservices—this is a monolithic server.

##### README for additional insights
- Notes on feature tasks: password hashing in UserService, GSON setup in ClientController, shared ChatMessage definition.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side
    subgraph "Client Side"
        direction TB
        App["App (Entry Point)"]:::client
        LoginView["LoginView"]:::client
        ChatView["ChatView"]:::client
        ClientController["ClientController"]:::client
        GSON["GSON Serializer"]:::client
        NetworkClient["NetworkClient"]:::client
        ChatMessageClient["ChatMessage DTO"]:::dto
    end

    %% Server Side
    subgraph "Server Side"
        direction TB
        ServerEntry["Server"]:::server
        UserService["UserService"]:::server
        SessionService["SessionService"]:::server
        ChatService["ChatService"]:::server
        DatabaseConnection["DatabaseConnection"]:::server
        Database["Database"]:::db
        ChatMessageServer["ChatMessage DTO"]:::dto
    end

    %% Client Flow
    App -->|starts UI| LoginView
    LoginView -->|user credentials| ClientController
    ClientController -->|serialize JSON| GSON
    GSON -->|JSON over HTTP/TCP| NetworkClient

    %% Server Flow - Auth
    NetworkClient -->|login request| ServerEntry
    ServerEntry -->|call| UserService
    UserService -->|query| DatabaseConnection
    DatabaseConnection -->|user data| UserService
    UserService -->|create session| SessionService
    SessionService -->|session token| ServerEntry
    ServerEntry -->|token response| NetworkClient
    NetworkClient -->|token| ClientController

    %% Chat Flow
    ClientController -->|ChatMessage JSON| GSON
    GSON -->|message payload| NetworkClient
    NetworkClient -->|chat request| ServerEntry
    ServerEntry -->|deserializes| ChatMessageServer
    ServerEntry -->|call| ChatService
    ChatService -->|check sessions| SessionService
    ChatService -->|persist message| DatabaseConnection
    ChatService -->|broadcast| ServerEntry
    ServerEntry -->|push JSON| NetworkClient
    NetworkClient -->|receive JSON| ClientController
    ClientController -->|update view| ChatView

    %% Shared DTO relationships
    ChatMessageClient ---|identical type| ChatMessageServer

    %% Click Events
    click LoginView "https://github.com/rayen03/swing-ai-chat/blob/main/client/src/main/java/com/aichatapp/views/LoginView.java"
    click ChatView "https://github.com/rayen03/swing-ai-chat/blob/main/client/src/main/java/com/aichatapp/views/ChatView.java"
    click ClientController "https://github.com/rayen03/swing-ai-chat/blob/main/client/src/main/java/com/aichatapp/controllers/ClientController.java"
    click App "https://github.com/rayen03/swing-ai-chat/blob/main/client/src/main/java/com/aichatapp/App.java"
    click ChatMessageClient "https://github.com/rayen03/swing-ai-chat/blob/main/client/src/main/java/com/aichatapp/models/ChatMessage.java"
    click ServerEntry "https://github.com/rayen03/swing-ai-chat/blob/main/server/src/main/java/com/aichatapp/Server.java"
    click ChatService "https://github.com/rayen03/swing-ai-chat/blob/main/server/src/main/java/com/aichatapp/services/ChatService.java"
    click UserService "https://github.com/rayen03/swing-ai-chat/blob/main/server/src/main/java/com/aichatapp/services/UserService.java"
    click SessionService "https://github.com/rayen03/swing-ai-chat/blob/main/server/src/main/java/com/aichatapp/services/SessionService.java"
    click DatabaseConnection "https://github.com/rayen03/swing-ai-chat/blob/main/server/src/main/java/com/aichatapp/models/DatabaseConnection.java"
    click ChatMessageServer "https://github.com/rayen03/swing-ai-chat/blob/main/server/src/main/java/com/aichatapp/models/ChatMessage.java"

    %% Styles
    classDef client fill:#D0E8FF,stroke:#0366d6,color:#000
    classDef server fill:#D0FFD0,stroke:#228B22,color:#000
    classDef db fill:#FFE0B2,stroke:#D2691E,color:#000
    classDef dto fill:#FFE0E0,stroke:#FF4500,color:#000
```
