# pankajjoshi-05/multi-threaded-chat-app architecture

> Architecture diagram of the GitHub repository pankajjoshi-05/multi-threaded-chat-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pankajjoshi-05/multi-threaded-chat-app
- Repository: https://github.com/pankajjoshi-05/multi-threaded-chat-app

## Overview

##### Project type and purpose
- This is a full-stack MERN (MongoDB, Express, React, Node) real-time chat application.
- It supports JWT authentication, WebSocket-based messaging (Socket.IO), media/file sharing (Multer + Cloudinary), AES-256 encryption (Node Crypto + worker threads), presence indicators, email notifications, and a responsive UI (Tailwind + DaisyUI).

##### File structure
- Top-level split: `frontend/` (React SPA) and `backend/` (Node/Express API + WebSocket server).
- Backend subfolders follow an MVC-style pattern:
- `config/` – database connection
- `controllers/` – business logic for auth, chat, user
- `routes/` – REST & WebSocket endpoints
- `models/` – Mongoose schemas
- `middleware/` – token verification, file uploads
- `utils/` – email templates, token generation, event emitter, cors setup
- `workers/` – encryption/decryption via Node Worker Threads
- Frontend is component-driven:
- `components/` by feature (auth, chat, core UI, panels, skeletons, ui)
- `pages/` – route targets (Login, Chat, Settings, etc.)
- `store/` – Zustand state slices (auth, chat, socket, theme, user)
- `hooks/`, `constants/`, `App.jsx` & routing

##### README for additional insights
- Confirms tech stack, architectural highlights (real-time via Socket.IO, worker threads for background encryption, Cloudinary for media, Nodemailer for email).
- Emphasizes modular structure and environment variable requirements.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Zone
    subgraph "Frontend" 
        direction TB
        ReactSPA["React SPA"]:::frontend
        HTTPClient["HTTP Client (REST)"]:::frontend
        WSClient["WebSocket Client"]:::frontend
    end

    %% Backend Zone
    subgraph "Backend"
        direction TB
        API["Express API + Socket.IO"]:::backend
        subgraph "Worker Thread Pool"
            direction TB
            EncryptWorker["Encrypt Worker"]:::worker
            DecryptWorker["Decrypt Worker"]:::worker
        end
        DB["MongoDB"]:::database
        Media["Cloudinary"]:::external
        Email["Email Service (SMTP)"]:::external
    end

    %% Frontend to Backend Connections
    ReactSPA -->|HTTP REST| HTTPClient -->|POST/GET| API
    ReactSPA -->|WebSocket| WSClient -->|Socket.IO| API

    %% Backend internal flows
    API -->|Encrypt/Decrypt Job| EncryptWorker
    API -->|Encrypt/Decrypt Job| DecryptWorker
    API -->|CRUD| DB
    API -->|Upload/Download| Media
    API -->|Send Email| Email

    %% Click Events
    click ReactSPA "https://github.com/pankajjoshi-05/multi-threaded-chat-app/blob/main/frontend/src/App.jsx"
    click API "https://github.com/pankajjoshi-05/multi-threaded-chat-app/blob/main/backend/src/index.js"
    click DB "https://github.com/pankajjoshi-05/multi-threaded-chat-app/blob/main/backend/src/config/db.js"
    click Media "https://github.com/pankajjoshi-05/multi-threaded-chat-app/blob/main/backend/src/utils/cloudinary.js"
    click Email "https://github.com/pankajjoshi-05/multi-threaded-chat-app/blob/main/backend/src/utils/email.utils.js"
    click EncryptWorker "https://github.com/pankajjoshi-05/multi-threaded-chat-app/blob/main/backend/src/workers/encrypt.worker.js"
    click DecryptWorker "https://github.com/pankajjoshi-05/multi-threaded-chat-app/blob/main/backend/src/workers/decrypt.worker.js"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#0050A0,stroke-width:2px
    classDef backend fill:#DFFFE0,stroke:#1A7F00,stroke-width:2px
    classDef worker fill:#FFF4D0,stroke:#A05A00,stroke-width:2px,stroke-dasharray: 5 5
    classDef database fill:#FFFFFF,stroke:#0000FF,stroke-width:2px,stroke-dasharray: 2 2
    classDef external fill:#FFE0D0,stroke:#A00000,stroke-width:2px,stroke-dasharray: 5 5
```
