# danishmemon95/chathive architecture

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

- Interactive diagram: https://gitdiagram.com/danishmemon95/chathive
- Repository: https://github.com/danishmemon95/chathive

## Overview

##### Project type and purpose
- ChatHive is a full-stack real-time chat application.
- The backend uses Node.js and Express to provide REST endpoints and WebSocket (socket.io) support.
- The frontend is a Vite-powered React application with Zustand for state management and Tailwind for styling.

##### File structure
- Top level:
- BackEnd/ — contains Express server code
- FrontEnd/ — contains React application
- package.json, .gitignore, README.md at project root
- Backend:
- src/index.js — server entry point
- Controllers/ — business logic for auth and messaging
- Routes/ — maps HTTP endpoints to controller methods
- Middlewares/ — request validation and JWT authentication
- Models/ — Mongoose schemas for User and Message
- libraries/ — database connection (db.js), Cloudinary file upload, socket initialization, utility functions
- Frontend:
- public/ and index.html — static assets entry
- src/main.jsx and src/App.jsx — React entry point and top-level component
- Components/ — UI widgets (chat container, sidebar, header, inputs, skeleton loaders)
- Pages/ — routeable views (Home, Login, SignUp, Profile, Settings)
- lib/ — Axios wrapper and other utilities
- store/ — Zustand stores for auth, chat, and theme
- tailwind.config.js and vite.config.js — styling and build configuration

##### Insights from README
- The README only contains the project title, so architectural details must be inferred from the code.

##### Detail without over-splitting
- Major moving parts (UI components, API routes, data models, middleware, external integrations)
- Flow of data is clear and end-to-end paths (user clicks send → socket event → db write → broadcast → UI update) are easy to trace.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "React Frontend"
        direction TB
        UI["UI Components"]:::frontend
        Pages["UI Pages (Auth, Chat, Profile, Settings)"]:::frontend
        Stores["State Stores (Zustand)"]:::frontend
        Axios["HTTP Client (Axios)"]:::frontend
        WSClient["WebSocket Client"]:::frontend
        Tailwind["Tailwind Config"]:::frontend
        Vite["Vite Config"]:::frontend
    end

    %% Backend Layer
    subgraph "Express Backend"
        direction TB
        Index["Server Entry Point"]:::backend

        subgraph "API Layer"
            direction TB
            RoutesAuth["Auth Routes (/api/auth)"]:::backend
            RoutesMsg["Message Routes (/api/messages)"]:::backend
        end

        subgraph "Business Layer"
            direction TB
            AuthCtrl["Auth Controller"]:::backend
            MsgCtrl["Message Controller"]:::backend
        end

        Middleware["JWT Auth & Validation"]:::backend

        subgraph "Data Layer"
            direction TB
            UserModel["User Model"]:::backend
            MsgModel["Message Model"]:::backend
            DB["MongoDB Connector"]:::backend
        end

        subgraph "Socket Layer"
            direction TB
            Socket["Socket.io Init & Events"]:::backend
        end

        subgraph "External Service"
            direction TB
            Cloudinary["Cloudinary (Image Storage)"]:::external
        end

        UtilsBE["Backend Utilities"]:::backend
    end

    Mongo["MongoDB Atlas"]:::database

    %% Connections: Frontend -> Backend
    Axios -->|"HTTP :5000"| Index
    WSClient -->|"WS :5000/socket.io"| Socket

    %% Backend internal flows
    Index --> RoutesAuth
    Index --> RoutesMsg
    Index --> Middleware
    Index --> DB
    Index --> Socket
    Index --> UtilsBE

    RoutesAuth -->|"calls"| AuthCtrl
    RoutesMsg -->|"calls"| MsgCtrl

    AuthCtrl -->|"uses"| UserModel
    MsgCtrl -->|"uses"| MsgModel
    MsgCtrl -->|"upload images"| Cloudinary

    UserModel -->|"CRUD"| DB
    MsgModel -->|"CRUD"| DB
    DB --> Mongo

    %% External Service call
    Cloudinary -->|"API"| Cloudinary

    %% Styling
    classDef frontend fill:#cce5ff,stroke:#1f77b4,stroke-width:1px
    classDef backend fill:#d4edda,stroke:#2ca02c,stroke-width:1px
    classDef database fill:#ffe5b4,stroke:#ff7f0e,stroke-width:1px
    classDef external fill:#e0bbff,stroke:#9467bd,stroke-width:1px

    %% Click Events
    click UI "https://github.com/danishmemon95/chathive/tree/main/FrontEnd/src/Components/"
    click Pages "https://github.com/danishmemon95/chathive/tree/main/FrontEnd/src/Pages/"
    click Stores "https://github.com/danishmemon95/chathive/tree/main/FrontEnd/src/store/"
    click Axios "https://github.com/danishmemon95/chathive/blob/main/FrontEnd/src/lib/axios.js"
    click WSClient "https://github.com/danishmemon95/chathive/blob/main/FrontEnd/src/lib/utils.js"
    click Tailwind "https://github.com/danishmemon95/chathive/blob/main/FrontEnd/tailwind.config.js"
    click Vite "https://github.com/danishmemon95/chathive/blob/main/FrontEnd/vite.config.js"

    click Index "https://github.com/danishmemon95/chathive/blob/main/BackEnd/src/index.js"
    click RoutesAuth "https://github.com/danishmemon95/chathive/blob/main/BackEnd/src/Routes/authRoute.js"
    click RoutesMsg "https://github.com/danishmemon95/chathive/blob/main/BackEnd/src/Routes/messageRoutes.js"
    click AuthCtrl "https://github.com/danishmemon95/chathive/blob/main/BackEnd/src/Controllers/authController.js"
    click MsgCtrl "https://github.com/danishmemon95/chathive/blob/main/BackEnd/src/Controllers/messageController.js"
    click Middleware "https://github.com/danishmemon95/chathive/blob/main/BackEnd/src/Middlewares/authMiddleware.js"
    click UserModel "https://github.com/danishmemon95/chathive/blob/main/BackEnd/src/Models/userModel.js"
    click MsgModel "https://github.com/danishmemon95/chathive/blob/main/BackEnd/src/Models/messageModel.js"
    click DB "https://github.com/danishmemon95/chathive/blob/main/BackEnd/src/libraries/db.js"
    click Socket "https://github.com/danishmemon95/chathive/blob/main/BackEnd/src/libraries/socket.js"
    click Cloudinary "https://github.com/danishmemon95/chathive/blob/main/BackEnd/src/libraries/cloudinary.js"
    click UtilsBE "https://github.com/danishmemon95/chathive/blob/main/BackEnd/src/libraries/utils.js"
    click Mongo "https://github.com/danishmemon95/chathive/blob/main/BackEnd/src/libraries/db.js"
```
