# burakorkmez/mern-chat-app architecture

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

- Interactive diagram: https://gitdiagram.com/burakorkmez/mern-chat-app
- Repository: https://github.com/burakorkmez/mern-chat-app

## Overview

##### Project type and purpose
- This is a full-stack real-time chat application built on the MERN stack (MongoDB, Express, React, Node) with JWT authentication, Socket.io for realtime messaging, TailwindCSS for styling, and Zustand for client state management.
- The README confirms features: user signup/login, protected routes, real-time messaging, online-user status, error handling, and deployment instructions.

##### File structure
- Top-level “backend” folder follows an MVC pattern:
- controllers/ (auth, user, message)
- models/ (User, Conversation, Message)
- routes/ (auth.routes.js, user.routes.js, message.routes.js)
- middleware (protectRoute for JWT enforcement)
- db/connectToMongoDB (DB connection)
- socket/socket.js (Socket.io setup)
- utils/generateToken.js
- server.js (Express app entrypoint)
- Top-level “frontend” folder is a Vite-powered React SPA:
- public/ & index.html
- src/components (sidebar, messages, skeletons)
- src/pages (Login, SignUp, Home)
- src/context (AuthContext, SocketContext)
- src/hooks (custom hooks for API calls & socket listening)
- src/zustand (global state management)
- config files (ESLint, PostCSS, Tailwind, Vite)

##### README for additional insights
- Confirms tech stack, JWT, Socket.io, Zustand, Tailwind, DaisyUI.
- Mentions deploying and environment variables (PORT, MONGO_DB_URI, JWT_SECRET, NODE_ENV).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (React SPA)"
        direction TB
        FE_App["App.jsx"]:::frontend
        FE_indexCSS["index.css"]:::frontend
        FE_main["main.jsx"]:::frontend

        subgraph "Pages"
            direction TB
            FE_Home["Home.jsx"]:::frontend
            FE_Login["Login.jsx"]:::frontend
            FE_SignUp["SignUp.jsx"]:::frontend
        end

        subgraph "Components"
            direction TB
            FE_Sidebar["Sidebar.jsx"]:::frontend
            FE_Conversation["Conversation.jsx"]:::frontend
            FE_Conversations["Conversations.jsx"]:::frontend
            FE_SearchInput["SearchInput.jsx"]:::frontend
            FE_LogoutButton["LogoutButton.jsx"]:::frontend
            FE_Messages["Messages.jsx"]:::frontend
            FE_MessageContainer["MessageContainer.jsx"]:::frontend
            FE_Message["Message.jsx"]:::frontend
            FE_MessageInput["MessageInput.jsx"]:::frontend
            FE_MessageSkeleton["MessageSkeleton.jsx"]:::frontend
        end

        subgraph "State & Context"
            direction TB
            FE_AuthContext["AuthContext.jsx"]:::frontend
            FE_SocketContext["SocketContext.jsx"]:::frontend
            FE_UseConversation["useConversation.js"]:::frontend
        end

        subgraph "Hooks"
            direction TB
            FE_useLogin["useLogin.js"]:::frontend
            FE_useSignup["useSignup.js"]:::frontend
            FE_useLogout["useLogout.js"]:::frontend
            FE_useGetConversations["useGetConversations.js"]:::frontend
            FE_useGetMessages["useGetMessages.js"]:::frontend
            FE_useSendMessage["useSendMessage.js"]:::frontend
            FE_useListenMessages["useListenMessages.js"]:::frontend
        end

        subgraph "Utilities"
            direction TB
            FE_extractTime["extractTime.js"]:::frontend
            FE_emojis["emojis.js"]:::frontend
        end

        subgraph "Config & Styling"
            direction TB
            FE_tailwind["tailwind.config.js"]:::frontend
            FE_postcss["postcss.config.js"]:::frontend
            FE_eslint[".eslintrc.cjs"]:::frontend
            FE_vite["vite.config.js"]:::frontend
            FE_indexHTML["index.html"]:::frontend
        end
    end

    %% Backend Layer
    subgraph "Backend (Express API)"
        direction TB
        BE_Server["server.js"]:::backend

        subgraph "Controllers"
            direction TB
            BE_authCtrl["auth.controller.js"]:::backend
            BE_userCtrl["user.controller.js"]:::backend
            BE_msgCtrl["message.controller.js"]:::backend
        end

        subgraph "Routes"
            direction TB
            BE_authRoutes["auth.routes.js"]:::backend
            BE_userRoutes["user.routes.js"]:::backend
            BE_msgRoutes["message.routes.js"]:::backend
        end

        subgraph "Middleware"
            direction TB
            BE_protect["protectRoute.js"]:::backend
        end

        subgraph "DB Connection"
            direction TB
            BE_connectDB["connectToMongoDB.js"]:::backend
        end

        subgraph "Real-time Engine"
            direction TB
            BE_socket["socket.js"]:::realtime
        end

        subgraph "Utilities"
            direction TB
            BE_generateToken["generateToken.js"]:::backend
        end
    end

    %% Database
    DB[(MongoDB)]:::database

    %% Interactions
    FE_App -->|HTTP REST| BE_Server
    FE_Login -->|HTTP POST /auth/login| BE_authRoutes
    FE_SignUp -->|HTTP POST /auth/signup| BE_authRoutes
    FE_AuthContext -->|provides token| FE_App
    FE_App -->|uses context| FE_SocketContext
    FE_SocketContext -->|WebSocket connect| BE_socket
    FE_Messages -->|emit send_message| BE_socket
    BE_socket -->|broadcast receive_message| FE_Messages
    BE_Server -->|uses Controllers| BE_authCtrl
    BE_Server -->|uses Controllers| BE_userCtrl
    BE_Server -->|uses Controllers| BE_msgCtrl
    BE_authRoutes -->|calls| BE_authCtrl
    BE_userRoutes -->|calls| BE_userCtrl
    BE_msgRoutes -->|calls| BE_msgCtrl
    BE_Server -->|applies| BE_protect
    BE_Server -->|connects to| DB
    BE_connectDB -->|initializes| DB
    BE_generateToken -->|used by| BE_authCtrl

    %% Click Events - Frontend
    click FE_App "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/App.jsx"
    click FE_indexCSS "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/index.css"
    click FE_main "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/main.jsx"
    click FE_Home "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/pages/home/Home.jsx"
    click FE_Login "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/pages/login/Login.jsx"
    click FE_SignUp "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/pages/signup/SignUp.jsx"
    click FE_Sidebar "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/components/sidebar/Sidebar.jsx"
    click FE_Conversation "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/components/sidebar/Conversation.jsx"
    click FE_Conversations "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/components/sidebar/Conversations.jsx"
    click FE_SearchInput "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/components/sidebar/SearchInput.jsx"
    click FE_LogoutButton "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/components/sidebar/LogoutButton.jsx"
    click FE_Messages "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/components/messages/Messages.jsx"
    click FE_MessageContainer "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/components/messages/MessageContainer.jsx"
    click FE_Message "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/components/messages/Message.jsx"
    click FE_MessageInput "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/components/messages/MessageInput.jsx"
    click FE_MessageSkeleton "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/components/skeletons/MessageSkeleton.jsx"
    click FE_AuthContext "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/context/AuthContext.jsx"
    click FE_SocketContext "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/context/SocketContext.jsx"
    click FE_UseConversation "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/zustand/useConversation.js"
    click FE_useLogin "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/hooks/useLogin.js"
    click FE_useSignup "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/hooks/useSignup.js"
    click FE_useLogout "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/hooks/useLogout.js"
    click FE_useGetConversations "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/hooks/useGetConversations.js"
    click FE_useGetMessages "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/hooks/useGetMessages.js"
    click FE_useSendMessage "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/hooks/useSendMessage.js"
    click FE_useListenMessages "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/hooks/useListenMessages.js"
    click FE_extractTime "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/utils/extractTime.js"
    click FE_emojis "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/src/utils/emojis.js"
    click FE_tailwind "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/tailwind.config.js"
    click FE_postcss "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/postcss.config.js"
    click FE_eslint "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/.eslintrc.cjs"
    click FE_vite "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/vite.config.js"
    click FE_indexHTML "https://github.com/burakorkmez/mern-chat-app/blob/master/frontend/public/index.html"

    %% Click Events - Backend
    click BE_Server "https://github.com/burakorkmez/mern-chat-app/blob/master/backend/server.js"
    click BE_authCtrl "https://github.com/burakorkmez/mern-chat-app/blob/master/backend/controllers/auth.controller.js"
    click BE_userCtrl "https://github.com/burakorkmez/mern-chat-app/blob/master/backend/controllers/user.controller.js"
    click BE_msgCtrl "https://github.com/burakorkmez/mern-chat-app/blob/master/backend/controllers/message.controller.js"
    click BE_authRoutes "https://github.com/burakorkmez/mern-chat-app/blob/master/backend/routes/auth.routes.js"
    click BE_userRoutes "https://github.com/burakorkmez/mern-chat-app/blob/master/backend/routes/user.routes.js"
    click BE_msgRoutes "https://github.com/burakorkmez/mern-chat-app/blob/master/backend/routes/message.routes.js"
    click BE_protect "https://github.com/burakorkmez/mern-chat-app/blob/master/backend/middleware/protectRoute.js"
    click BE_connectDB "https://github.com/burakorkmez/mern-chat-app/blob/master/backend/db/connectToMongoDB.js"
    click BE_socket "https://github.com/burakorkmez/mern-chat-app/blob/master/backend/socket/socket.js"
    click BE_generateToken "https://github.com/burakorkmez/mern-chat-app/blob/master/backend/utils/generateToken.js"

    %% Styles
    classDef frontend fill:#EEF6FF,stroke:#3B82F6,stroke-width:1px
    classDef backend fill:#F0FDF4,stroke:#10B981,stroke-width:1px
    classDef realtime fill:#FFF7ED,stroke:#F97316,stroke-width:1px
    classDef database fill:#FDF2F8,stroke:#DB2777,stroke-width:1px,stroke-dasharray: 5 5
```
