# neiserdeveloper/ms-chat-socket architecture

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

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

## Overview

##### Project Type and Purpose
- This is a standalone chat microservice exposing WebSocket endpoints for real-time messaging.
- It does not include a UI, but rather assumes external clients (web, mobile) will open WebSocket connections.
- The core capabilities: configure WebSocket handshake, accept/route chat messages via a simple broker, and push messages back to subscribers.

##### File Structure
- src/main/java/com/chat/socket/MsChatSocketApplication.java – Spring Boot entry point.
- configuration/WebSocketConfiguration.java – sets up STOMP/WebSocket endpoints and message broker.
- controller/WebSocketController.java – @MessageMapping handlers that receive and broadcast ChatMessage DTOs.
- dto/ChatMessage.java – the domain model for each chat payload.
- application.properties – broker configuration (e.g. destination prefixes, allowed origins).
- No persistence layer or external broker libraries shown, so likely using Spring’s in-memory broker.

##### README for Additional Insights
- Describes the project as a “Microservicio chat con Websocket en JAVA 17 con Spring Boot.”
- Focus is on a single microservice that uses Spring WebSocket support for real-time chat.

##### Main Components and Their Interactions
a. Clients (Web or Mobile)
– Connect via WebSocket (STOMP) to the chat endpoint.
b. API Gateway / Load Balancer (optional for production)
– Routes incoming WebSocket handshake requests to one of the service instances.
c. MsChatSocket Microservice
– WebSocket Configuration Component
- Exposes STOMP endpoint (e.g., `/ws-chat`)
- Configures message broker (in-memory or external)
– WebSocket Controller
- Listens on application destinations (e.g., `/app/chat.send`)
- Broadcasts to subscriptions (e.g., `/topic/public`)
– ChatMessage DTO
- Defines the payload schema for chat events.
d. Message Broker
– In-memory (Spring’s SimpleBroker) or external (RabbitMQ, Redis)
– Routes messages between publisher (controller) and subscribers (clients).
e. Monitoring / Logging (optional)
– Spring Actuator, logs for health, metrics, and trace.

##### Architectural Patterns & Principles
- Microservice — single responsibility (real-time chat).
- Event-driven / Pub-Sub — clients subscribe to topics; controller publishes events.
- Layered design — configuration, controller, DTO layers.
- Scalability — stateless service instances managed behind a load balancer.

- Clear component names and roles.
– Connection setup (WebSocket handshake).
– Message publish and broadcast paths.
– External actors (clients, LB)
– Service internals (config, controller, DTO)
– Infrastructure (broker)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Actors
    Clients["Clients (Web/Mobile)"]:::external
    LoadBalancer["API Gateway / Load Balancer"]:::external

    %% Infrastructure
    SimpleBroker["Spring SimpleBroker\n(in-memory Message Broker)"]:::broker

    %% Service Group
    subgraph "MsChatSocket Microservice"
        direction TB
        App["MsChatSocketApplication"]:::service
        WSConfig["WebSocketConfiguration"]:::service
        WSController["WebSocketController"]:::service
        ChatDTO["ChatMessage DTO"]:::service
        AppProps["application.properties"]:::service
    end

    %% Connections
    Clients -->|"STOMP connect (WebSocket handshake)"| LoadBalancer
    LoadBalancer -->|"routes to endpoint"| WSConfig
    WSConfig -->|"registers STOMP endpoint\n(/ws-chat)"| App
    WSConfig -->|"configures broker"| SimpleBroker
    WSConfig -->|"wires message mappings"| WSController
    WSController -->|"onMessage (/app/chat.send)"| SimpleBroker
    SimpleBroker -->|"broadcast (/topic/public)"| WSController
    WSController -->|"push messages"| Clients

    %% Click Events
    click App "https://github.com/neiserdeveloper/ms-chat-socket/blob/master/src/main/java/com/chat/socket/MsChatSocketApplication.java"
    click WSConfig "https://github.com/neiserdeveloper/ms-chat-socket/blob/master/src/main/java/com/chat/socket/configuration/WebSocketConfiguration.java"
    click WSController "https://github.com/neiserdeveloper/ms-chat-socket/blob/master/src/main/java/com/chat/socket/controller/WebSocketController.java"
    click ChatDTO "https://github.com/neiserdeveloper/ms-chat-socket/blob/master/src/main/java/com/chat/socket/dto/ChatMessage.java"
    click AppProps "https://github.com/neiserdeveloper/ms-chat-socket/blob/master/src/main/resources/application.properties"
    click Tests "https://github.com/neiserdeveloper/ms-chat-socket/blob/master/src/test/java/com/chat/socket/MsChatSocketApplicationTests.java"
    click README "https://github.com/neiserdeveloper/ms-chat-socket/blob/master/README.md"
    click POM "https://github.com/neiserdeveloper/ms-chat-socket/blob/master/pom.xml"

    %% Styles
    classDef external fill:#add8e6,stroke:#000,stroke-width:1px
    classDef service fill:#90ee90,stroke:#000,stroke-width:1px
    classDef broker fill:#ffcc99,stroke:#000,stroke-width:1px
```
