# ayaan-22/forger architecture

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

- Interactive diagram: https://gitdiagram.com/ayaan-22/forger
- Repository: https://github.com/ayaan-22/forger

## Overview

##### Project Type and Purpose
- This is a full-stack real-time chat application ("Forger").
- Frontend: React single-page app (Vite + Tailwind + Zustand).
- Backend: Node.js/Express REST API plus Socket.IO for real-time messaging.
- Persistence: MongoDB (via Mongoose).
- External service: Cloudinary for user image uploads.

##### File Structure
- client/ – React code organized into pages, components, constants, lib (axios helper), store (Zustand).
- server/ – Express entry point (index.js), controllers (auth, message), routes, middleware (JWT auth), models (User, Message), lib (db connection, socket setup, Cloudinary).

##### Main Components
a. Frontend SPA
- Pages (Home, Login, Signup, Profile, Settings)
- Components (Navbar, ChatContainer, MessageInput, etc.)
- State stores (useAuthStore, useChatStore, useThemeStore)
b. Backend API Server
- REST API endpoints (/auth, /messages) handled by authControllers & messageControllers
- JWT auth middleware
- Socket.IO server instance
- DB connector via db.js
- Cloudinary integration via cloudinary.js
c. Database
- MongoDB (User & Message collections)
d. External Services
- Cloudinary (image uploads)

##### Relationships and Data Flows
- Frontend → Backend (HTTP/REST via Axios) for signup, login, profile fetch, message history.
- Frontend ↔ Backend (WebSocket via Socket.IO) for real‐time message send/receive.
- Backend → Database (MongoDB) to persist/fetch users & messages.
- Backend → Cloudinary for storing/retrieving uploaded avatars or images.

##### Architectural Patterns & Design Principles
- SPA (decoupled client + server)
- MVC‐style on server (routes → controllers → models)
- Middleware for auth enforcement
- State management (Zustand) on client
- Real-time publish/subscribe via Socket.IO

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (React + Vite + Tailwind)" 
        direction TB
        HP["HomePage.jsx"] 
        LP["LoginPage.jsx"] 
        SP["SignUpPage.jsx"] 
        PP["ProfilePage.jsx"] 
        SetP["SettingsPage.jsx"] 
        Navbar["Navbar.jsx"] 
        ChatContainer["ChatContainer.jsx"] 
        ChatHeader["ChatHeader.jsx"] 
        MessageInput["MessageInput.jsx"] 
        Sidebar["Sidebar.jsx"] 
        NoChat["NoChatSelected.jsx"] 
        AuthImg["AuthImagePattern.jsx"] 
        MsgSkel["MessageSkeleton.jsx"] 
        SideSkel["SidebarSkeleton.jsx"] 
        AuthStore["useAuthStore.js"] 
        ChatStore["useChatStore.js"] 
        ThemeStore["useThemeStore.js"] 
        AxiosLib["axios.js"] 
        UtilsClient["utils.js"] 
    end

    %% Backend Layer
    subgraph "Backend (Express + Socket.IO)" 
        direction TB
        Index["index.js"] 
        subgraph "Routes"
            direction TB
            AuthR["authRoutes.js"] 
            MsgR["messageRoutes.js"] 
        end
        subgraph "Controllers"
            direction TB
            AuthC["authControllers.js"] 
            MsgC["messageControllers.js"] 
        end
        AuthMdw["authMiddleware.js"] 
        SockLib["socket.js"] 
        DBConn["db.js"] 
        CloudLib["cloudinary.js"] 
        UtilsSrv["utils.js"] 
    end

    %% Data & Services Layer
    subgraph "Data & Services" 
        direction TB
        DB[(MongoDB)] 
        Cloud["Cloudinary"] 
    end

    %% Client to Server Communications
    AxiosLib -->|"REST/JSON (Axios)"| AuthR
    AxiosLib -->|"REST/JSON (Axios)"| MsgR
    ChatContainer -->|"Socket.IO"| SockLib

    %% Server Internal Flows
    Index --> AuthR
    Index --> MsgR
    Index --> SockLib
    AuthR --> AuthMdw
    AuthR --> AuthC
    MsgR --> AuthMdw
    MsgR --> MsgC
    AuthC -->|"Mongoose ORM"| DB
    MsgC -->|"Mongoose ORM"| DB
    AuthC -->|"Cloudinary SDK"| Cloud
    SockLib --> MsgC

    %% Backend DB & Cloud connections
    DBConn --> DB
    CloudLib --> Cloud

    %% Click Events - Frontend
    click HP "https://github.com/ayaan-22/forger/blob/main/client/src/pages/HomePage.jsx"
    click LP "https://github.com/ayaan-22/forger/blob/main/client/src/pages/LoginPage.jsx"
    click SP "https://github.com/ayaan-22/forger/blob/main/client/src/pages/SignUpPage.jsx"
    click PP "https://github.com/ayaan-22/forger/blob/main/client/src/pages/ProfilePage.jsx"
    click SetP "https://github.com/ayaan-22/forger/blob/main/client/src/pages/SettingsPage.jsx"
    click Navbar "https://github.com/ayaan-22/forger/blob/main/client/src/components/Navbar.jsx"
    click ChatContainer "https://github.com/ayaan-22/forger/blob/main/client/src/components/ChatContainer.jsx"
    click ChatHeader "https://github.com/ayaan-22/forger/blob/main/client/src/components/ChatHeader.jsx"
    click MessageInput "https://github.com/ayaan-22/forger/blob/main/client/src/components/MessageInput.jsx"
    click Sidebar "https://github.com/ayaan-22/forger/blob/main/client/src/components/Sidebar.jsx"
    click NoChat "https://github.com/ayaan-22/forger/blob/main/client/src/components/NoChatSelected.jsx"
    click AuthImg "https://github.com/ayaan-22/forger/blob/main/client/src/components/AuthImagePattern.jsx"
    click MsgSkel "https://github.com/ayaan-22/forger/blob/main/client/src/components/skeletons/MessageSkeleton.jsx"
    click SideSkel "https://github.com/ayaan-22/forger/blob/main/client/src/components/skeletons/SidebarSkeleton.jsx"
    click AuthStore "https://github.com/ayaan-22/forger/blob/main/client/src/store/useAuthStore.js"
    click ChatStore "https://github.com/ayaan-22/forger/blob/main/client/src/store/useChatStore.js"
    click ThemeStore "https://github.com/ayaan-22/forger/blob/main/client/src/store/useThemeStore.js"
    click AxiosLib "https://github.com/ayaan-22/forger/blob/main/client/src/lib/axios.js"
    click UtilsClient "https://github.com/ayaan-22/forger/blob/main/client/src/lib/utils.js"

    %% Click Events - Backend
    click Index "https://github.com/ayaan-22/forger/blob/main/server/src/index.js"
    click AuthR "https://github.com/ayaan-22/forger/blob/main/server/src/routes/authRoutes.js"
    click MsgR "https://github.com/ayaan-22/forger/blob/main/server/src/routes/messageRoutes.js"
    click AuthC "https://github.com/ayaan-22/forger/blob/main/server/src/controllers/authControllers.js"
    click MsgC "https://github.com/ayaan-22/forger/blob/main/server/src/controllers/messageControllers.js"
    click AuthMdw "https://github.com/ayaan-22/forger/blob/main/server/src/middleware/authMiddleware.js"
    click SockLib "https://github.com/ayaan-22/forger/blob/main/server/src/lib/socket.js"
    click DBConn "https://github.com/ayaan-22/forger/blob/main/server/src/lib/db.js"
    click CloudLib "https://github.com/ayaan-22/forger/blob/main/server/src/lib/cloudinary.js"
    click UtilsSrv "https://github.com/ayaan-22/forger/blob/main/server/src/lib/utils.js"
    
    %% Styles
    classDef frontend fill:#D6EAF8,stroke:#1B4F72,color:#1B2631
    classDef backend fill:#D5F5E3,stroke:#186A3B,color:#1B2631
    classDef data fill:#FCF3CF,stroke:#B9770E,color:#1B2631

    class HP,LP,SP,PP,SetP,Navbar,ChatContainer,ChatHeader,MessageInput,Sidebar,NoChat,AuthImg,MsgSkel,SideSkel,AuthStore,ChatStore,ThemeStore,AxiosLib,UtilsClient frontend
    class Index,AuthR,MsgR,AuthC,MsgC,AuthMdw,SockLib,DBConn,CloudLib,UtilsSrv backend
    class DB,Cloud data
```
