# anhdung2k1/chatbot-socket architecture

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

- Interactive diagram: https://gitdiagram.com/anhdung2k1/chatbot-socket
- Repository: https://github.com/anhdung2k1/chatbot-socket

## Overview

##### Project Type & Purpose
- The README and file structure indicate that this is a full-stack/multi-service application where the primary goal is to facilitate real-time chatbot interactions over socket connections.
- It provides authentication capabilities (via a dedicated “authentication” module) and implements client-server communication using Java socket programming – with clearly separated modules for the chatbot client and chatbot server.
- Docker and docker-compose are used for containerized deployment, meaning the different services can run in isolation, yet work together as one system.

##### File Structure for Key Components
- Authentication Module:
- Located in the “authentication” directory.
- Structured according to a layered architecture with separate packages for configuration, controllers (handling REST endpoints for user actions like sign-in/sign-up and questions/subject management), services (both interface definitions and concrete implementations), repositories (likely interfacing with a database), entities/models, and mappers.
- Security configuration elements (e.g., JwtAuthenticationFilter and JwtService) indicate the use of JWT-based security.
- Chatbot-Socket Components:
- “chatbot-socket-server” is the backend socket server. It contains the main server class, client handlers, and service classes that manage real-time socket connections.
- “chatbot-socket-client” contains the client application that likely incorporates a UI along with services to communicate with the server. It also includes UI components for signing in and signing up.
- Shared Components:
- The “pkg-common” directory holds common utilities and shared classes (such as constants, HTTP connectivity, logging, and patterns) that are used by both the server and client modules.
- Deployment & Configuration:
- docker-compose.yaml, Dockerfiles in some modules (e.g., authentication and chatbot-socket-server) and SQL files imply containerization and a defined database setup.

a. And Represent Main Components:
- Authentication Service (Spring Boot application) – show its layered structure (Controllers, Services, Repositories) and the use of JWT security.
- Chatbot Socket Server – include its main server component, socket handling (ClientHandler, SocketHandler), and service layer.
- Chatbot Socket Client – represent the client application, including the UI components (e.g., chat interface, SignInPage, SignUpPage) and client services.
- Shared Common Package – note that the pkg-common module provides utilities that support both the client and server.

b. Relationships & Interactions:
- If applicable, show that the Authentication Service might interact with a database backend.
- The pkg-common utility should be shown as a shared component influencing both the client and server module.

c. Architectural Patterns & Design Principles:
- Layered architecture in the authentication module (controllers, services, repositories).
- Separation of concerns: authentication logic is decoupled from the real-time socket communication.
- That Docker is used for container orchestration. You may include a “Docker Compose” block that groups the services, indicating which ones run in separate containers.

d. Technologies & Frameworks:
- Java and Spring Boot for the authentication module.
- Java socket programming (and possibly libraries over SocketIO) for the chatbot server and client.
- Maven as the build tool (as indicated by the pom.xml files).
- JWT-based security (visible from the configuration components).
- Docker and docker-compose for container setup.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Global Deployment Node
    DockerCompose["Docker Compose"]:::deployment
    click DockerCompose "https://github.com/anhdung2k1/chatbot-socket/blob/main/docker-compose.yaml"
    
    %% Containerized Backend Services
    AuthService["Authentication Service (Spring Boot)"]:::backend
    click AuthService "https://github.com/anhdung2k1/chatbot-socket/tree/main/authentication/"
    
    ChatbotServer["Chatbot Socket Server"]:::backend
    click ChatbotServer "https://github.com/anhdung2k1/chatbot-socket/tree/main/chatbot-socket-server/"
    
    %% Frontend Client Service
    ChatbotClient["Chatbot Socket Client"]:::frontend
    click ChatbotClient "https://github.com/anhdung2k1/chatbot-socket/tree/main/chatbot-socket-client/"
    
    %% Shared Utilities
    SharedCommon["Shared Common Utilities"]:::common
    click SharedCommon "https://github.com/anhdung2k1/chatbot-socket/tree/main/pkg-common/"
    
    %% Database Node
    Database["Database (SQL Schema)"]:::database
    click Database "https://github.com/anhdung2k1/chatbot-socket/blob/main/sql/chatbot.sql"
    
    %% Deployment Connections (Containerization)
    DockerCompose -->|"deploys"| AuthService
    DockerCompose -->|"deploys"| ChatbotServer
    DockerCompose -->|"deploys"| ChatbotClient
    
    %% Authentication Service Internal Layers
    AuthCtrl["Controllers"]:::backendLayer
    AuthSvc["Services"]:::backendLayer
    AuthRep["Repositories"]:::backendLayer
    
    AuthService -->|"layered"| AuthCtrl
    AuthCtrl -->|"delegatesTo"| AuthSvc
    AuthSvc -->|"calls"| AuthRep
    AuthRep -->|"persistsIn"| Database
    
    %% Chatbot Socket Server Internal Structure
    ServerMain["Main Server"]:::backendComponent
    ClientHandler["Client Handler"]:::backendComponent
    SocketHandler["Socket Handler"]:::backendComponent
    
    ChatbotServer -->|"details"| ServerMain
    ServerMain -->|"manages"| ClientHandler
    ServerMain -->|"manages"| SocketHandler
    ServerMain -->|"uses"| SharedCommon
    
    %% Chatbot Socket Client Internal Structure
    App["App.java"]:::frontendComponent
    UI["UI (SignIn/SignUp)"]:::frontendComponent
    ClientSvc["Client Services"]:::frontendComponent
    
    ChatbotClient -->|"entryPoint"| App
    App -->|"initializes"| UI
    App -->|"includes"| ClientSvc
    ClientSvc -->|"uses"| SharedCommon
    
    %% Inter-Service Communications
    UI -->|"REST_API"| AuthService
    UI -->|"socket_connects"| ServerMain

%% Styles
classDef backend fill:#ADD8E6,stroke:#000,stroke-width:1px;
classDef backendLayer fill:#87CEFA,stroke:#000,stroke-width:1px;
classDef backendComponent fill:#6495ED,stroke:#000,stroke-width:1px;
classDef frontend fill:#90EE90,stroke:#000,stroke-width:1px;
classDef frontendComponent fill:#98FB98,stroke:#000,stroke-width:1px;
classDef common fill:#FFD700,stroke:#000,stroke-width:1px;
classDef database fill:#FFB6C1,stroke:#000,stroke-dasharray: 5, 5,stroke-width:1px;
classDef deployment fill:#D3D3D3,stroke:#000,stroke-width:1px;
```
