# nitesh6gg/hashtag-chat-application architecture

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

- Interactive diagram: https://gitdiagram.com/nitesh6gg/hashtag-chat-application
- Repository: https://github.com/nitesh6gg/hashtag-chat-application

## Overview

##### Project Type and Purpose
- This is a full‑stack real‑time chat application named “workChat.”
- Backend: Java Spring Boot application exposing REST endpoints for authentication, user management, message history, plus a WebSocket endpoint for real‑time chat.
- Frontend: Angular Single‑Page Application (SPA) in the `ui/` directory, using an API service for REST calls and a WebSocket service for live message streaming.

##### Key Directories & Components
- Backend (`src/main/java/com/workchat`)
- config/
– WebSocketConfig: registers WebSocket endpoint
– WebConfig: general MVC / CORS settings
– ChatWebSocketHandler & WebSocketSessionManager: manage socket sessions & broadcast
- controller/
– AuthController, UserController, ChatController: expose REST resources
- service & serviceImpl/
– AuthService, UserService, MessageService + their Impl classes
– CustomPasswordEncoder (and Impl)
- repository/
– UserRepository, MessageRepository (Spring Data JPA)
- entity/
– User, Message
- dto/ & globalResponse/
– carry request/response payloads
- resources/application.properties: DB & app configuration
- Frontend (`ui/`)
- src/app/components: login, main (chatsection, userlist)
- src/app/services
– apiService: handles REST calls (login, fetch users/messages)
– webSocketService: opens WebSocket, handles incoming/outgoing chat messages
- server.ts (for SSR or dev proxy), angular.json, tailwind.config.js, etc.

##### Interactions & Data Flows
- User opens SPA → served by either static‑file server (could be Spring Boot or separate Node)
- On login: Angular apiService → HTTP POST /auth/login → AuthController → AuthService → UserRepository → DB
- On joining chat: Angular webSocketService connects to ws://…/chat endpoint → ChatWebSocketHandler
- Sending a message: Angular sends over WebSocket → handler ↔ MessageService → MessageRepository → persist → broadcast to sessions via WebSocketSessionManager → other clients’ webSocketService
- Fetch history/userlist: Angular apiService → UserController/ChatController → services → repositories → DB → response JSON

##### Architectural Patterns & Design Principles
- Layered architecture (Controller → Service → Repository)
- Separation of concerns: config, controller, service, repository, entity, DTO/response
- Event‑driven messaging for real‑time chat via WebSocket
- SPA on frontend with clearly separated REST vs. WebSocket concerns
- Dependency injection (Spring) and inversion of control

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Frontend (Angular SPA)"
        Angular["Angular SPA"]:::frontend
        apiService["apiService"]:::frontend
        webSocketService["webSocketService"]:::frontend
        loginComponent["Login Component"]:::frontend
        mainComponent["Main Component"]:::frontend
        chatSection["Chat Section"]:::frontend
        userList["User List"]:::frontend
    end

    subgraph "Backend (Spring Boot)"
        subgraph "Config Layer"
            WebConfig["WebConfig"]:::backend
            WebSocketConfig["WebSocketConfig"]:::backend
            ChatWebSocketHandler["ChatWebSocketHandler"]:::realtime
            WebSocketSessionManager["WebSocketSessionManager"]:::realtime
        end
        subgraph "Controller Layer"
            AuthController["AuthController"]:::backend
            UserController["UserController"]:::backend
            ChatController["ChatController"]:::backend
        end
        subgraph "Service Layer"
            AuthService["AuthService"]:::backend
            AuthServiceImpl["AuthServiceImpl"]:::backend
            UserService["UserService"]:::backend
            UserServiceImpl["UserServiceImpl"]:::backend
            MessageService["MessageService"]:::backend
            MessageServiceImpl["MessageServiceImpl"]:::backend
            CustomPasswordEncoder["CustomPasswordEncoder"]:::backend
            CustomPasswordEncoderImpl["CustomPasswordEncoderImpl"]:::backend
        end
        subgraph "Repository Layer"
            UserRepository["UserRepository"]:::backend
            MessageRepository["MessageRepository"]:::backend
        end
        subgraph "Entity/DTO Layer"
            UserEntity["User"]:::backend
            MessageEntity["Message"]:::backend
            LoginDto["LoginDto"]:::backend
            UserDto["UserDto"]:::backend
            LoginResponse["LoginResponse"]:::backend
            MessageResponse["MessageResponse"]:::backend
        end
        ApplicationProps["application.properties"]:::backend
    end

    Database[(Database)]:::db

    %% REST flows
    Angular -->|"REST Calls"| apiService
    apiService -->|"POST /auth/login"| AuthController
    apiService -->|"GET /users"| UserController
    apiService -->|"GET /messages"| ChatController
    AuthController --> AuthService
    UserController --> UserService
    ChatController --> MessageService
    AuthService --> UserRepository
    UserService --> UserRepository
    MessageService --> MessageRepository
    UserRepository --> Database
    MessageRepository --> Database

    %% WebSocket flows
    Angular -->|"WS Connect"| webSocketService
    webSocketService -->|"ws://.../chat"| ChatWebSocketHandler
    ChatWebSocketHandler --> WebSocketSessionManager
    ChatWebSocketHandler --> MessageService
    MessageService --> MessageRepository
    WebSocketSessionManager --> webSocketService

    %% Static asset serving
    Angular -->|"Serve SPA"| ApplicationProps

    %% Click Events
    click WebSocketConfig "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/src/main/java/com/workchat/config/WebSocketConfig.java"
    click WebConfig "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/src/main/java/com/workchat/config/WebConfig.java"
    click ChatWebSocketHandler "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/src/main/java/com/workchat/config/ChatWebSocketHandler.java"
    click WebSocketSessionManager "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/src/main/java/com/workchat/config/WebSocketSessionManager.java"
    click AuthController "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/src/main/java/com/workchat/controller/AuthController.java"
    click UserController "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/src/main/java/com/workchat/controller/UserController.java"
    click ChatController "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/src/main/java/com/workchat/controller/ChatController.java"
    click AuthService "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/src/main/java/com/workchat/service/AuthService.java"
    click AuthServiceImpl "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/src/main/java/com/workchat/serviceImpl/AuthServiceImpl.java"
    click UserService "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/src/main/java/com/workchat/service/UserService.java"
    click UserServiceImpl "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/src/main/java/com/workchat/serviceImpl/UserServiceImpl.java"
    click MessageService "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/src/main/java/com/workchat/service/MessageService.java"
    click MessageServiceImpl "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/src/main/java/com/workchat/serviceImpl/MessageServiceImpl.java"
    click CustomPasswordEncoder "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/src/main/java/com/workchat/service/CustomPasswordEncoder.java"
    click CustomPasswordEncoderImpl "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/src/main/java/com/workchat/serviceImpl/CustomPasswordEncoderImpl.java"
    click UserRepository "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/src/main/java/com/workchat/repository/UserRepository.java"
    click MessageRepository "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/src/main/java/com/workchat/repository/MessageRepository.java"
    click UserEntity "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/src/main/java/com/workchat/entity/User.java"
    click MessageEntity "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/src/main/java/com/workchat/entity/Message.java"
    click LoginDto "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/src/main/java/com/workchat/dto/request/LoginDto.java"
    click UserDto "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/src/main/java/com/workchat/dto/request/UserDto.java"
    click LoginResponse "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/src/main/java/com/workchat/globalResponse/LoginResponse.java"
    click MessageResponse "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/src/main/java/com/workchat/globalResponse/MessageResponse.java"
    click ApplicationProps "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/src/main/resources/application.properties"
    click apiService "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/ui/src/app/services/apiService/api.service.ts"
    click webSocketService "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/ui/src/app/services/webSocketService/web-socket.service.ts"
    click loginComponent "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/ui/src/app/components/login/login.component.ts"
    click chatSection "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/ui/src/app/components/main/chatsection/chatsection.component.ts"
    click userList "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/ui/src/app/components/main/userlist/userlist.component.ts"
    click mainComponent "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/ui/src/app/components/main/main.component.ts"
    click Angular "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/ui/angular.json"
    click Tailwind "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/ui/tailwind.config.js"
    click Server "https://github.com/nitesh6gg/hashtag-chat-application/blob/main/ui/server.ts"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef backend fill:#E0FFE0,stroke:#28a745,color:#28a745;
    classDef realtime fill:#F5E0FF,stroke:#6f42c1,color:#6f42c1;
    classDef db fill:#FFD580,stroke:#d73a49,color:#d73a49;
```
