# s4kr3d-w0r1d/whatsapp-clone architecture

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

- Interactive diagram: https://gitdiagram.com/s4kr3d-w0r1d/whatsapp-clone
- Repository: https://github.com/s4kr3d-w0r1d/whatsapp-clone

## Overview

##### Main Components
- Frontend Client: Represented by the React-based application located under “whatsapp-clone/newfrontend”. This layer includes all UI components for authentication, chat windows, group management, media sharing, profile management, etc.
- Backend Server: A Spring Boot application (under “whatsapp-clone/src/main/java”) handling business logic. It includes controllers for authentication, chat (private and group), file upload, user blocking, and real-time WebSocket messaging.
- WebSocket Layer: The backend’s configuration for WebSocket communications (see files such as WebSocketConfig.java, CustomHandshakeInterceptor.java, WsChatController.java) that enable real-time one-to-one and group messaging using STOMP over WebSocket.
- Database: Although not explicitly represented in the file tree, the README mentions PostgreSQL as the database. This will store user data, chat messages, groups, and metadata.
- Media/File Storage: A component for managing media uploads. The FileUploadController and FileStorageService handle file uploads (media is stored on disk as indicated in the README, e.g., on “C:/uploads/chat”).

##### Out Relationships & Interactions
- From Frontend → Backend REST API endpoints (e.g., AuthController, FileUploadController).
- From Frontend ↔ Backend via WebSocket (using STOMP in the client and configurations like WebSocketConfig.java on the server).
- Backend and Database: Show a connection from the backend to PostgreSQL (via Spring Data JPA and Hibernate) for persistent operations.
- Security: Illustrate the JWT-based authentication flow, with the Authentication Filter (JwtAuthenticationFilter), CustomUserDetailsService, and SecurityConfig ensuring secure API and WebSocket connections.

##### Architectural Patterns & Design Principles
- Layered Architecture: The backend is organized into controllers, services, repositories, and models, aligning with a traditional MVC but expanded to include WebSocket handling.
- Separation of Concerns: The clear split between frontend and backend, and within the backend (controllers for request handling, services for business logic, repositories for data access) should be visibly emphasized.
- Real-Time Messaging: The integration of WebSocket communication alongside RESTful endpoints distinguishes this full-stack design. Show how WebSocket endpoints are integrated (via annotations and configuration files found under the “config” package).

##### Technologies & Frameworks
- Frontend: Vite, React.js, HTML/CSS/JavaScript, and libraries like SockJS and STOMP.js.
- Backend: Java, Spring Boot, Spring Data JPA, Spring Security, Spring WebSocket with STOMP, JWT.
- Build Tools: Maven (for backend) and Vite (for frontend).
- Database: PostgreSQL

##### Elements
- Use clear labels for every component. For example:
- “React Client (Vite)” for the frontend.
- “Spring Boot REST API” and “WebSocket API (STOMP)” for backend services.
- “JWT Authentication & Security” as an aspect of the backend.
- “PostgreSQL Database” and “Media/File Storage”.
- From the user’s browser (frontend) to the REST endpoints.

- Under the backend modules, further decompose into groups showing Controllers, Services, and Repositories. Optionally, indicate cross-cutting concerns like Security configurations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    user["User"]:::user

    FE["React Client (Vite)"]:::frontend
    user --> FE

    subgraph "Backend REST Controllers"
        AuthC["AuthController"]:::backend
        UserProfileC["UserProfileController"]:::backend
        GroupChatC["GroupChatController"]:::backend
        PrivateChatC["PrivateChatController"]:::backend
        FileUploadC["FileUploadController"]:::backend
    end

    FileStorageS["FileStorageService"]:::backend

    subgraph "WebSocket API (STOMP)"
        WSConf["WebSocketConfig"]:::websocket
        Handshake["CustomHandshakeInterceptor"]:::websocket
        WSChat["WsChatController"]:::websocket
    end

    subgraph "Security (JWT)"
        SecConfig["SecurityConfig"]:::security
        JwtFilter["JwtAuthenticationFilter"]:::security
        UserDetails["CustomUserDetailsService"]:::security
    end

    DB["PostgreSQL Database"]:::database
    Repos["Repositories"]:::database
    Media["Media/File Storage"]:::media

    %% Frontend to REST API (HTTP calls)
    FE -->|"HTTP"| AuthC
    FE -->|"HTTP"| UserProfileC
    FE -->|"HTTP"| GroupChatC
    FE -->|"HTTP"| PrivateChatC
    FE -->|"HTTP"| FileUploadC

    %% Frontend to WebSocket (bi-directional)
    FE <-->|"WebSocket"| WSChat

    %% REST Controllers interactions with Database/Repositories
    AuthC -->|"JPA"| Repos
    UserProfileC -->|"JPA"| Repos
    GroupChatC -->|"JPA"| Repos
    PrivateChatC -->|"JPA"| Repos

    %% File upload flow
    FileUploadC -->|"Invokes"| FileStorageS
    FileStorageS -->|"Stores files"| Media

    %% WebSocket configuration relationships
    WSChat -->|"ConfiguredBy"| WSConf
    WSChat -->|"Uses"| Handshake

    %% Security components underpin REST
    AuthC -->|"SecuredBy"| SecConfig
    AuthC -->|"SecuredBy"| JwtFilter
    AuthC -->|"SecuredBy"| UserDetails

    %% REST Controllers access Database directly as well
    AuthC -->|"Reads/Writes"| DB
    UserProfileC -->|"Reads/Writes"| DB
    GroupChatC -->|"Reads/Writes"| DB
    PrivateChatC -->|"Reads/Writes"| DB

    %% Click Events
    click FE "https://github.com/s4kr3d-w0r1d/whatsapp-clone/tree/main/whatsapp-clone/newfrontend"
    click AuthC "https://github.com/s4kr3d-w0r1d/whatsapp-clone/blob/main/whatsapp-clone/src/main/java/com/whatsappclone/controllers/AuthController.java"
    click UserProfileC "https://github.com/s4kr3d-w0r1d/whatsapp-clone/blob/main/whatsapp-clone/src/main/java/com/whatsappclone/controllers/UserProfileController.java"
    click GroupChatC "https://github.com/s4kr3d-w0r1d/whatsapp-clone/blob/main/whatsapp-clone/src/main/java/com/whatsappclone/controllers/GroupChatController.java"
    click PrivateChatC "https://github.com/s4kr3d-w0r1d/whatsapp-clone/blob/main/whatsapp-clone/src/main/java/com/whatsappclone/controllers/PrivateChatController.java"
    click FileUploadC "https://github.com/s4kr3d-w0r1d/whatsapp-clone/blob/main/whatsapp-clone/src/main/java/com/whatsappclone/controllers/FileUploadController.java"
    click FileStorageS "https://github.com/s4kr3d-w0r1d/whatsapp-clone/blob/main/whatsapp-clone/src/main/java/com/whatsappclone/services/FileStorageService.java"
    click WSConf "https://github.com/s4kr3d-w0r1d/whatsapp-clone/blob/main/whatsapp-clone/src/main/java/com/whatsappclone/config/WebSocketConfig.java"
    click Handshake "https://github.com/s4kr3d-w0r1d/whatsapp-clone/blob/main/whatsapp-clone/src/main/java/com/whatsappclone/config/CustomHandshakeInterceptor.java"
    click WSChat "https://github.com/s4kr3d-w0r1d/whatsapp-clone/blob/main/whatsapp-clone/src/main/java/com/whatsappclone/controllers/WsChatController.java"
    click SecConfig "https://github.com/s4kr3d-w0r1d/whatsapp-clone/blob/main/whatsapp-clone/src/main/java/com/whatsappclone/config/SecurityConfig.java"
    click JwtFilter "https://github.com/s4kr3d-w0r1d/whatsapp-clone/blob/main/whatsapp-clone/src/main/java/com/whatsappclone/security/JwtAuthenticationFilter.java"
    click UserDetails "https://github.com/s4kr3d-w0r1d/whatsapp-clone/blob/main/whatsapp-clone/src/main/java/com/whatsappclone/security/CustomUserDetailsService.java"
    click Repos "https://github.com/s4kr3d-w0r1d/whatsapp-clone/tree/main/whatsapp-clone/src/main/java/com/whatsappclone/repositories"
    
classDef frontend fill:#ffadad,stroke:#333,stroke-width:2px;
classDef backend fill:#a0c4ff,stroke:#333,stroke-width:2px;
classDef websocket fill:#caffbf,stroke:#333,stroke-width:2px;
classDef security fill:#ffd6a5,stroke:#333,stroke-width:2px;
classDef database fill:#fdffb6,stroke:#333,stroke-width:2px;
classDef media fill:#ffcad4,stroke:#333,stroke-width:2px;
classDef user fill:#c0e6de,stroke:#333,stroke-width:2px;
```
