# prateekkumar2204/social-media architecture

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

- Interactive diagram: https://gitdiagram.com/prateekkumar2204/social-media
- Repository: https://github.com/prateekkumar2204/social-media

## Overview

##### Project type and purpose
- This is a full-stack social-media application with real-time group chat and video-call features.
- The backend is a Node.js/Express REST API with authentication, user/group/message/post models.
- The frontend is a React/Vite single-page app styled with SCSS, handling routing, chat UI, group management, video calling via Agora.

##### File structure
- Top-level “backend” folder:
- index.js (Express app entry)
- controllers/logincontroller.js (login logic)
- middlewares/authenticate.js (JWT or token auth)
- model/*.js (Mongoose schemas for User, Post, Group, Message, GroupChat)
- routers/useroutes.js (user-facing endpoints)
- public/images (static assets)
- Top-level “frontend” folder:
- src/pages (route components like Login, Home, Chat, VideoCall)
- src/Components (ChatArea, mainArea subcomponents for chat UI and group popups)
- src/api/AuthApi.jsx (REST calls for auth)
- src/store/auth.jsx (client auth state)
- SCSS folder for global styling per page/feature
- Video-call integration via agora-rtm-sdk

##### README
- Minimal (“A social media project”), but file names imply features: authentication, posts, group chats, and video calls.

##### Detail
- Where middleware plugs in (e.g., “authentication” before protected routes).
- Sequence if needed: user logs in → token returned → WebSocket handshake includes token → stream.
- Both synchronous (REST) and asynchronous (WebSocket, Agora events) flows.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Browser Layer
    subgraph "Client (Browser)" 
        direction TB
        React["React SPA\n(main.jsx)"]:::frontend
        Vite["Vite Config\n(vite.config.js)"]:::frontend
        HTML["HTML Template\n(index.html)"]:::frontend
        CSS["Global Stylesheet\n(index.css)"]:::frontend
        AuthAPI["Auth API Layer\n(AuthApi.jsx)"]:::frontend
        Store["Auth State Store\n(auth.jsx)"]:::frontend
        Routes["Routing Definitions\n(index.jsx)"]:::frontend
        subgraph "Pages" 
            direction TB
            Login["Login Page\n(Login.jsx)"]:::frontend
            Register["Register Page\n(Register.jsx)"]:::frontend
            Home["Home/Dashboard\n(Home.jsx)"]:::frontend
            ChatPage["Chat Page\n(Chat.jsx)"]:::frontend
            VideoCall["Video Call Page\n(VideoCall.jsx)"]:::frontend
            Others["Other Pages\n(Contactus, Friends, Profile,\nLeaderboard, Group)"]:::frontend
        end
        SCSS["SCSS Styles\n(src/Scss)"]:::frontend
        DataConst["Data/Constants\n(data.js)"]:::frontend
        ImgAssets["Image Assets\n(src/image)"]:::frontend
        AgoraSDK["Agora RTM SDK\n(agora-rtm-sdk-1.5.1.js)"]:::frontend
    end

    %% Backend Layer
    subgraph "Server (Backend)" 
        direction TB
        Gateway["API Gateway\n(Load Balancer)"]:::backend
        ExpressApp["Express App\n(index.js)"]:::backend
        subgraph "Auth Service"
            direction TB
            AuthMid["Authenticate Middleware\n(authenticate.js)"]:::backend
            LoginCtrl["Login Controller\n(logincontroller.js)"]:::backend
        end
        subgraph "REST API"
            direction TB
            UserRoutes["User Routes\n(useroutes.js)"]:::backend
        end
        subgraph "Real-Time Chat Service"
            direction TB
            SocketSvc["Socket.IO Service"]:::backend
        end
        StaticAssets["Static Assets\n(public/images)"]:::backend
    end

    %% Data Store
    subgraph "Data Stores"
        direction TB
        Mongo["MongoDB Cluster"]:::datastore
        UserModel["User Model\n(userSchema.js)"]:::datastore
        PostModel["Post Model\n(postModel.js)"]:::datastore
        GroupModel["Group Model\n(group.js)"]:::datastore
        GroupChatModel["GroupChat Model\n(groupchat.js)"]:::datastore
        MessageModel["Message Model\n(message.js)"]:::datastore
    end

    %% External Services
    subgraph "External"
        direction TB
        AgoraCloud["Agora Cloud"]:::external
        CDN["CDN / Object Storage"]:::external
    end

    %% Connections
    React -->|"HTTP(S) REST" | Gateway
    Gateway -->|"/login, /users, /posts"| ExpressApp
    ExpressApp -->|uses| AuthMid
    AuthMid -->|calls| LoginCtrl
    ExpressApp -->|routes| UserRoutes
    ExpressApp -->|serves| StaticAssets
    ExpressApp -->|emit/receive WS| SocketSvc
    ExpressApp -->|CRUD| Mongo
    SocketSvc -->|persist msgs| Mongo
    React -->|"WebSocket" | SocketSvc
    React -->|"RTM/RTC"| AgoraSDK
    AgoraSDK -->|connect| AgoraCloud
    StaticAssets -->|delivered via| CDN

    %% Models to MongoDB
    UserModel --> Mongo
    PostModel --> Mongo
    GroupModel --> Mongo
    GroupChatModel --> Mongo
    MessageModel --> Mongo

    %% Click Events
    click ExpressApp "https://github.com/prateekkumar2204/social-media/blob/main/backend/index.js"
    click AuthMid "https://github.com/prateekkumar2204/social-media/blob/main/backend/middlewares/authenticate.js"
    click LoginCtrl "https://github.com/prateekkumar2204/social-media/blob/main/backend/controllers/logincontroller.js"
    click UserRoutes "https://github.com/prateekkumar2204/social-media/blob/main/backend/routers/useroutes.js"
    click UserModel "https://github.com/prateekkumar2204/social-media/blob/main/backend/model/userSchema.js"
    click PostModel "https://github.com/prateekkumar2204/social-media/blob/main/backend/model/postModel.js"
    click GroupModel "https://github.com/prateekkumar2204/social-media/blob/main/backend/model/group.js"
    click GroupChatModel "https://github.com/prateekkumar2204/social-media/blob/main/backend/model/groupchat.js"
    click MessageModel "https://github.com/prateekkumar2204/social-media/blob/main/backend/model/message.js"
    click StaticAssets "https://github.com/prateekkumar2204/social-media/tree/main/backend/public/images"
    click React "https://github.com/prateekkumar2204/social-media/blob/main/frontend/src/main.jsx"
    click Vite "https://github.com/prateekkumar2204/social-media/blob/main/frontend/vite.config.js"
    click HTML "https://github.com/prateekkumar2204/social-media/blob/main/frontend/index.html"
    click CSS "https://github.com/prateekkumar2204/social-media/blob/main/frontend/src/index.css"
    click AuthAPI "https://github.com/prateekkumar2204/social-media/blob/main/frontend/src/api/AuthApi.jsx"
    click Store "https://github.com/prateekkumar2204/social-media/blob/main/frontend/src/store/auth.jsx"
    click Routes "https://github.com/prateekkumar2204/social-media/blob/main/frontend/src/Routes/index.jsx"
    click Login "https://github.com/prateekkumar2204/social-media/blob/main/frontend/src/pages/Login.jsx"
    click Register "https://github.com/prateekkumar2204/social-media/blob/main/frontend/src/pages/Register.jsx"
    click Home "https://github.com/prateekkumar2204/social-media/blob/main/frontend/src/pages/Home.jsx"
    click ChatPage "https://github.com/prateekkumar2204/social-media/blob/main/frontend/src/pages/Chat.jsx"
    click VideoCall "https://github.com/prateekkumar2204/social-media/blob/main/frontend/src/pages/VideoCall.jsx"
    click AgoraSDK "https://github.com/prateekkumar2204/social-media/blob/main/frontend/src/pages/agora-rtm-sdk-1.5.1.js"
    click SCSS "https://github.com/prateekkumar2204/social-media/tree/main/frontend/src/Scss"
    click DataConst "https://github.com/prateekkumar2204/social-media/blob/main/frontend/src/data.js"
    click ImgAssets "https://github.com/prateekkumar2204/social-media/tree/main/frontend/src/image"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#3399ff,color:#000
    classDef backend fill:#d4edda,stroke:#28a745,color:#000
    classDef datastore fill:#fff3cd,stroke:#ffc107,color:#000
    classDef external fill:#e2d6f7,stroke:#6f42c1,color:#000
```
