# ali-bouali/whatsapp-clone architecture

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

- Interactive diagram: https://gitdiagram.com/ali-bouali/whatsapp-clone
- Repository: https://github.com/ali-bouali/whatsapp-clone

## Overview

##### Main Components

a. Client Layer:
- Angular Frontend (whatsapp-clone-ui)
- Components Module (chat-list, main)
- Services Module (chat, message, user services)
- Keycloak Integration
- WebSocket Client

b. Security Layer:
- Keycloak Server
- Authentication
- Authorization
- User Management

c. Backend Layer (Spring Boot):
- REST API Controllers
- ChatController
- MessageController
- UserController
- Service Layer
- ChatService
- MessageService
- UserService
- NotificationService
- FileService
- Data Layer
- Repositories
- Entity Models
- WebSocket Server
- Security Configuration

d. Database Layer:
- Database (likely PostgreSQL/MySQL based on Spring Boot configuration)
- User tables
- Chat tables
- Message tables

##### Interaction Flows to Highlight

- Authentication Flow:
- Token-based authentication path

- Real-time Communication:
- WebSocket connections between frontend and backend
- Notification system flow

- Message Flow:
- Message creation and delivery path
- File upload/media handling flow

##### Specific Implementation Details

a. Frontend Architecture:
- Component hierarchy
- Service layer interaction
- HTTP interceptors for authentication
- WebSocket integration

b. Backend Architecture:
- Controller → Service → Repository pattern
- WebSocket configuration
- File handling system
- Security filters and interceptors

##### Additional Elements

- Notes for important configurations
- Scaling points and potential load balancers
- Security boundaries

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef security fill:#f1c40f,stroke:#f39c12,color:black
    classDef database fill:#9b59b6,stroke:#8e44ad,color:white
    classDef websocket fill:#e74c3c,stroke:#c0392b,color:white
    classDef entity fill:#1abc9c,stroke:#16a085,color:white

    %% Frontend Layer
    subgraph Frontend
        UI[Angular Frontend]:::frontend
        ChatList[Chat List Component]:::frontend
        MainComp[Main Component]:::frontend
        FrontendServices[Services Module]:::frontend
        KeycloakInt[Keycloak Integration]:::frontend
        WSClient[WebSocket Client]:::frontend
        
        UI --> ChatList
        UI --> MainComp
        UI --> FrontendServices
        UI --> KeycloakInt
        UI --> WSClient
    end

    %% Security Layer
    subgraph Security
        KeycloakServer[Keycloak Server]:::security
        SecurityConfig[Security Configuration]:::security
        JWTConverter[JWT Converter]:::security
        
        KeycloakServer --> SecurityConfig
        SecurityConfig --> JWTConverter
    end

    %% Backend Layer
    subgraph Backend
        %% Controllers
        ChatCtrl[Chat Controller]:::backend
        MessageCtrl[Message Controller]:::backend
        UserCtrl[User Controller]:::backend
        
        %% Services
        ChatSvc[Chat Service]:::backend
        MessageSvc[Message Service]:::backend
        UserSvc[User Service]:::backend
        NotifSvc[Notification Service]:::backend
        FileSvc[File Service]:::backend
        
        %% WebSocket
        WSServer[WebSocket Server]:::websocket
        WSConfig[WebSocket Config]:::websocket
        
        %% Repositories
        ChatRepo[Chat Repository]:::backend
        MessageRepo[Message Repository]:::backend
        UserRepo[User Repository]:::backend
        
        %% Entities
        ChatEntity[Chat Entity]:::entity
        MessageEntity[Message Entity]:::entity
        UserEntity[User Entity]:::entity
        NotifEntity[Notification Entity]:::entity
        
        %% Backend Connections
        ChatCtrl --> ChatSvc
        MessageCtrl --> MessageSvc
        UserCtrl --> UserSvc
        
        ChatSvc --> ChatRepo
        MessageSvc --> MessageRepo
        UserSvc --> UserRepo
        
        ChatRepo --> ChatEntity
        MessageRepo --> MessageEntity
        UserRepo --> UserEntity
        NotifSvc --> NotifEntity
        
        WSServer --> WSConfig
    end

    %% Database Layer
    subgraph Database
        DB[(Database)]:::database
    end

    %% Cross-layer connections
    FrontendServices -.-> ChatCtrl
    FrontendServices -.-> MessageCtrl
    FrontendServices -.-> UserCtrl
    WSClient -.-> WSServer
    KeycloakInt -.-> KeycloakServer
    SecurityConfig -.-> ChatCtrl
    SecurityConfig -.-> MessageCtrl
    SecurityConfig -.-> UserCtrl
    ChatEntity --> DB
    MessageEntity --> DB
    UserEntity --> DB
    NotifEntity --> DB

    %% Click events
    click ChatList "https://github.com/ali-bouali/whatsapp-clone/tree/main/whatsapp-clone-ui/src/app/components/chat-list/"
    click MainComp "https://github.com/ali-bouali/whatsapp-clone/tree/main/whatsapp-clone-ui/src/app/pages/main/"
    click FrontendServices "https://github.com/ali-bouali/whatsapp-clone/tree/main/whatsapp-clone-ui/src/app/services/services/"
    click KeycloakInt "https://github.com/ali-bouali/whatsapp-clone/tree/main/whatsapp-clone-ui/src/app/utils/keycloak/"
    click ChatCtrl "https://github.com/ali-bouali/whatsapp-clone/blob/main/whatsappclone/src/main/java/com/alibou/whatsappclone/chat/ChatController.java"
    click MessageCtrl "https://github.com/ali-bouali/whatsapp-clone/blob/main/whatsappclone/src/main/java/com/alibou/whatsappclone/message/MessageController.java"
    click UserCtrl "https://github.com/ali-bouali/whatsapp-clone/blob/main/whatsappclone/src/main/java/com/alibou/whatsappclone/user/UserController.java"
    click ChatSvc "https://github.com/ali-bouali/whatsapp-clone/blob/main/whatsappclone/src/main/java/com/alibou/whatsappclone/chat/ChatService.java"
    click MessageSvc "https://github.com/ali-bouali/whatsapp-clone/blob/main/whatsappclone/src/main/java/com/alibou/whatsappclone/message/MessageService.java"
    click UserSvc "https://github.com/ali-bouali/whatsapp-clone/blob/main/whatsappclone/src/main/java/com/alibou/whatsappclone/user/UserService.java"
    click FileSvc "https://github.com/ali-bouali/whatsapp-clone/blob/main/whatsappclone/src/main/java/com/alibou/whatsappclone/file/FileService.java"
    click NotifSvc "https://github.com/ali-bouali/whatsapp-clone/blob/main/whatsappclone/src/main/java/com/alibou/whatsappclone/notification/NotificationService.java"
    click ChatRepo "https://github.com/ali-bouali/whatsapp-clone/blob/main/whatsappclone/src/main/java/com/alibou/whatsappclone/chat/ChatRepository.java"
    click MessageRepo "https://github.com/ali-bouali/whatsapp-clone/blob/main/whatsappclone/src/main/java/com/alibou/whatsappclone/message/MessageRepository.java"
    click UserRepo "https://github.com/ali-bouali/whatsapp-clone/blob/main/whatsappclone/src/main/java/com/alibou/whatsappclone/user/UserRepository.java"
    click SecurityConfig "https://github.com/ali-bouali/whatsapp-clone/blob/main/whatsappclone/src/main/java/com/alibou/whatsappclone/security/SecurityConfig.java"
    click JWTConverter "https://github.com/ali-bouali/whatsapp-clone/blob/main/whatsappclone/src/main/java/com/alibou/whatsappclone/security/KeycloakJwtAuthenticationConverter.java"
    click WSConfig "https://github.com/ali-bouali/whatsapp-clone/blob/main/whatsappclone/src/main/java/com/alibou/whatsappclone/ws/WebSocketConfig.java"
    click ChatEntity "https://github.com/ali-bouali/whatsapp-clone/blob/main/whatsappclone/src/main/java/com/alibou/whatsappclone/chat/Chat.java"
    click MessageEntity "https://github.com/ali-bouali/whatsapp-clone/blob/main/whatsappclone/src/main/java/com/alibou/whatsappclone/message/Message.java"
    click UserEntity "https://github.com/ali-bouali/whatsapp-clone/blob/main/whatsappclone/src/main/java/com/alibou/whatsappclone/user/User.java"
    click NotifEntity "https://github.com/ali-bouali/whatsapp-clone/blob/main/whatsappclone/src/main/java/com/alibou/whatsappclone/notification/Notification.java"
```
