# ankitsinghsisodya/bit-mitra architecture

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

- Interactive diagram: https://gitdiagram.com/ankitsinghsisodya/bit-mitra
- Repository: https://github.com/ankitsinghsisodya/bit-mitra

## Overview

##### Project type and purpose
- This is a full-stack social media web application (BIT-MITRA) with two main parts:
- Frontend: React + Redux SPA for users to view feeds, profiles, send messages
- Backend: Node.js/Express REST API + Socket.io for real-time chat
- Purpose: allow user registration/login, profile management, CRUD on posts/comments/likes, direct messaging, real-time notifications.

##### File structure
- Top-level directories:
- backend/
– controllers/ (message, post, user) – route handlers
– routes/ (message.route.js, post.route.js, user.route.js)
– models/ (user, post, comment, conversation, message) – Mongoose schemas
– middlewares/ (isAuthenticated, multer)
– socket/ (socket.js) – real-time logic
– utils/ (db connection, Cloudinary, data URI)
– index.js – Express app entry point
- frontend/
– src/components – page and UI components
– src/redux – slices and store
– src/hooks – custom data-fetch hooks
– public/index.html, vite.config.js, tailwind.config.js
- Config files: package.json, .gitignore in both dirs, ESLint, PostCSS.

##### Extract insights from the README
- REST API endpoints for users, posts, comments, likes
- JWT authentication via middleware
- Real-time features built with Socket.io
- Media storage via Cloudinary
- Data persisted in MongoDB

##### Main components
a. Frontend client
– React SPA (pages: Feed, Profile, Chat, etc.)
– Redux store for global state (authSlice, postSlice, chatSlice, socketSlice, etc.)
– HTTP client (Axios/fetch) for REST API
– WebSocket client (Socket.io-client) for real-time events
b. Backend server
– Express.js API layer
- Controllers: UserController, PostController, MessageController
- Routes: /api/users, /api/posts, /api/messages
- Middlewares: Authentication (JWT), File Upload (multer)
– Socket.io server for real-time chat/notifications
– Utility modules: DB connection, Cloudinary integration
c. Database
– MongoDB Atlas (collections: users, posts, comments, conversations, messages)
d. External services
– Cloudinary for image/video uploads
– (Optional) CDN for serving static assets
e. Authentication & Security
– JWT tokens passed in HTTP headers and on Socket.io handshake

##### Relationships and data flows
- Frontend → HTTP REST → Backend API → MongoDB
- Frontend ← HTTP REST ← Backend API ← MongoDB
- Frontend ↔ WebSocket ↔ Backend Socket.io server
- Backend → Cloudinary API for file uploads → returns URL → stored in MongoDB
- Client stores JWT locally → sends in Authorization header / Socket handshake

##### Architectural patterns & design principles
- Layered architecture (Presentation → API → Business logic → Data)
- MVC‐inspired structure on the backend (models, controllers, routes)
- Component and hook-based architecture on the frontend
- Redux for centralized state management
- Separation of concerns: REST vs. WebSocket sub-systems
- Use of middleware for cross-cutting concerns (auth, file handling)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend Client (React SPA)" 
        direction TB
        FE_SRC["frontend/src"]:::frontendDir
        FE_ENTRY["main.jsx"]:::frontendFile
        FE_APP["App.jsx"]:::frontendFile
        FE_STORE["Store (store.js)"]:::frontendFile
        FE_PAGES["Pages (Feed, Profile, Chat, etc.)"]:::frontend
        FE_HOOKS["Hooks (useGetRTM, etc.)"]:::frontend
        FE_WS["Socket.io-client"]:::frontend
        FE_HTTP["HTTP Client (Axios)"]:::frontend
        FE_SRC --> FE_ENTRY
        FE_ENTRY --> FE_APP
        FE_APP --> FE_STORE
        FE_APP --> FE_PAGES
        FE_APP --> FE_HOOKS
        FE_APP --> FE_HTTP
        FE_APP --> FE_WS
    end

    %% Backend Layer
    subgraph "Backend Server" 
        direction TB
        subgraph "Express API" 
            direction TB
            BE_ENTRY["index.js"]:::backendFile
            subgraph "Controllers"
                direction TB
                C_USER["UserController"]:::backendFile
                C_POST["PostController"]:::backendFile
                C_MSG["MessageController"]:::backendFile
            end
            subgraph "Routes"
                direction TB
                R_USER["user.route.js"]:::backendFile
                R_POST["post.route.js"]:::backendFile
                R_MSG["message.route.js"]:::backendFile
            end
            subgraph "Middlewares"
                direction TB
                M_AUTH["isAuthenticated.js"]:::backendFile
                M_UPLOAD["multer.js"]:::backendFile
            end
            subgraph "Utils"
                direction TB
                U_DB["db.js"]:::backendFile
                U_CLOUD["cloudinary.js"]:::backendFile
                U_DATA["dataUri.js"]:::backendFile
            end
            BE_ENTRY --> C_USER
            BE_ENTRY --> C_POST
            BE_ENTRY --> C_MSG
            BE_ENTRY --> R_USER
            BE_ENTRY --> R_POST
            BE_ENTRY --> R_MSG
            BE_ENTRY --> M_AUTH
            BE_ENTRY --> M_UPLOAD
            BE_ENTRY --> U_DB
            BE_ENTRY --> U_CLOUD
            BE_ENTRY --> U_DATA
        end
        subgraph "Socket.io Server"
            direction TB
            BE_SOCKET["socket.js"]:::backendFile
        end
        BE_ENTRY --> BE_SOCKET
    end

    %% Database and External
    subgraph "Data Store" 
        direction TB
        DB["MongoDB Atlas"]:::database
    end
    Cloudinary["Cloudinary"]:::external

    %% Relationships
    FE_HTTP -->|"REST GET/POST/PUT/DELETE\nAuth: JWT"| BE_ENTRY
    BE_ENTRY -->|"Mongoose ORM"| DB
    BE_ENTRY -->|"Image/Video upload"| Cloudinary
    FE_WS <-->|"Socket.io events\nAuth: JWT"| BE_SOCKET
    BE_SOCKET --> BE_ENTRY

    %% Class Definitions
    classDef frontendDir fill:#E8F0FE,stroke:#4285F4,color:#174EA6,stroke-width:1px;
    classDef frontendFile fill:#D2E3FC,stroke:#4285F4,color:#174EA6,stroke-width:1px;
    classDef frontend fill:#EBF1FF,stroke:#4285F4,color:#174EA6,stroke-width:1px;
    classDef backendFile fill:#E6F4EA,stroke:#34A853,color:#196F3D,stroke-width:1px;
    classDef database fill:#FCE8E6,stroke:#EA4335,color:#A42724,stroke-width:1px;
    classDef external fill:#F1F3F4,stroke:#5F6368,color:#202124,stroke-width:1px;

    %% Click Events
    click FE_SRC "https://github.com/ankitsinghsisodya/bit-mitra/tree/main/frontend/src"
    click FE_ENTRY "https://github.com/ankitsinghsisodya/bit-mitra/blob/main/frontend/src/main.jsx"
    click FE_APP "https://github.com/ankitsinghsisodya/bit-mitra/blob/main/frontend/src/App.jsx"
    click FE_STORE "https://github.com/ankitsinghsisodya/bit-mitra/blob/main/frontend/src/redux/store.js"
    click FE_PAGES "https://github.com/ankitsinghsisodya/bit-mitra/blob/main/frontend/src/components/ChatPage.jsx"
    click FE_HOOKS "https://github.com/ankitsinghsisodya/bit-mitra/blob/main/frontend/src/hooks/useGetRTM.jsx"
    click BE_ENTRY "https://github.com/ankitsinghsisodya/bit-mitra/blob/main/backend/index.js"
    click C_USER "https://github.com/ankitsinghsisodya/bit-mitra/blob/main/backend/controllers/user.controller.js"
    click C_POST "https://github.com/ankitsinghsisodya/bit-mitra/blob/main/backend/controllers/post.controller.js"
    click C_MSG "https://github.com/ankitsinghsisodya/bit-mitra/blob/main/backend/controllers/message.controller.js"
    click R_USER "https://github.com/ankitsinghsisodya/bit-mitra/blob/main/backend/routes/user.route.js"
    click R_POST "https://github.com/ankitsinghsisodya/bit-mitra/blob/main/backend/routes/post.route.js"
    click R_MSG "https://github.com/ankitsinghsisodya/bit-mitra/blob/main/backend/routes/message.route.js"
    click M_AUTH "https://github.com/ankitsinghsisodya/bit-mitra/blob/main/backend/middlewares/isAuthenticated.js"
    click M_UPLOAD "https://github.com/ankitsinghsisodya/bit-mitra/blob/main/backend/middlewares/multer.js"
    click U_DB "https://github.com/ankitsinghsisodya/bit-mitra/blob/main/backend/utils/db.js"
    click U_CLOUD "https://github.com/ankitsinghsisodya/bit-mitra/blob/main/backend/utils/cloudinary.js"
    click U_DATA "https://github.com/ankitsinghsisodya/bit-mitra/blob/main/backend/utils/dataUri.js"
    click BE_SOCKET "https://github.com/ankitsinghsisodya/bit-mitra/blob/main/backend/socket/socket.js"
    click DB "https://github.com/ankitsinghsisodya/bit-mitra/blob/main/backend/models/user.model.js"
```
