# pankil-soni/mern-chat-app architecture

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

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

## Overview

##### Main Components

a) Frontend Layer:
- React Application (Client-side)
- Authentication Components
- Dashboard Components
- Chat Interface Components
- Context Providers (Chat & App State)
- Real-time Socket Client

b) Backend Layer:
- Express.js Server
- Authentication Controllers
- Message Controllers
- Conversation Controllers
- User Controllers
- WebSocket Server (Socket.IO)
- Middleware (User Authentication)

c) External Services:
- MongoDB Database
- AWS S3 (Image Storage)
- Cloudinary (Image Processing)
- Google Cloud AI (Chatbot)
- Email Service (OTP)

##### Component Relationships

- Frontend → Backend (REST API calls)
- Frontend ↔ Backend (WebSocket bidirectional)
- Backend → MongoDB (Data persistence)
- Backend → AWS S3 (Image storage)
- Backend → Cloudinary (Image processing)
- Backend → Google Cloud AI (Chatbot responses)
- Backend → Email Service (OTP delivery)

##### Specific Implementation Details

Key architectural patterns:
- Real-time Communication Layer
- WebSocket connection for:
- Live chat messages
- Typing indicators
- Online status
- Message seen status
- Authentication Flow
- JWT-based auth
- OTP verification path
- File Handling Pipeline
- Image upload flow
- S3 storage integration

##### Component Details

For each major component, include:
- Purpose/responsibility
- Key dependencies
- Security measures
- Scaling considerations

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        RC[React Client]:::frontend
        click RC "https://github.com/pankil-soni/mern-chat-app/tree/main/frontend/src"
        
        subgraph AuthComponents
            AC[Authentication Components]:::frontend
            click AC "https://github.com/pankil-soni/mern-chat-app/tree/main/frontend/src/components/Authentication"
        end
        
        subgraph DashComponents
            CI[Chat Interface]:::frontend
            click CI "https://github.com/pankil-soni/mern-chat-app/tree/main/frontend/src/components/Dashboard"
            CA[Chat Area]:::frontend
            click CA "https://github.com/pankil-soni/mern-chat-app/blob/main/frontend/src/components/Dashboard/ChatArea.js"
            CAT[Chat Area Top]:::frontend
            click CAT "https://github.com/pankil-soni/mern-chat-app/blob/main/frontend/src/components/Dashboard/ChatAreaTop.js"
            SM[Single Message]:::frontend
            click SM "https://github.com/pankil-soni/mern-chat-app/blob/main/frontend/src/components/Dashboard/SingleMessage.js"
        end
        
        subgraph ContextProviders
            AppState[App State Context]:::frontend
            click AppState "https://github.com/pankil-soni/mern-chat-app/blob/main/frontend/src/context/appState.js"
            ChatContext[Chat Context]:::frontend
            click ChatContext "https://github.com/pankil-soni/mern-chat-app/blob/main/frontend/src/context/chatContext.js"
        end
        
        subgraph UserProfile
            PM[Profile Menu]:::frontend
            click PM "https://github.com/pankil-soni/mern-chat-app/blob/main/frontend/src/components/Navbar/ProfileMenu.js"
            PMD[Profile Modal]:::frontend
            click PMD "https://github.com/pankil-soni/mern-chat-app/blob/main/frontend/src/components/miscellaneous/ProfileModal.js"
        end
        
        subgraph FileHandling
            FUM[File Upload Modal]:::frontend
            click FUM "https://github.com/pankil-soni/mern-chat-app/blob/main/frontend/src/components/miscellaneous/FileUploadModal.js"
            DMM[Delete Message Modal]:::frontend
            click DMM "https://github.com/pankil-soni/mern-chat-app/blob/main/frontend/src/components/miscellaneous/DeleteMessageModal.js"
        end
    end
    
    subgraph Backend
        ES[Express Server]:::backend
        click ES "https://github.com/pankil-soni/mern-chat-app/blob/main/backend/index.js"
        
        subgraph Controllers
            AuthC[Auth Controller]:::backend
            click AuthC "https://github.com/pankil-soni/mern-chat-app/blob/main/backend/Controllers/auth_controller.js"
            MsgC[Message Controller]:::backend
            click MsgC "https://github.com/pankil-soni/mern-chat-app/blob/main/backend/Controllers/message_controller.js"
            ConvC[Conversation Controller]:::backend
            click ConvC "https://github.com/pankil-soni/mern-chat-app/blob/main/backend/Controllers/conversation_controller.js"
            UserC[User Controller]:::backend
            click UserC "https://github.com/pankil-soni/mern-chat-app/blob/main/backend/Controllers/userController.js"
        end
        
        subgraph SocketServer
            WS[WebSocket Server]:::websocket
            click WS "https://github.com/pankil-soni/mern-chat-app/tree/main/backend/socket"
            WSH[Socket Handlers]:::websocket
            click WSH "https://github.com/pankil-soni/mern-chat-app/blob/main/backend/socket/handlers.js"
        end
        
        subgraph Middleware
            AuthM[Auth Middleware]:::security
            click AuthM "https://github.com/pankil-soni/mern-chat-app/blob/main/backend/middleware/fetchUser.js"
        end
        
        subgraph Models
            UM[User Model]:::database
            click UM "https://github.com/pankil-soni/mern-chat-app/blob/main/backend/Models/User.js"
            MM[Message Model]:::database
            click MM "https://github.com/pankil-soni/mern-chat-app/blob/main/backend/Models/Message.js"
            CM[Conversation Model]:::database
            click CM "https://github.com/pankil-soni/mern-chat-app/blob/main/backend/Models/Conversation.js"
        end
        
        subgraph ImageProcessing
            IU[Image Upload Handler]:::backend
            click IU "https://github.com/pankil-soni/mern-chat-app/blob/main/backend/config/imageupload.js"
        end
    end
    
    subgraph ExternalServices
        DB[(MongoDB)]:::database
        S3[AWS S3]:::external
        CD[Cloudinary]:::external
        AI[Google Cloud AI]:::external
        EM[Email Service]:::external
    end
    
    %% Connections
    RC --> AuthC
    RC --> MsgC
    RC --> ConvC
    RC --> UserC
    RC <-.-> WS
    
    AuthC --> DB
    MsgC --> DB
    ConvC --> DB
    UserC --> DB
    
    IU --> S3
    IU --> CD
    
    AuthC --> EM
    MsgC --> AI
    
    %% Styles
    classDef frontend fill:#3498db
    classDef backend fill:#2ecc71
    classDef database fill:#f1c40f
    classDef external fill:#e74c3c
    classDef websocket fill:#9b59b6
    classDef security fill:#e67e22
    
    %% Legend
    subgraph Legend
        F[Frontend]:::frontend
        B[Backend]:::backend
        D[Database]:::database
        E[External Services]:::external
        W[WebSocket]:::websocket
        S[Security]:::security
    end
```
