# samisb2002/chat-app architecture

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

- Interactive diagram: https://gitdiagram.com/samisb2002/chat-app
- Repository: https://github.com/samisb2002/chat-app

## Overview

##### Project type and purpose
- This is a full-stack real-time chat application (“Chatty”) built on the MERN stack (MongoDB, Express, React, Node.js) plus Socket.IO for real-time messaging, Redis for presence, Cloudinary for image storage, and JWT for auth.

##### File structure
- Top-level:
- backend/ – Node.js + Express REST & Socket.IO server, organized in MVC style (controllers, models, routes) with a lib folder for shared utilities (db, redis, socket, cloudinary).
- frontend/ – React (Vite) app, organized into pages, components, state stores (Zustand), utilities (axios, utils), Tailwind/DaisyUI styling.
- Root has overarching docs and instructions.

##### README
- Confirms real-time chat, user auth, online presence, image sharing, responsive design, dark/light mode.
- Lists all core technologies and their roles.

##### Detail without over-splitting
- Five major zones (client, API, WebSocket, databases, external storage) but group related functions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend
    subgraph "Frontend (React)" 
        direction TB
        UI["Client (Browser)"]:::frontend
        subgraph "Pages & Components"
            direction TB
            Pages["src/pages"]:::frontend
            Components["src/components"]:::frontend
        end
        subgraph "API Layer"
            direction TB
            Axios["axios.js"]:::frontend
            UtilsFE["utils.js"]:::frontend
            App["App.jsx"]:::frontend
        end
        subgraph "State Management"
            direction TB
            AuthStore["useAuthStore.js"]:::frontend
            ChatStore["useChatStore.js"]:::frontend
            DashboardStore["useDashboardStore.js"]:::frontend
            ThemeStore["useThemeStore.js"]:::frontend
        end
    end

    %% Backend
    subgraph "Backend (Node.js & Express)" 
        direction TB
        Entry["index.js"]:::server
        subgraph "REST API"
            direction TB
            AuthCtrl["auth.controller.js"]:::server
            DashboardCtrl["dashboard.controller.js"]:::server
            MessageCtrl["message.controller.js"]:::server
            AuthRoute["auth.route.js"]:::server
            DashboardRoute["dashboard.route.js"]:::server
            MessageRoute["message.route.js"]:::server
        end
        Middleware["auth.middleware.js"]:::server
        SocketLib["socket.js"]:::server
        UtilsBE["utils.js"]:::server
        subgraph "Models & DB"
            direction TB
            DBConn["db.js"]:::server
            UserModel["user.model.js"]:::server
            MessageModel["message.model.js"]:::server
        end
        RedisLib["redis.js"]:::server
        CloudinaryLib["cloudinary.js"]:::server
    end

    %% Storage & External Services
    subgraph "Storage & External Services"
        direction TB
        MongoDB[(MongoDB)]:::storage
        RedisDB[(Redis)]:::storage
        Cloudinary[(Cloudinary)]:::external
    end

    %% Connections
    UI -->|"HTTP REST (Axios)"| Axios
    UI -->|"WebSocket (Socket.IO)"| SocketLib
    App -->|uses Axios & Router| Axios
    App -->|initializes Socket.IO client| SocketLib

    Axios -->|calls routes| Entry
    Entry -->|routes to controllers| AuthRoute
    Entry -->|routes to controllers| DashboardRoute
    Entry -->|routes to controllers| MessageRoute
    AuthRoute --> AuthCtrl
    DashboardRoute --> DashboardCtrl
    MessageRoute --> MessageCtrl
    AuthCtrl -->|JWT, bcrypt| UtilsBE
    AuthCtrl -->|reads/writes| UserModel
    DashboardCtrl -->|reads| UserModel
    DashboardCtrl -->|reads| MessageModel
    MessageCtrl -->|reads/writes| MessageModel
    AuthCtrl -->|issues JWT| Middleware
    MessageCtrl -->|uploads image| CloudinaryLib
    MessageCtrl -->|stores URL| MessageModel

    Entry --> Middleware
    AuthCtrl --> DBConn
    DashboardCtrl --> DBConn
    MessageCtrl --> DBConn

    SocketLib -->|auth via JWT| Middleware
    SocketLib -->|PUB/SUB presence| RedisLib
    SocketLib -->|broadcast| UI

    DBConn --> MongoDB
    RedisLib --> RedisDB
    CloudinaryLib --> Cloudinary

    %% Click Events
    click Pages "https://github.com/samisb2002/chat-app/tree/main/frontend/src/pages"
    click Components "https://github.com/samisb2002/chat-app/tree/main/frontend/src/components"
    click Axios "https://github.com/samisb2002/chat-app/blob/main/frontend/src/lib/axios.js"
    click UtilsFE "https://github.com/samisb2002/chat-app/blob/main/frontend/src/lib/utils.js"
    click App "https://github.com/samisb2002/chat-app/blob/main/frontend/src/App.jsx"
    click AuthStore "https://github.com/samisb2002/chat-app/blob/main/frontend/src/store/useAuthStore.js"
    click ChatStore "https://github.com/samisb2002/chat-app/blob/main/frontend/src/store/useChatStore.js"
    click DashboardStore "https://github.com/samisb2002/chat-app/blob/main/frontend/src/store/useDashboardStore.js"
    click ThemeStore "https://github.com/samisb2002/chat-app/blob/main/frontend/src/store/useThemeStore.js"
    click Entry "https://github.com/samisb2002/chat-app/blob/main/backend/src/index.js"
    click AuthCtrl "https://github.com/samisb2002/chat-app/blob/main/backend/src/controllers/auth.controller.js"
    click DashboardCtrl "https://github.com/samisb2002/chat-app/blob/main/backend/src/controllers/dashboard.controller.js"
    click MessageCtrl "https://github.com/samisb2002/chat-app/blob/main/backend/src/controllers/message.controller.js"
    click AuthRoute "https://github.com/samisb2002/chat-app/blob/main/backend/src/routes/auth.route.js"
    click DashboardRoute "https://github.com/samisb2002/chat-app/blob/main/backend/src/routes/dashboard.route.js"
    click MessageRoute "https://github.com/samisb2002/chat-app/blob/main/backend/src/routes/message.route.js"
    click SocketLib "https://github.com/samisb2002/chat-app/blob/main/backend/src/lib/socket.js"
    click Middleware "https://github.com/samisb2002/chat-app/blob/main/backend/src/middleware/auth.middleware.js"
    click UtilsBE "https://github.com/samisb2002/chat-app/blob/main/backend/src/lib/utils.js"
    click DBConn "https://github.com/samisb2002/chat-app/blob/main/backend/src/lib/db.js"
    click UserModel "https://github.com/samisb2002/chat-app/blob/main/backend/src/models/user.model.js"
    click MessageModel "https://github.com/samisb2002/chat-app/blob/main/backend/src/models/message.model.js"
    click RedisLib "https://github.com/samisb2002/chat-app/blob/main/backend/src/lib/redis.js"
    click CloudinaryLib "https://github.com/samisb2002/chat-app/blob/main/backend/src/lib/cloudinary.js"

    %% Styles
    classDef frontend fill:#c3dafe,stroke:#2b6cb0,color:#1a202c
    classDef server fill:#9ae6b4,stroke:#2f855a,color:#1a202c
    classDef storage fill:#fbd38d,stroke:#dd6b20,color:#1a202c
    classDef external fill:#e2e8f0,stroke:#4a5568,color:#1a202c
```
