# sankalp51/chatify architecture

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

- Interactive diagram: https://gitdiagram.com/sankalp51/chatify
- Repository: https://github.com/sankalp51/chatify

## Overview

##### Project type and purpose
- Chatify is a full-stack, real-time chat application built on the MERN stack (MongoDB, Express.js, React.js, Node.js) with Socket.io for bidirectional messaging.
- Core use cases: user sign-up/login, one-to-one or group chat, emoji support, password reset via email/OTP, file/image uploads, theme toggle.

##### File structure
- Top-level split:
- frontend/ (React + Vite + Tailwind + Redux + Socket.io client)
- backend/ (Node.js + Express + Socket.io server + Mongoose + Redis + Cloudinary + Nodemailer)
- backend layers:
- config/ – 3rd-party setup (DB, Redis, CORS, Multer, Cloudinary, Nodemailer)
- controllers/ – MVC controllers (auth, chat, message, user, password reset)
- middlewares/ – credential checks, JWT verification, error handling
- models/ – Mongoose schemas (User, Chat, Message)
- routes/ – Express routers for REST endpoints
- utils/ – OTP generation/email templating
- views/public/ – static HTML/CSS (404, index)
- frontend layers:
- src/components/ – UI components (base_components & shadcn/ui)
- src/context & redux/features – global state (auth, chats, notifications)
- src/hooks – custom hooks (Axios instance, auth, theme, refresh tokens)
- src/pages & layouts – top-level pages (Auth, Home, ResetPassword) + route wrappers
- src/socket.ts – Socket.io client initialization
- src/utils/lib – helper functions (chat logic, axios config)

##### README insights
- Explicit list of tech stack
- Emphasis on real-time messaging via Socket.io
- JWT for auth, Redis for caching/session, Cloudinary for media, Multer for uploads, Nodemailer for emails

##### Detail without over-splitting
- Every major module: UI, state, API, real-time, DB, cache, media, email
- Data flows (REST vs WebSocket) are clearly differentiated and labeled

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "React App" 
        direction TB
        FC["Frontend Client<br/>(React/Vite/Tailwind/Redux/Socket.io-client)"]:::frontend
        UI["UI Components"]:::frontend
        SM["State Management<br/>(Redux & Context)"]:::frontend
        HK["Custom Hooks"]:::frontend
        PG["Pages & Layouts"]:::frontend
        SC["Socket.io Client"]:::frontend
        UT["Utilities<br/>(Axios, chatLogic, helpers)"]:::frontend
    end

    %% API Layer
    subgraph "Express API" 
        direction TB
        APIGW["API Gateway<br/>(Express.js + CORS + JSON + JWT)"]:::backend
        subgraph "Middleware & Config"
            direction TB
            CORS["CORS & JSON Parser"]:::backend
            CRED["Credentials Check"]:::backend
            JWTM["JWT Verification"]:::backend
            ERRH["Error Handler"]:::backend
        end
        subgraph "Routes"
            direction TB
            AR["Auth Routes"]:::backend
            CR["Chat Routes"]:::backend
            MR["Message Routes"]:::backend
            RR["ResetPassword Routes"]:::backend
            UR["User Routes"]:::backend
        end
        subgraph "Controllers"
            direction TB
            AC["AuthController"]:::backend
            RTC["RefreshTokenController"]:::backend
            RPC["ResetPasswordController"]:::backend
            CC["ChatController"]:::backend
            MC["MessageController"]:::backend
            UC["UserController"]:::backend
        end
        subgraph "Config & Utils"
            direction TB
            DBCFG["DB Connection"]:::backend
            REDISCFG["Redis Config"]:::backend
            MULTER["Multer Config"]:::backend
            CLOUCFG["Cloudinary Config"]:::backend
            MAILCFG["Nodemailer Config"]:::backend
            OTP["OTP Utils"]:::backend
            EMAILTPL["OTP Email Template"]:::backend
        end
    end

    %% Real-time Server
    SC -->|connects| APIGW
    SC -->|emit/listen| MC
    SC -->|emit/listen| CC

    %% RESTful Flows
    FC -->|REST calls| APIGW
    APIGW -->|use| CORS
    APIGW -->|use| CRED
    APIGW -->|use| JWTM
    APIGW -->|use| ERRH
    APIGW -->|route| AR
    APIGW -->|route| CR
    APIGW -->|route| MR
    APIGW -->|route| RR
    APIGW -->|route| UR

    %% Route to Controller
    AR --> AC
    AR --> RTC
    AR --> RPC
    CR --> CC
    MR --> MC
    UR --> UC
    RR --> RPC

    %% Controllers to Data Layer
    AC -->|issue JWT| REDISCFG
    RTC -->|refresh tokens| REDISCFG
    RPC -->|OTP| OTP
    RPC -->|send email| EMAILTPL
    RPC -->|mail via| MAILCFG
    CC --> DBCFG
    MC --> DBCFG
    UC --> DBCFG

    %% Media Upload Flow
    CC -->|upload| MULTER
    MULTER -->|store media| CLOUCFG
    CLOUCFG --> DBCFG

    %% Data Stores
    DB["MongoDB"]:::datastore
    RD["Redis"]:::datastore

    DBCFG --> DB
    REDISCFG --> RD

    %% External Services
    CLD["Cloudinary"]:::external
    SMTP["Nodemailer/SMTP"]:::external

    CLOUCFG --> CLD
    MAILCFG --> SMTP

    %% Frontend Composition
    FC --> UI
    FC --> SM
    FC --> HK
    FC --> PG
    FC --> UT

    %% Click Events
    click FC "https://github.com/sankalp51/chatify/tree/main/frontend/src"
    click APIGW "https://github.com/sankalp51/chatify/blob/main/backend/server.js"
    click SC "https://github.com/sankalp51/chatify/blob/main/backend/server.js"
    click AC "https://github.com/sankalp51/chatify/blob/main/backend/controllers/auth/authControllers.js"
    click RTC "https://github.com/sankalp51/chatify/blob/main/backend/controllers/auth/refreshTokenController.js"
    click RPC "https://github.com/sankalp51/chatify/blob/main/backend/controllers/auth/resetPasswordController.js"
    click CC "https://github.com/sankalp51/chatify/blob/main/backend/controllers/chatControllers.js"
    click MC "https://github.com/sankalp51/chatify/blob/main/backend/controllers/messageController.js"
    click UC "https://github.com/sankalp51/chatify/blob/main/backend/controllers/userControllers.js"
    click AR "https://github.com/sankalp51/chatify/blob/main/backend/routes/authRoutes/authRoutes.js"
    click CR "https://github.com/sankalp51/chatify/blob/main/backend/routes/chatRoutes.js"
    click MR "https://github.com/sankalp51/chatify/blob/main/backend/routes/messageRoutes.js"
    click RR "https://github.com/sankalp51/chatify/blob/main/backend/routes/resetPasswordRoutes.js"
    click UR "https://github.com/sankalp51/chatify/blob/main/backend/routes/userRoutes.js"
    click CORS "https://github.com/sankalp51/chatify/blob/main/backend/config/corsConfig.js"
    click CRED "https://github.com/sankalp51/chatify/blob/main/backend/middlewares/credentials.js"
    click JWTM "https://github.com/sankalp51/chatify/blob/main/backend/middlewares/verifyJwt.js"
    click ERRH "https://github.com/sankalp51/chatify/blob/main/backend/middlewares/errorHandler.js"
    click DBCFG "https://github.com/sankalp51/chatify/blob/main/backend/config/db.js"
    click REDISCFG "https://github.com/sankalp51/chatify/blob/main/backend/config/redisConfig.js"
    click MULTER "https://github.com/sankalp51/chatify/blob/main/backend/config/multerConfig.js"
    click CLOUCFG "https://github.com/sankalp51/chatify/blob/main/backend/config/cloudinaryConfig.js"
    click MAILCFG "https://github.com/sankalp51/chatify/blob/main/backend/config/nodemailerConfig.js"
    click OTP "https://github.com/sankalp51/chatify/blob/main/backend/utils/otp.js"
    click EMAILTPL "https://github.com/sankalp51/chatify/blob/main/backend/utils/otpEmailTemplate.js"
    click DB "https://github.com/sankalp51/chatify/blob/main/backend/models/User.js"
    click DB "https://github.com/sankalp51/chatify/blob/main/backend/models/Chat.js"
    click DB "https://github.com/sankalp51/chatify/blob/main/backend/models/Message.js"
    click UI "https://github.com/sankalp51/chatify/tree/main/frontend/src/components/base_components"
    click UI "https://github.com/sankalp51/chatify/tree/main/frontend/src/components/ui"
    click SM "https://github.com/sankalp51/chatify/blob/main/frontend/src/redux/store.ts"
    click SM "https://github.com/sankalp51/chatify/tree/main/frontend/src/redux/features"
    click SM "https://github.com/sankalp51/chatify/tree/main/frontend/src/context"
    click HK "https://github.com/sankalp51/chatify/tree/main/frontend/src/hooks"
    click PG "https://github.com/sankalp51/chatify/blob/main/frontend/src/pages/Auth.tsx"
    click PG "https://github.com/sankalp51/chatify/blob/main/frontend/src/pages/Home.tsx"
    click PG "https://github.com/sankalp51/chatify/blob/main/frontend/src/pages/ResetPassword.tsx"
    click PG "https://github.com/sankalp51/chatify/blob/main/frontend/src/layouts/AuthLayout.tsx"
    click PG "https://github.com/sankalp51/chatify/blob/main/frontend/src/layouts/MainLayout.tsx"
    click PG "https://github.com/sankalp51/chatify/blob/main/frontend/src/layouts/PersistLogin.tsx"
    click SC "https://github.com/sankalp51/chatify/blob/main/frontend/src/socket.ts"
    click UT "https://github.com/sankalp51/chatify/blob/main/frontend/src/utils/axios.ts"
    click UT "https://github.com/sankalp51/chatify/blob/main/frontend/src/utils/chatLogic.ts"
    click UT "https://github.com/sankalp51/chatify/blob/main/frontend/src/lib/utils.ts"

    %% Styles
    classDef frontend fill:#E8F1FF,stroke:#0366d6,stroke-width:1px
    classDef backend fill:#E6FFEB,stroke:#137333,stroke-width:1px
    classDef datastore fill:#FFF4E5,stroke:#b35c00,stroke-width:1px
    classDef external fill:#F3E5FF,stroke:#6f42c1,stroke-width:1px
```
