# harshsrivastava1323/letschat architecture

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

- Interactive diagram: https://gitdiagram.com/harshsrivastava1323/letschat
- Repository: https://github.com/harshsrivastava1323/letschat

## Overview

##### Project type and purpose
- This is a full-stack real-time chat application built on the MERN stack (MongoDB, Express, React, Node.js) augmented with Socket.io for live messaging, JWT for auth, Tailwind/DaisyUI for styling, and Zustand for client state.

##### File structure
- Top-level separation:
- frontend/ – React + Vite single-page app
- backend/ – Node.js/Express REST & WebSocket server
- backend/src follows an MVC-style pattern:
- controllers/ – business logic for auth & messages
- models/ – Mongoose schemas (User, Message)
- routes/ – Express routes for HTTP API
- middleware/ – JWT auth guard
- lib/ – DB connection, Cloudinary image service, Socket.io setup, utility helpers
- seeds/ – initial user data
- frontend/src:
- pages/ – route components (Home, Login, Signup, Profile, Settings)
- components/ – UI building blocks (ChatContainer, Navbar, MessageInput, Sidebar, skeleton loaders)
- lib/axios.js – preconfigured HTTP client
- store/ – global Zustand stores (auth, chat, theme)
- constants/ – shared values (e.g., API endpoints)

##### README for additional insights
- Features: JWT-based Auth, real-time messaging via WebSocket, online user status, error handling, free deployment.
- Tech: MERN + Socket.io + TailwindCSS + DaisyUI + Zustand.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (Browser)"
        direction TB
        ReactSPA["React SPA"]:::frontend
        Main["Client Entry Point (main.jsx)"]:::frontend
        App["Root React Component (App.jsx)"]:::frontend
        Pages["Page Components (Home, Login, Signup,\nProfile, Settings)"]:::frontend
        Components["UI Components (ChatContainer,\nNavbar, MessageInput, Sidebar, Loaders)"]:::frontend
        Axios["Preconfigured Axios Client"]:::frontend
        FUtils["Utility Helpers"]:::frontend
        Constants["Application Constants"]:::frontend
        AuthStore["Zustand Auth Store"]:::frontend
        ChatStore["Zustand Chat Store"]:::frontend
        ThemeStore["Zustand Theme Store"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Server)"
        direction TB
        Index["HTTP API Server\n(index.js)"]:::backend
        WSSetup["WebSocket Server Setup\n(socket.js)"]:::backend
        DBConn["MongoDB Connection\n(db.js)"]:::backend
        AuthMiddleware["JWT Auth Middleware"]:::backend
        subgraph "Controllers"
            direction TB
            AuthController["Authentication Controller"]:::backend
            MsgController["Message Controller"]:::backend
        end
        subgraph "Routes"
            direction TB
            AuthRoutes["Authentication Routes"]:::backend
            MsgRoutes["Message Routes"]:::backend
        end
        subgraph "Models"
            direction TB
            UserModel["User Schema"]:::backend
            MsgModel["Message Schema"]:::backend
        end
        Cloudinary["Cloudinary Service"]:::external
        Utils["Utility Helpers"]:::backend
        Seed["Initial User Seed Data"]:::backend
    end

    %% External Services
    MongoDB["MongoDB Atlas"]:::external

    %% Data Flows
    ReactSPA -->|"HTTP REST Calls"| Index
    ReactSPA -.->|"WebSocket Events"| WSSetup
    Main --> ReactSPA
    App --> ReactSPA
    Pages --> App
    Components --> App
    Axios --> ReactSPA
    FUtils --> ReactSPA
    Constants --> ReactSPA
    AuthStore --> ReactSPA
    ChatStore --> ReactSPA
    ThemeStore --> ReactSPA

    Index --> AuthRoutes
    Index --> MsgRoutes
    Index --> DBConn
    Index --> WSSetup
    Index --> Utils
    AuthRoutes -->|uses| AuthController
    MsgRoutes -->|uses| MsgController
    AuthRoutes --> AuthMiddleware
    MsgRoutes --> AuthMiddleware
    AuthController --> UserModel
    MsgController --> MsgModel
    AuthController --> Cloudinary
    MsgController --> Cloudinary
    DBConn --> MongoDB
    Utils -.-> Index
    Seed --> UserModel

    %% Click Events
    click ReactSPA "https://github.com/harshsrivastava1323/letschat/tree/main/frontend/src/"
    click Main "https://github.com/harshsrivastava1323/letschat/blob/main/frontend/src/main.jsx"
    click App "https://github.com/harshsrivastava1323/letschat/blob/main/frontend/src/App.jsx"
    click Axios "https://github.com/harshsrivastava1323/letschat/blob/main/frontend/src/lib/axios.js"
    click FUtils "https://github.com/harshsrivastava1323/letschat/blob/main/frontend/src/lib/utils.js"
    click Constants "https://github.com/harshsrivastava1323/letschat/blob/main/frontend/src/constants/index.js"
    click AuthStore "https://github.com/harshsrivastava1323/letschat/blob/main/frontend/src/store/useAuthStore.js"
    click ChatStore "https://github.com/harshsrivastava1323/letschat/blob/main/frontend/src/store/useChatStore.js"
    click ThemeStore "https://github.com/harshsrivastava1323/letschat/blob/main/frontend/src/store/useThemeStore.js"
    click Index "https://github.com/harshsrivastava1323/letschat/blob/main/backend/src/index.js"
    click WSSetup "https://github.com/harshsrivastava1323/letschat/blob/main/backend/src/lib/socket.js"
    click DBConn "https://github.com/harshsrivastava1323/letschat/blob/main/backend/src/lib/db.js"
    click Cloudinary "https://github.com/harshsrivastava1323/letschat/blob/main/backend/src/lib/cloudinary.js"
    click Utils "https://github.com/harshsrivastava1323/letschat/blob/main/backend/src/lib/utils.js"
    click AuthController "https://github.com/harshsrivastava1323/letschat/blob/main/backend/src/controllers/auth.controller.js"
    click MsgController "https://github.com/harshsrivastava1323/letschat/blob/main/backend/src/controllers/message.controller.js"
    click AuthRoutes "https://github.com/harshsrivastava1323/letschat/blob/main/backend/src/routes/auth.route.js"
    click MsgRoutes "https://github.com/harshsrivastava1323/letschat/blob/main/backend/src/routes/message.route.js"
    click AuthMiddleware "https://github.com/harshsrivastava1323/letschat/blob/main/backend/src/middleware/auth.middleware.js"
    click UserModel "https://github.com/harshsrivastava1323/letschat/blob/main/backend/src/models/user.model.js"
    click MsgModel "https://github.com/harshsrivastava1323/letschat/blob/main/backend/src/models/message.model.js"
    click Seed "https://github.com/harshsrivastava1323/letschat/blob/main/backend/src/seeds/user.seed.js"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#006064,stroke-width:1px
    classDef backend fill:#E8F5E9,stroke:#1B5E20,stroke-width:1px
    classDef external fill:#FFF3E0,stroke:#E65100,stroke-width:1px
```
