# satwik152/chatza architecture

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

- Interactive diagram: https://gitdiagram.com/satwik152/chatza
- Repository: https://github.com/satwik152/chatza

## Overview

##### Project type and purpose
- This is a full-stack real-time chat application (“Full Stack Realtime Chat App”) built with the MERN stack (MongoDB, Express/Node.js, React), Socket.io for real-time messaging, Zustand for client state management, TailwindCSS + DaisyUI for styling, JWT for auth, and Cloudinary for image handling.

##### File structure
- Top-level directories:
- backend/ – Node.js/Express application, REST controllers, WebSocket logic (src/lib/socket.js), models (User, Message), middleware (auth), routes, seed data, configuration (db, cloudinary).
- frontend/ – React application with Vite, TailwindCSS, DaisyUI; pages (Home, Login, SignUp, Profile, Settings), reusable components (ChatContainer, Sidebar, Navbar, MessageInput, skeleton loaders), shared libs (axios wrapper, utils), global stores (Zustand for auth, chat, theme).
- Build and deployment scripts in package.json; .env variables for MongoDB URI, port, JWT secret, Cloudinary credentials.

##### Key insights from README
- Real-time events handled over WebSockets (Socket.io).
- REST API endpoints for auth (signup/login/JWT) and message history.
- Online user status maintained via sockets.
- Client-side global state via Zustand.
- Error handling on both server and client.
- Deployment targets unspecified, but build/start commands provided.

##### Main components and their interactions
a. Frontend (Browser/React App)
- UI pages/components → React/Vite dev server or built static assets served by hosting.
- Uses HTTP(S) REST calls (axios) to backend for signup, login, fetching message history, profile, settings.
- Opens a Socket.io connection to backend for real-time messaging, user status updates.
- State management by Zustand stores (auth, chat, theme).

b. Backend (Express/Node.js server)
- HTTP server exposing REST routes (/auth, /messages).
- Socket.io server bound to same HTTP server (or separate port) to handle handshake, authentication (JWT in socket handshake), join rooms, broadcast messages, track online users.
- Controllers coordinate DB operations via Mongoose models (User, Message).
- Middleware enforces JWT on protected REST and socket events.
- Utilities: cloudinary.js for image uploads (e.g., profile pics), db.js for MongoDB connection, utils.js for shared helpers.

c. Database
- MongoDB (cloud or local) with two collections: users, messages.

d. External services
- Cloudinary for storing profile images or any media attachments.

##### Architectural patterns and design principles
- Separation of concerns: frontend vs. backend layers.
- MVC‐style pattern on server: controllers, models, routes.
- Pub/Sub real-time messaging through Socket.io.
- Stateless REST API with JWT authentication.
- Client state management with a unidirectional data flow (Zustand stores).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client (Frontend)"
        direction TB
        FEApp["React App"]:::frontend
        Pages["Pages:\nHome, Login, SignUp,\nProfile, Settings"]:::frontend
        Components["Components:\nChatContainer, Sidebar,\nNavbar, ChatHeader,\nMessageInput, NoChatSelected,\nAuthImagePattern, Skeletons"]:::frontend
        Stores["Zustand Stores:\nauthStore, chatStore,\nthemeStore"]:::frontend
        Libs["Lib & Config:\naxios.js, utils.js,\ntailwind.config.js,\nvite.config.js"]:::frontend
        FEApp --> Pages
        FEApp --> Components
        FEApp --> Stores
        FEApp --> Libs
        click FEApp "https://github.com/satwik152/chatza/tree/main/frontend/"
        click Pages "https://github.com/satwik152/chatza/blob/main/frontend/src/pages/HomePage.jsx"
        click Pages "https://github.com/satwik152/chatza/blob/main/frontend/src/pages/LoginPage.jsx"
        click Pages "https://github.com/satwik152/chatza/blob/main/frontend/src/pages/SignUpPage.jsx"
        click Pages "https://github.com/satwik152/chatza/blob/main/frontend/src/pages/ProfilePage.jsx"
        click Pages "https://github.com/satwik152/chatza/blob/main/frontend/src/pages/SettingsPage.jsx"
        click Components "https://github.com/satwik152/chatza/blob/main/frontend/src/components/ChatContainer.jsx"
        click Components "https://github.com/satwik152/chatza/blob/main/frontend/src/components/Sidebar.jsx"
        click Components "https://github.com/satwik152/chatza/blob/main/frontend/src/components/Navbar.jsx"
        click Components "https://github.com/satwik152/chatza/blob/main/frontend/src/components/ChatHeader.jsx"
        click Components "https://github.com/satwik152/chatza/blob/main/frontend/src/components/MessageInput.jsx"
        click Components "https://github.com/satwik152/chatza/blob/main/frontend/src/components/NoChatSelected.jsx"
        click Components "https://github.com/satwik152/chatza/blob/main/frontend/src/components/AuthImagePattern.jsx"
        click Components "https://github.com/satwik152/chatza/tree/main/frontend/src/components/skeletons/"
        click Libs "https://github.com/satwik152/chatza/blob/main/frontend/src/lib/axios.js"
        click Libs "https://github.com/satwik152/chatza/blob/main/frontend/src/lib/utils.js"
        click Libs "https://github.com/satwik152/chatza/blob/main/frontend/tailwind.config.js"
        click Libs "https://github.com/satwik152/chatza/blob/main/frontend/vite.config.js"
        click Stores "https://github.com/satwik152/chatza/blob/main/frontend/src/store/useAuthStore.js"
        click Stores "https://github.com/satwik152/chatza/blob/main/frontend/src/store/useChatStore.js"
        click Stores "https://github.com/satwik152/chatza/blob/main/frontend/src/store/useThemeStore.js"
    end

    subgraph "Backend (Node.js/Express + Socket.io)"
        direction TB
        BEApp["Server Entry\nindex.js"]:::backend
        AuthCtrl["Auth Controller"]:::backend
        MsgCtrl["Message Controller"]:::backend
        AuthMid["Auth Middleware"]:::backend
        SocketHd["Socket.io Handler"]:::backend
        DBConn["DB Connector"]:::backend
        CLDUtil["Cloudinary Utility"]:::backend
        Utils["Shared Helpers"]:::backend
        BEApp --> AuthCtrl
        BEApp --> MsgCtrl
        BEApp --> SocketHd
        AuthCtrl --> AuthMid
        MsgCtrl --> AuthMid
        BEApp --> DBConn
        BEApp --> CLDUtil
        BEApp --> Utils
        click BEApp "https://github.com/satwik152/chatza/blob/main/backend/src/index.js"
        click AuthCtrl "https://github.com/satwik152/chatza/blob/main/backend/src/controllers/auth.controller.js"
        click MsgCtrl "https://github.com/satwik152/chatza/blob/main/backend/src/controllers/message.controller.js"
        click AuthMid "https://github.com/satwik152/chatza/blob/main/backend/src/middleware/auth.middleware.js"
        click SocketHd "https://github.com/satwik152/chatza/blob/main/backend/src/lib/socket.js"
        click DBConn "https://github.com/satwik152/chatza/blob/main/backend/src/lib/db.js"
        click CLDUtil "https://github.com/satwik152/chatza/blob/main/backend/src/lib/cloudinary.js"
        click Utils "https://github.com/satwik152/chatza/blob/main/backend/src/lib/utils.js"
    end

    FEApp -->|"HTTP: POST /auth/login, POST /auth/signup, GET /messages"| BEApp
    FEApp -.->|"WS: connection, join_room, send_message, receive_message, user_online"| SocketHd

    DB["MongoDB\n(users, messages)"]:::db
    BEApp -->|"Reads/Writes"| DB
    click DB "https://github.com/satwik152/chatza/blob/main/backend/src/models/user.model.js"
    click DB "https://github.com/satwik152/chatza/blob/main/backend/src/models/message.model.js"

    CLD["Cloudinary"]:::external
    BEApp -->|"Uploads/Downloads Media"| CLD
    click CLD "https://github.com/satwik152/chatza/blob/main/backend/src/lib/cloudinary.js"

    classDef frontend fill:#cce5ff,stroke:#004085;
    classDef backend fill:#d4edda,stroke:#155724;
    classDef db fill:#fff3cd,stroke:#856404;
    classDef external fill:#e2e3e5,stroke:#6c757d;
```
