# gayatriagarwal19/clover architecture

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

- Interactive diagram: https://gitdiagram.com/gayatriagarwal19/clover
- Repository: https://github.com/gayatriagarwal19/clover

## Overview

##### Project Type & Purpose
- Full-stack real-time messaging & conferencing web app.
- Frontend: React SPA (Vite) with Redux, socket.io, WebRTC client libs.
- Backend: Node.js/Express + socket.io + mediasoup SFU.
- Persistence: MongoDB (Mongoose).
- External services: SMTP (sendMail), STUN/TURN servers.

##### Main Components
a. Client (Browser)
– Static assets served via Vite dev server (dev) or CDN/Vercel (prod).
– React SPA modules: pages (Login, Home, ForgotPassword), features (Conversation, Meeting, Panel…).
– Redux store: actions, reducers, middleware (socket.io-promise).
– Media capture libs (getUserAudio/Video/Screen).
– socket.io client for real-time messaging/signaling.
b. API Layer (Backend Express)
– HTTP routes under /auth, /rooms, /messages, /users, /files, /rtc, /meeting.
– socket.io namespace for events (init, more-messages, typing, status).
– Mediasoup controller (in src/mediasoup) for WebRTC SFU orchestration.
c. Database
– MongoDB via Mongoose.
– Collections: User, Room, Message, Meeting, File, Image, Email, AuthCode.
d. External Services
– SMTP server (sendMail utility) for verification codes.
– STUN/TURN (configured in backend/config.js).
e. Launcher/Scripts
– scripts/launcher.js orchestrates startup (both frontend and backend in dev).
– launcher/* (optional bundling or Docker orchestration).

##### Relationships & Data Flows
– HTTP Request/Response:
- User actions (login/register, CRUD rooms/files) → Express REST endpoints → Mongoose → MongoDB → JSON response → React UI.
– WebSocket/socket.io:
- Chat messages, typing indicators, room events broadcast in real time.
– WebRTC Signaling (via HTTP+socket.io) → mediasoup SFU → Peer RTP streams.
– Media Streams:
- Clients send audio/video to SFU → SFU redistributes streams to participants.
– Email Service:
- Password reset/verification flows invoke sendMail utility → external SMTP.

##### Architectural Patterns & Design Principles
– Separation of Concerns:
- Frontend (presentation + client business logic) vs. Backend (API + real-time + media server).
– Modular Routing & Event Handlers:
- Each feature (auth, rtc, meeting, files) lives in its own express route file or socket handler.
– CQRS-style split:
- REST for CRUD, WebSocket for events.
– SFU (Selective Forwarding Unit) pattern via mediasoup for group calls.

a. Partition your canvas into three horizontal tiers (or vertical columns):
1. Client Tier (Browser)
2. Server Tier (Express + mediasoup)
3. Data & External Services Tier (MongoDB, SMTP, STUN/TURN)
– In Client Tier: “React SPA”, “Redux Store”, “socket.io client”, “getUserMedia libs”.
– In Server Tier: “Express HTTP Server”, “socket.io Server”, “Mediasoup Workers”.
– In Data Tier: “MongoDB Cluster”, “SMTP Service”, “STUN/TURN Servers”.
– HTTP calls → Express → MongoDB → HTTP response.
– WebSocket ↔ socket.io ↔ Express events.
– Signaling over socket.io/HTTP → Mediasoup → RTP streams ↔ Clients.
– sendMail utility → SMTP.
d. Major endpoints:
– /api/auth/**, /api/rooms/**, /api/meeting/**, /rtc/create, /rtc/join, etc.

##### Final Checklist
[ ] Clear, descriptive labels for components & modules
[ ] Grouped containers for major subsystems
[ ] Annotations of key technologies (React, Redux, Express, socket.io, mediasoup, MongoDB)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Tier
    subgraph "Client Tier"
        direction TB
        ReactSPA["React SPA"]:::client
        ReduxStore["Redux Store"]:::client
        SocketClient["socket.io Client"]:::client
        MediaLibs["Media Capture Libs"]:::client
        FeatureModules["Feature & Page Modules"]:::client
    end

    %% Server Tier
    subgraph "Server Tier"
        direction TB
        ExpressServer["Express HTTP Server"]:::server
        APIRoutes["REST API Routes"]:::server
        SocketHandlers["Socket.io Event Handlers"]:::server
        MediasoupController["Mediasoup SFU Controller"]:::server
        STUNTURNConfig["STUN/TURN Config"]:::server
        EmailUtil["Email Service Utility"]:::server
        ResetScript["Backend Reset Script"]:::server
    end

    %% Data & External Services Tier
    subgraph "Data & External Services Tier"
        direction TB
        MongoInit["Mongoose Init"]:::data
        DBModels["Database Models"]:::data
        MongoDB["MongoDB Cluster"]:::data
        SMTP["SMTP Service"]:::external
        STUNTURN["STUN/TURN Servers"]:::external
    end

    %% Launcher Script
    Launcher["Launcher Script"]:::server

    %% Relationships
    ReactSPA -->|HTTP/JSON| ExpressServer
    ReactSPA -->|WS/event| SocketHandlers
    ReduxStore -->|dispatch| ReactSPA
    SocketClient -->|signal/events| SocketHandlers
    MediaLibs -->|capture| ReactSPA
    FeatureModules -->|UI modules| ReactSPA

    ExpressServer -->|uses| APIRoutes
    ExpressServer -->|uses| SocketHandlers
    ExpressServer -->|uses| MediasoupController
    ExpressServer -->|reads| STUNTURNConfig
    ExpressServer -->|calls| EmailUtil
    SocketHandlers -->|signal| MediasoupController

    APIRoutes -->|CRUD| MongoInit
    APIRoutes -->|CRUD| DBModels
    MongoInit -->|connect| MongoDB
    DBModels -->|schema| MongoDB

    EmailUtil -->|SMTP| SMTP
    STUNTURNConfig -->|configures| STUNTURN

    MediasoupController -->|connect| STUNTURN
    MediasoupController -->|stream RTP| ReactSPA

    Launcher -->|starts| ReactSPA
    Launcher -->|starts| ExpressServer

    %% Click Events - Client Tier
    click ReactSPA "https://github.com/gayatriagarwal19/clover/tree/main/frontend/src"
    click ReduxStore "https://github.com/gayatriagarwal19/clover/blob/main/frontend/src/store.js"
    click ReduxStore "https://github.com/gayatriagarwal19/clover/tree/main/frontend/src/reducers"
    click SocketClient "https://github.com/gayatriagarwal19/clover/blob/main/frontend/src/lib/socket.io-promise.js"
    click SocketClient "https://github.com/gayatriagarwal19/clover/blob/main/frontend/src/actions/initIO.js"
    click MediaLibs "https://github.com/gayatriagarwal19/clover/blob/main/frontend/src/lib/getUserAudio.js"
    click MediaLibs "https://github.com/gayatriagarwal19/clover/blob/main/frontend/src/lib/getUserVideo.js"
    click MediaLibs "https://github.com/gayatriagarwal19/clover/blob/main/frontend/src/lib/getUserScreen.js"
    click MediaLibs "https://github.com/gayatriagarwal19/clover/blob/main/frontend/src/lib/getUserMedia.js"
    click FeatureModules "https://github.com/gayatriagarwal19/clover/tree/main/frontend/src/features"
    click FeatureModules "https://github.com/gayatriagarwal19/clover/tree/main/frontend/src/pages"

    %% Click Events - Server Tier
    click ExpressServer "https://github.com/gayatriagarwal19/clover/blob/main/backend/index.js"
    click ExpressServer "https://github.com/gayatriagarwal19/clover/blob/main/backend/src/init.js"
    click APIRoutes "https://github.com/gayatriagarwal19/clover/tree/main/backend/src/routes"
    click SocketHandlers "https://github.com/gayatriagarwal19/clover/tree/main/backend/src/events"
    click MediasoupController "https://github.com/gayatriagarwal19/clover/blob/main/backend/src/mediasoup/index.js"
    click STUNTURNConfig "https://github.com/gayatriagarwal19/clover/blob/main/backend/config.js"
    click EmailUtil "https://github.com/gayatriagarwal19/clover/blob/main/backend/src/utils/sendMail.js"
    click ResetScript "https://github.com/gayatriagarwal19/clover/blob/main/backend/reset.js"

    %% Click Events - Data Tier
    click MongoInit "https://github.com/gayatriagarwal19/clover/blob/main/backend/src/models/mongoose.js"
    click DBModels "https://github.com/gayatriagarwal19/clover/blob/main/backend/src/models/User.js"
    click DBModels "https://github.com/gayatriagarwal19/clover/blob/main/backend/src/models/Room.js"
    click DBModels "https://github.com/gayatriagarwal19/clover/blob/main/backend/src/models/Message.js"
    click DBModels "https://github.com/gayatriagarwal19/clover/blob/main/backend/src/models/Meeting.js"
    click DBModels "https://github.com/gayatriagarwal19/clover/blob/main/backend/src/models/File.js"
    click DBModels "https://github.com/gayatriagarwal19/clover/blob/main/backend/src/models/Image.js"
    click DBModels "https://github.com/gayatriagarwal19/clover/blob/main/backend/src/models/Email.js"
    click DBModels "https://github.com/gayatriagarwal19/clover/blob/main/backend/src/models/AuthCode.js"

    %% Click Events - Launcher
    click Launcher "https://github.com/gayatriagarwal19/clover/blob/main/scripts/launcher.js"

    %% Styles
    classDef client fill:#D0E8FF,stroke:#348FEB,color:#000
    classDef server fill:#D0FFD0,stroke:#33AA33,color:#000
    classDef data fill:#FFE0B2,stroke:#FF9900,color:#000
    classDef external fill:#FFDAB9,stroke:#FF7700,color:#000
```
