# vytrg/chatroom architecture

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

- Interactive diagram: https://gitdiagram.com/vytrg/chatroom
- Repository: https://github.com/vytrg/chatroom

## Overview

##### Main Components

A. Frontend Layer:
- Static resources (HTML, CSS, JS)
- Templates (Thymeleaf views)
- WebSocket client connection

B. Backend Layer:
- Controllers Package
- Service Layer
- Repository Layer
- Model/Domain Layer
- Exception Handling

C. Database Layer:
- SQL Server
- Entity relationships

D. WebSocket Communication Layer:
- Real-time message handling
- Connection management

- [Client Tier] → [Application Tier] → [Data Tier]

##### Connection Flows

- Frontend → Controllers
- Controllers → Services
- Services → Repositories
- Repositories → Database

- WebSocket Client → WebSocket Server
- WebSocket Server → Message Broker

##### Additional Elements

- Exception Handling Layer:
- ApiExceptionHandler
- To all controller components

- Security Layer (if implemented):
- Authentication flow
- Authorization checks

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef frontend fill:#4299e1,stroke:#2b6cb0,color:white
    classDef backend fill:#48bb78,stroke:#2f855a,color:white
    classDef controller fill:#ecc94b,stroke:#d69e2e,color:black
    classDef database fill:#f56565,stroke:#c53030,color:white
    classDef websocket fill:#9f7aea,stroke:#6b46c1,color:white
    classDef service fill:#38b2ac,stroke:#2c7a7b,color:white
    classDef repository fill:#ed8936,stroke:#c05621,color:white
    classDef model fill:#667eea,stroke:#4c51bf,color:white
    classDef exception fill:#fc8181,stroke:#e53e3e,color:white

    subgraph Frontend
        StaticRes["Static Resources"]:::frontend
        Templates["Templates"]:::frontend
        WSClient["WebSocket Client"]:::websocket
    end

    subgraph Controllers
        HomeCtrl["Home Controller"]:::controller
        UserCtrl["User Controller"]:::controller
        ContactCtrl["Contact Controller"]:::controller
    end

    subgraph Services
        UserSvc["User Service"]:::service
        ContactSvc["Contact Service"]:::service
    end

    subgraph Repositories
        UserRepo["User Repository"]:::repository
        ContactRepo["Contact Repository"]:::repository
    end

    subgraph Models
        User["User"]:::model
        Message["Message"]:::model
        Conversation["Conversation"]:::model
        ContactWith["ContactWith"]:::model
        ConvMember["ConversationMember"]:::model
    end

    ExceptionHandler["API Exception Handler"]:::exception
    Database[(SQL Server)]:::database
    WSServer["WebSocket Server"]:::websocket

    %% Connections
    StaticRes --> HomeCtrl
    Templates --> HomeCtrl
    WSClient <--> WSServer

    HomeCtrl --> UserSvc
    UserCtrl --> UserSvc
    ContactCtrl --> ContactSvc

    UserSvc --> UserRepo
    ContactSvc --> ContactRepo

    UserRepo --> Database
    ContactRepo --> Database

    ExceptionHandler -.-> Controllers

    %% Click Events
    click StaticRes "https://github.com/vytrg/chatroom/tree/main/src/main/resources/static"
    click Templates "https://github.com/vytrg/chatroom/tree/main/src/main/resources/templates/view"
    click HomeCtrl "https://github.com/vytrg/chatroom/blob/main/src/main/java/com/example/chatroom/controller/HomeController.java"
    click UserCtrl "https://github.com/vytrg/chatroom/blob/main/src/main/java/com/example/chatroom/controller/UserController.java"
    click ContactCtrl "https://github.com/vytrg/chatroom/blob/main/src/main/java/com/example/chatroom/controller/ContactWithController.java"
    click UserSvc "https://github.com/vytrg/chatroom/blob/main/src/main/java/com/example/chatroom/service/UserService.java"
    click ContactSvc "https://github.com/vytrg/chatroom/blob/main/src/main/java/com/example/chatroom/service/ContactWithService.java"
    click UserRepo "https://github.com/vytrg/chatroom/blob/main/src/main/java/com/example/chatroom/repository/UserRepository.java"
    click ContactRepo "https://github.com/vytrg/chatroom/blob/main/src/main/java/com/example/chatroom/repository/ContactWithRepository.java"
    click User "https://github.com/vytrg/chatroom/blob/main/src/main/java/com/example/chatroom/model/User.java"
    click Message "https://github.com/vytrg/chatroom/blob/main/src/main/java/com/example/chatroom/model/Message.java"
    click Conversation "https://github.com/vytrg/chatroom/blob/main/src/main/java/com/example/chatroom/model/Conversation.java"
    click ContactWith "https://github.com/vytrg/chatroom/blob/main/src/main/java/com/example/chatroom/model/ContactWith.java"
    click ConvMember "https://github.com/vytrg/chatroom/blob/main/src/main/java/com/example/chatroom/model/ConversationMember.java"
    click ExceptionHandler "https://github.com/vytrg/chatroom/blob/main/src/main/java/com/example/chatroom/exception/ApiEceptionHandler.java"
    click Database "https://github.com/vytrg/chatroom/blob/main/dbscript/database.sql"

    %% Legend
    subgraph Legend
        Frontend_L["Frontend"]:::frontend
        Backend_L["Backend Service"]:::service
        Controller_L["Controller"]:::controller
        Database_L[(Database)]:::database
        WebSocket_L["WebSocket"]:::websocket
        Repository_L["Repository"]:::repository
        Model_L["Model"]:::model
        Exception_L["Exception Handler"]:::exception
    end
```
