# tri1210/eduroom architecture

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

- Interactive diagram: https://gitdiagram.com/tri1210/eduroom
- Repository: https://github.com/tri1210/eduroom

## Overview

##### Project type and purpose
- EduRoom is a full-stack, web-based video conferencing and chat application.
- Frontend: React SPA (client/)
- Backend: Node.js + Express REST + Socket.io signaling (server/)
- Real-time video/audio: WebRTC via simple-peer
- Features: authentication, room management, multi-user video & text chat, screen sharing, AI chatbot

##### High-level architectural components
a. Client (Browser)
- React UI: pages (Home, Login, Register, Room…), reusable components (Navbar, Chat, VideoCard, BottomBar)
- State & context: AuthContext, API wrappers (api.js)
- WebSocket client: socket.js connecting to server for real-time signaling & chat
- WebRTC peers: simple-peer instances for media stream negotiation
- HTTP REST calls: user auth, profile update, news, room list
b. Server
- Express app (index.js)
- Middleware: auth.middleware.js for JWT validation
- REST routes: user, room, message, news, chatbot
- Socket.io server: attached to Express for signaling events (join-room, signal exchange, chat messages)
- Data models: User, Room, Message, PrivateMessage, News (likely MongoDB via Mongoose)
- AI Chatbot integration: chatbot.routes.js calls external AI service (e.g., OpenAI)
- Database: external (MongoDB) – not shown in code, but implied by models
c. External services
- Database server (MongoDB)
- AI Chatbot API (OpenAI or similar)

##### Relationships and data flows
1. User opens browser → React app served (public/index.html)
2. React → HTTP POST /api/auth (sign-in/up) → JWT issued
3. Authenticated React → HTTP GET /api/rooms, /api/news → server queries DB → returns JSON
4. User “Join Room”: React emits Socket.io “join-room” with JWT → server authorizes via auth.middleware → adds to Socket.io room
5. WebRTC signaling:
- Peer A emits “signal” → server broadcasts to other peers in room → Peer B receives → simple-peer handshake → direct P2P media streams
6. Text chat: React emits “chat-message” via Socket.io → server saves via Message.model → broadcasts to room
7. AI Chatbot: React posts to /api/chatbot → server routes to chatbot.routes → invokes external AI service → returns bot response

##### Architectural patterns and design principles
- Separation of concerns: frontend vs. backend vs. database vs. external services
- Component-based UI (React)
- MVC-like structure on server (routes → controllers embedded in routes → models)
- Event-driven, real-time layer via WebSocket (Socket.io)
- Peer-to-peer media streaming via WebRTC
- JWT-based stateless authentication

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (React SPA)"
        direction TB
        SPA["React SPA"]:::frontend
        App["App.jsx"]:::frontend
        PublicHTML["index.html"]:::frontend
        PublicCSS["index.css"]:::frontend
        API["api.js<br/>utils/api.js"]:::frontend
        AuthCtx["AuthContext.jsx"]:::frontend
        SocketClient["socket.js"]:::frontend
        SW["serviceWorker.js"]:::frontend

        subgraph "Pages"
            direction TB
            Home["Home.jsx"]:::frontend
            Login["Login.jsx"]:::frontend
            Register["Register.jsx"]:::frontend
            RoomPage["Room.jsx"]:::frontend
            PrivateChat["PrivateChat.jsx"]:::frontend
            UpdateProfile["UpdateProfile.jsx"]:::frontend
            ProtectedRoute["ProtectedRoute.jsx"]:::frontend
        end

        subgraph "UI Components"
            direction TB
            Navbar["Navbar.js"]:::frontend
            BottomBar["BottomBar.js"]:::frontend
            ChatWidget["Chat.js"]:::frontend
            ChatBotWidget["ChatBotWidget.jsx"]:::frontend
            VideoCard["VideoCard.js"]:::frontend
        end
    end

    %% Backend Layer
    subgraph "Backend (Express + Socket.io)"
        direction TB
        Server["index.js"]:::backend
        AuthMW["auth.middleware.js"]:::backend

        subgraph "REST API Routes"
            direction TB
            UserRoutes["user.routes.js"]:::backend
            RoomRoutes["room.routes.js"]:::backend
            MessageRoutes["message.routes.js"]:::backend
            NewsRoutes["news.routes.js"]:::backend
            ChatbotRoutes["chatbot.routes.js"]:::backend
        end

        SocketIO["Socket.io Handlers"]:::backend

        subgraph "Data Models"
            direction TB
            UserModel["user.model.js"]:::backend
            RoomModel["room.model.js"]:::backend
            MessageModel["Message.model.js"]:::backend
            PrivateMessageModel["PrivateMessage.model.js"]:::backend
            NewsModel["news.model.js"]:::backend
        end
    end

    %% Infrastructure Layer
    subgraph "Infrastructure"
        direction TB
        DB["MongoDB"]:::infra
        AI["External AI Chatbot API"]:::infra
    end

    %% Relationships
    SPA -->|HTTP/HTTPS POST /api/auth| Server
    SPA -->|HTTP GET /api/rooms, /api/news| Server
    Server -->|Queries & Persists| DB
    Server -->|Invokes REST| AI

    SPA <-->|WS/WSS signaling & chat| SocketIO
    SocketIO -->|Uses Middleware| AuthMW
    SPA <-->|WebRTC Peer Streams| SPA

    %% Click Events
    click SPA "https://github.com/tri1210/eduroom/tree/main/client/"
    click App "https://github.com/tri1210/eduroom/blob/main/client/src/App.jsx"
    click PublicHTML "https://github.com/tri1210/eduroom/blob/main/client/public/index.html"
    click PublicCSS "https://github.com/tri1210/eduroom/blob/main/client/public/index.css"
    click API "https://github.com/tri1210/eduroom/blob/main/client/src/api.js"
    click API "https://github.com/tri1210/eduroom/blob/main/client/src/utils/api.js"
    click AuthCtx "https://github.com/tri1210/eduroom/blob/main/client/src/utils/AuthContext.jsx"
    click SocketClient "https://github.com/tri1210/eduroom/blob/main/client/src/socket.js"
    click Home "https://github.com/tri1210/eduroom/blob/main/client/src/pages/Home.jsx"
    click Login "https://github.com/tri1210/eduroom/blob/main/client/src/pages/Login.jsx"
    click Register "https://github.com/tri1210/eduroom/blob/main/client/src/pages/Register.jsx"
    click RoomPage "https://github.com/tri1210/eduroom/blob/main/client/src/pages/Room.jsx"
    click PrivateChat "https://github.com/tri1210/eduroom/blob/main/client/src/pages/PrivateChat.jsx"
    click UpdateProfile "https://github.com/tri1210/eduroom/blob/main/client/src/pages/UpdateProfile.jsx"
    click ProtectedRoute "https://github.com/tri1210/eduroom/blob/main/client/src/pages/ProtectedRoute.jsx"
    click Navbar "https://github.com/tri1210/eduroom/blob/main/client/src/components/Navbar.js"
    click BottomBar "https://github.com/tri1210/eduroom/blob/main/client/src/components/BottomBar/BottomBar.js"
    click ChatWidget "https://github.com/tri1210/eduroom/blob/main/client/src/components/Chat/Chat.js"
    click ChatBotWidget "https://github.com/tri1210/eduroom/blob/main/client/src/components/ChatBotWidget.jsx"
    click VideoCard "https://github.com/tri1210/eduroom/blob/main/client/src/components/Video/VideoCard.js"
    click SW "https://github.com/tri1210/eduroom/blob/main/client/src/serviceWorker.js"
    click Server "https://github.com/tri1210/eduroom/blob/main/server/index.js"
    click AuthMW "https://github.com/tri1210/eduroom/blob/main/server/middleware/auth.middleware.js"
    click UserRoutes "https://github.com/tri1210/eduroom/blob/main/server/routes/user.routes.js"
    click RoomRoutes "https://github.com/tri1210/eduroom/blob/main/server/routes/room.routes.js"
    click MessageRoutes "https://github.com/tri1210/eduroom/blob/main/server/routes/message.routes.js"
    click NewsRoutes "https://github.com/tri1210/eduroom/blob/main/server/routes/news.routes.js"
    click ChatbotRoutes "https://github.com/tri1210/eduroom/blob/main/server/routes/chatbot.routes.js"
    click UserModel "https://github.com/tri1210/eduroom/blob/main/server/models/user.model.js"
    click RoomModel "https://github.com/tri1210/eduroom/blob/main/server/models/room.model.js"
    click MessageModel "https://github.com/tri1210/eduroom/blob/main/server/models/Message.model.js"
    click PrivateMessageModel "https://github.com/tri1210/eduroom/blob/main/server/models/PrivateMessage.model.js"
    click NewsModel "https://github.com/tri1210/eduroom/blob/main/server/models/news.model.js"
    click DB "https://github.com/tri1210/eduroom/blob/main/server/package.json"
    click AI "https://github.com/tri1210/eduroom/blob/main/server/package.json"

    %% Styling
    classDef frontend fill:#D4E6F1,stroke:#1B4F72,stroke-width:1px;
    classDef backend fill:#D5F5E3,stroke:#196F3D,stroke-width:1px;
    classDef infra fill:#FCF3CF,stroke:#B9770E,stroke-width:1px;
```
