# tamilvendhan23/chatterbox_messenger architecture

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

- Interactive diagram: https://gitdiagram.com/tamilvendhan23/chatterbox_messenger
- Repository: https://github.com/tamilvendhan23/chatterbox_messenger

## Overview

##### Project Type & Purpose
- This is a full-stack real-time chat application built using the MERN stack (MongoDB, Express/Node.js, React) and enhanced by Socket.io for real-time messaging.
- The README highlights features such as JWT-based authentication, real-time messaging, user status tracking, and global state management with Zustand on the frontend.
- As the name implies and from the folder structure, the project is split into a backend and a frontend, each with its own set of directories and specific responsibilities.

##### File Structure Key Points
- The top-level directories include "backend" and "frontend":
- Backend: Contains directories for controllers, routes, middleware, models, seeds, and libraries. This indicates a typical RESTful API service with authentication (auth.controller.js, auth.middleware.js) and message handling endpoints.
- Frontend: Based on React (using JSX files) and coupled with TailwindCSS (tailwind.config.js) and other styling configurations. It also maintains its state management (Zustand stores), components, and pages.
- Configuration files like package.json, eslint configurations, and build tools (vite.config.js, postcss.config.js) are also in place.
- The integration of Socket.io and Cloudinary (files in backend/src/lib/cloudinary.js) hints at specialized modules for image handling as well as real time communication.

##### Main Components & Their Responsibilities
A. Frontend
- React-Based UI: Contains multiple pages (LoginPage, HomePage, ProfilePage, etc.) and reusable components (ChatContainer, Navbar, Sidebar, skeletons for loading states).
- Global State Management: Implemented with Zustand (stores for auth, chat, theme).
- External API Calls: Abstracted via axios in a library under frontend/src/lib/axios.js.
- Design & Styling: Using TailwindCSS and Daisy UI.
B. Backend
- API Server: Created using Node.js/Express (backend/src/index.js as entry point). REST endpoints are defined in routes (auth.route.js and message.route.js).
- Controllers & Models: Separate controllers handle business logic for authentication and messaging, while models define the MongoDB schema for users and messages.
- Middleware: Authentication middleware (JWT-based) to secure routes.
- Real-Time Communication: Integrated via Socket.io (backend/src/lib/socket.js) to handle realtime messaging.
- Database & External Services:
○ Database connector (backend/src/lib/db.js) to interact with MongoDB.
○ Cloudinary integration (backend/src/lib/cloudinary.js) for media/image handling.
C. External Components
- MongoDB: To persist chat and user data.
- Cloudinary: For image management.
- Socket.io: For handling real-time events and online user status.
- JWT: For securing authentication and authorization across endpoints.

- Components and Layout:
1. Frontend Component:
- UI elements (Pages, Components, State Management).
2. API Gateway / Backend Component:
- Authentication Controller & Middleware.
- Message Controller.
- Routes (auth and message endpoints).
- Socket.io integration (depicting real-time message flow).
- Database module handling.
- Cloudinary integration for file/image uploads.
3. Data Stores and External Services:
- Cloudinary module with an external Cloudinary service.
4. Communication Channels:
- HTTP REST APIs from Frontend → Backend.
- Real-time bidirectional communication between Frontend and Backend via Socket.io.
- Data flow from Backend to MongoDB for persistent storage.
5. Annotation:

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Components
    subgraph "Frontend"
        RC["React Client UI"]:::frontend
        GSM["Global State Management (Zustand)"]:::frontend
        API_F["External API Calls Library"]:::frontend
    end

    GSM -->|"provides state to"| RC
    RC -->|"uses"| API_F

    %% Backend Components
    subgraph "Backend"
        ES["Express API Server"]:::backend
        ACT["Authentication Controller"]:::backend
        AMW["Authentication Middleware"]:::backend
        MC["Message Controller"]:::backend
        AR_AUTH["Auth Routes"]:::backend
        AR_MESSAGE["Message Routes"]:::backend
        SOCK["Socket.io Module"]:::backend
        DB["Database Connector"]:::backend
        CLD["Cloudinary Integration Module"]:::backend
    end

    API_F -->|"HTTP Request"| ES
    RC <-->|"Socket.io"| SOCK

    ES -->|"handles auth"| ACT
    ES -->|"secures routes"| AMW
    ES -->|"handles messaging"| MC
    ES -->|"routes API"| AR_AUTH
    ES -->|"routes API"| AR_MESSAGE
    ES -->|"initiates realtime"| SOCK
    ES -->|"DB operations"| DB
    ES -->|"media handling"| CLD

    %% External Services
    MDB[(MongoDB)]
    CLD_EXT((Cloudinary))

    DB -->|"connects to"| MDB
    CLD -->|"uploads to"| CLD_EXT

    %% Click Events
    click RC "https://github.com/tamilvendhan23/chatterbox_messenger/tree/main/frontend/src/pages"
    click GSM "https://github.com/tamilvendhan23/chatterbox_messenger/tree/main/frontend/src/store"
    click API_F "https://github.com/tamilvendhan23/chatterbox_messenger/blob/main/frontend/src/lib/axios.js"
    click ES "https://github.com/tamilvendhan23/chatterbox_messenger/blob/main/backend/src/index.js"
    click ACT "https://github.com/tamilvendhan23/chatterbox_messenger/blob/main/backend/src/controllers/auth.controller.js"
    click AMW "https://github.com/tamilvendhan23/chatterbox_messenger/blob/main/backend/src/middleware/auth.middleware.js"
    click MC "https://github.com/tamilvendhan23/chatterbox_messenger/blob/main/backend/src/controllers/message.controller.js"
    click AR_AUTH "https://github.com/tamilvendhan23/chatterbox_messenger/blob/main/backend/src/routes/auth.route.js"
    click AR_MESSAGE "https://github.com/tamilvendhan23/chatterbox_messenger/blob/main/backend/src/routes/message.route.js"
    click SOCK "https://github.com/tamilvendhan23/chatterbox_messenger/blob/main/backend/src/lib/socket.js"
    click DB "https://github.com/tamilvendhan23/chatterbox_messenger/blob/main/backend/src/lib/db.js"
    click CLD "https://github.com/tamilvendhan23/chatterbox_messenger/blob/main/backend/src/lib/cloudinary.js"

    %% Styles
    classDef frontend fill:#FFE7A0,stroke:#e28900,stroke-width:2px;
    classDef backend fill:#A0D2DB,stroke:#007B8F,stroke-width:2px;
    classDef external fill:#C7F9CC,stroke:#32CD32,stroke-width:2px;
```
