# arjunthakur0412/nextjs-whatsapp-clone architecture

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

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

## Overview

##### Project Type and Purpose
- The project is a full-stack communication application modeled after WhatsApp. It emphasizes real-time messaging, group chats, media sharing, audio/video call features supported by WebRTC (via Zegocloud), and real-time communication (likely via Socket.IO).
- Key technologies include Next.js for the frontend, Node.js on the backend with Prisma to interact with a PostgreSQL database, as well as integrations for Firebase Authentication and audio/video communication.

##### File Structure
- Notice the clear separation between the “client” (frontend) and “server” (backend) directories.
- In the client folder:
- The “src” directory hosts Next.js pages, reusable components (such as chat, call, and common UI components), context providers for state management, styles using Tailwind CSS, and utility functions.
- The public assets include static files, images (e.g., avatars), and even sound files.
- In the server folder:
- You have controllers, routes, and middlewares which indicate an MVC-like pattern to manage server-side logic.
- The “prisma” directory indicates usage of Prisma for ORM with a PostgreSQL database.
- The utilities include custom modules such as token generation and a Prisma client initializer.

##### Extract Key Architectural Components
a. Frontend (Client):
- Next.js frontend with pages rendering dynamic components.
- UI components for chats, calls, and common utilities.
- Context API for state management across the application.
- Integration with external APIs for audio/video calls, possibly communicating with Socket.IO for real-time updates.
b. Backend (Server):
- REST API endpoints defined in the “routes”.
- Controllers that contain the business logic for authentication, message handling, etc.
- Middlewares (e.g., for authentication) protecting certain routes.
- Prisma layer managing database interactions with PostgreSQL.
c. Communication and External Services:
- Real-time communication via Socket.IO (for messaging).
- Firebase Authentication for secure user management.
- Zegocloud (WebRTC) for implementing video and audio calls.
- Database: PostgreSQL serving as the persistent layer.

- Within the Frontend block (client):
- UI components, the Next.js pages, context/state management layer, and static assets.
- Usage of Tailwind CSS for styling.
- Within the Backend block (server):
- Detail the API layer including routes, controllers, and middlewares.
- Prisma ORM connecting to the PostgreSQL database.
- External integrations such as Firebase Authentication and Socket.IO.
- An external block for the Real-Time Communication Service:
- WebRTC integration via Zegocloud for audio/video calls.
- A separate connection showing WebSocket connections or real-time channels between the client and backend for live updates.
- Connections between Backend and external services (Firebase, Zegocloud) clearly labeled.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Subgraph
    subgraph "Frontend"
        A("Next.js Pages"):::frontend
        B("UI Components"):::frontend
        C("Chat Components (Chat & Chatlist)"):::frontend
        D("Call Components"):::frontend
        E("State Management"):::frontend
        F("Tailwind CSS"):::frontend
        G("Utility Functions"):::frontend
    end

    %% Backend Subgraph
    subgraph "Backend"
        H("API Routes"):::backend
        I("Controllers"):::backend
        J("Middlewares"):::backend
        K("Prisma ORM"):::backend
        L("Utility Modules"):::backend
    end

    %% External Services Subgraph
    subgraph "External Services"
        M("PostgreSQL Database"):::external
        N("Firebase Authentication"):::external
        O("Socket.IO"):::external
        P("Zegocloud WebRTC"):::external
    end

    %% Frontend Internal Connections
    C -->|"part_of"| B
    D -->|"part_of"| B
    B -->|"updates_State"| E
    F -->|"styles"| A

    %% Connections from Frontend to Backend & External
    A -->|"REST_calls"| H
    G -->|"utils_api"| H
    A -->|"socket_connection"| O

    %% Backend Internal Connections
    H -->|"calls"| I
    H -->|"protected_by"| J
    I -->|"db_operations"| K
    K -->|"stores"| M

    %% Backend to External Services
    I -->|"auth_verify"| N
    I -->|"realtime_messaging"| O
    I -->|"audio_video_calls"| P

    %% Click Events for Frontend Components
    click A "https://github.com/arjunthakur0412/nextjs-whatsapp-clone/tree/main/client/src/pages"
    click B "https://github.com/arjunthakur0412/nextjs-whatsapp-clone/tree/main/client/src/components"
    click C "https://github.com/arjunthakur0412/nextjs-whatsapp-clone/tree/main/client/src/components/Chat"
    click D "https://github.com/arjunthakur0412/nextjs-whatsapp-clone/tree/main/client/src/components/Call"
    click E "https://github.com/arjunthakur0412/nextjs-whatsapp-clone/tree/main/client/src/context"
    click F "https://github.com/arjunthakur0412/nextjs-whatsapp-clone/blob/main/client/tailwind.config.js"
    click G "https://github.com/arjunthakur0412/nextjs-whatsapp-clone/tree/main/client/src/utils"

    %% Click Events for Backend Components
    click H "https://github.com/arjunthakur0412/nextjs-whatsapp-clone/tree/main/server/routes"
    click I "https://github.com/arjunthakur0412/nextjs-whatsapp-clone/tree/main/server/controllers"
    click J "https://github.com/arjunthakur0412/nextjs-whatsapp-clone/tree/main/server/middlewares"
    click K "https://github.com/arjunthakur0412/nextjs-whatsapp-clone/tree/main/server/prisma"
    click L "https://github.com/arjunthakur0412/nextjs-whatsapp-clone/tree/main/server/utils"

    %% Styles
    classDef frontend fill:#E6F7FF,stroke:#1890FF,stroke-width:2px;
    classDef backend fill:#FFF7E6,stroke:#FA8C16,stroke-width:2px;
    classDef external fill:#F6FFED,stroke:#52C41A,stroke-width:2px;
```
