# ayushkul/whatsapp-clone architecture

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

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

## Overview

##### Project type and purpose
- This is a full-stack WhatsApp-style chat application clone.
- Frontend: a React single-page application (SPA) providing login, contact list, and conversation UIs.
- Backend: a Node.js/Express server implementing RESTful endpoints (and potentially WebSocket support) with an MVC-style structure and a connection to a document database (e.g., MongoDB) for users and channels.

##### File structure
Top-level:
- client/ – React app
– public/ – static assets and index.html
– src/ – source code
- components/ – ContactListComponent, ConversationComponent
- managers/ – cookieManager, httpManager (abstractions for auth token storage and API calls)
- modules/login – login page logic
- mockData, utility – helpers for mocks and shared utilities
- server/ – Node/Express API
– app/controllers – request handlers
– app/models – data schemas (channel.js, user.js)
– routes – mapping URLs to controllers
– config – environment and port settings
– dbConnection – database initialization
– utility/validator – input validation
– server.js – entry point

##### README
- Confirms a deployed demo and tutorial links.

a. Main components
1. Frontend (React SPA)
- UI Components (ContactListComponent, ConversationComponent)
- State & API managers (cookieManager, httpManager)
2. Backend (Express API)
- Routes layer
- Controllers (business logic)
- Models (data schemas)
- Config & Utilities
3. Database (e.g., MongoDB)
4. (Optional) Real-time transport (WebSockets/Socket.io) if implemented
5. External services (if any, e.g., authentication provider, file storage)
b. Relationships & interactions
- React components invoke httpManager → Express endpoints (login, fetch contacts, send/receive messages).
- cookieManager stores JWT or session tokens, attached to outgoing requests.
- Express routes forward requests to controllers → controllers use models to read/write DB via dbConnection.
- DB returns data, controllers format and send HTTP (or WS) responses back to client.
- (If using WebSockets) a persistent socket channel for real-time message delivery.
c. Architectural patterns
- Client: component-based UI, separation of concerns via “managers” and “modules.”
- Server: MVC-inspired layering (Routes → Controllers → Models).
- Configuration and environment kept separate in config/.
- Single responsibility for utilities (validator, dbConnection).
d. Key technologies
- React, React Router (implied), JavaScript modules.
- cookieManager & httpManager abstractions for API calls and auth.
- Node.js, Express.js, RESTful routing.
- Mongoose or similar ODM for user/channel models.
- MongoDB (or any document store).
- Optional real-time library (Socket.io) for bi-directional messaging.

##### Detail
- Config and utility layers that affect initialization and validation.
- Auth flow: login module → httpManager → auth route → controller → token issued → cookieManager stores it → subsequent API calls include the token.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (React SPA)"
        direction TB
        CL["ContactListComponent"]:::frontend
        CC["ConversationComponent"]:::frontend
        Login["Login Module"]:::frontend
        HTTP["httpManager"]:::frontend
        Cookie["cookieManager"]:::frontend
        UtilFE["Utilities"]:::util
        Mock["Mock Data"]:::util
    end

    %% Backend Layer
    subgraph "Backend (Node.js/Express)"
        direction TB
        SR["server.js (Entry Point)"]:::backend
        CFG["Config"]:::backend
        DBConn["DB Connection"]:::backend
        VAL["Input Validator"]:::backend
        UtilBE["Server Utilities"]:::util

        subgraph "Routes Layer"
            direction TB
            Routes["Routes"]:::backend
        end

        subgraph "Controllers"
            direction TB
            Ctrl["Controllers"]:::backend
        end

        subgraph "Models"
            direction TB
            UserM["User Model"]:::backend
            ChannelM["Channel Model"]:::backend
        end
    end

    %% Database
    DB["MongoDB Database"]:::database

    %% Connections Frontend
    Login -->|"uses"| HTTP
    CL -->|"fetch contacts via"| HTTP
    CC -->|"send/receive msgs via"| HTTP
    HTTP -->|"attaches token via"| Cookie
    HTTP -->|"HTTP Requests"| Routes

    %% Connections Backend
    SR --> CFG
    SR --> DBConn
    SR --> VAL
    SR --> UtilBE
    Routes --> Ctrl
    Ctrl --> UserM
    Ctrl --> ChannelM
    DBConn --> DB
    Ctrl --> DB

    %% Optional WebSocket
    CC -.->|"WebSocket"| SR
    SR -.->|"WebSocket"| CC

    %% Click Events Frontend
    click CL "https://github.com/ayushkul/whatsapp-clone/blob/main/client/src/components/ContactListComponent.js"
    click CC "https://github.com/ayushkul/whatsapp-clone/blob/main/client/src/components/ConversationComponent.js"
    click Cookie "https://github.com/ayushkul/whatsapp-clone/blob/main/client/src/managers/cookieManager.js"
    click HTTP "https://github.com/ayushkul/whatsapp-clone/blob/main/client/src/managers/httpManager.js"
    click Login "https://github.com/ayushkul/whatsapp-clone/blob/main/client/src/modules/login/index.js"
    click UtilFE "https://github.com/ayushkul/whatsapp-clone/blob/main/client/src/utility/index.js"
    click Mock "https://github.com/ayushkul/whatsapp-clone/blob/main/client/src/mockData.js"
    click SR "https://github.com/ayushkul/whatsapp-clone/blob/main/server/server.js"

    %% Click Events Backend
    click Routes "https://github.com/ayushkul/whatsapp-clone/blob/main/server/routes/index.js"
    click Ctrl "https://github.com/ayushkul/whatsapp-clone/blob/main/server/app/controllers/index.js"
    click UserM "https://github.com/ayushkul/whatsapp-clone/blob/main/server/app/models/user.js"
    click ChannelM "https://github.com/ayushkul/whatsapp-clone/blob/main/server/app/models/channel.js"
    click CFG "https://github.com/ayushkul/whatsapp-clone/blob/main/server/config/index.js"
    click DBConn "https://github.com/ayushkul/whatsapp-clone/blob/main/server/dbConnection/index.js"
    click VAL "https://github.com/ayushkul/whatsapp-clone/blob/main/server/utility/validator.js"
    click UtilBE "https://github.com/ayushkul/whatsapp-clone/blob/main/server/utility/index.js"

    %% Styles
    classDef frontend fill:#D6EAF8,stroke:#1B4F72,stroke-width:1px;
    classDef backend fill:#D5F5E3,stroke:#145A32,stroke-width:1px;
    classDef database fill:#FCF3CF,stroke:#7D6608,stroke-width:1px,shape:cylinder;
    classDef util fill:#FDEBD0,stroke:#935116,stroke-width:1px
```
