# miroslavpejic85/mirotalksfu architecture

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

- Interactive diagram: https://gitdiagram.com/miroslavpejic85/mirotalksfu
- Repository: https://github.com/miroslavpejic85/mirotalksfu

## Overview

##### Project Type and Purpose
- MiroTalk SFU is a full-stack, self-hosted, real-time video conferencing system built on Node.js and Mediasoup (Selective Forwarding Unit).
- It provides a PWA frontend, REST/Swagger API layer, WebSocket/WebRTC media routing, RTMP streaming support, and integrations (Slack, Discord, Mattermost, Sentry, Recall.ai, OpenAI).

##### File Structure Highlights
- **app/** – Core Node.js monolith:
- app/src/ – SFU logic (Server.js, Peer, Room, RtmpStreamer, etc.), middleware, config.
- app/api/ – REST endpoints (join, meeting, stats, token) implemented in JS/PHP/Python/Sh.
- app/ssl/ – SSL certs for HTTPS.
- **public/** – Static assets: HTML views, JS client code, CSS, images, sounds, SFU client libs (Mediasoup).
- **cloud/** – Supplemental Node.js server for “cloud” assets or functions.
- **rtmpServers/** – Standalone RTMP server demos & Docker recipes (nginx-rtmp, node-media-server).
- **webhook/** – Microservice to emit meeting events to external webhooks.
- **widgets/** – Embeddable support widgets for third-party sites.
- **docker-compose.template.yml**, **Dockerfile**, **webpack.config.js** – Containerization & build.
- **tests/** – Unit tests for core modules (Validator, XSS, ServerAPI).

1. **Clients (Browser/Mobile PWA)**
- Components: UI (public/views + public/js/C \
- Protocols: HTTPS for UI & REST, WebSocket for signaling, WebRTC for media
2. **Load Balancer / SSL Terminator**
- Optional: Nginx, HAProxy, or cloud LB
3. **Node.js Application Server**
- HTTP REST API (app/api)
- Static file server (public/)
- WebSocket signaling + Mediasoup worker management (app/src/Server.js)
- Business logic: Room, Peer, JWT Auth, Host Protection
4. **Mediasoup SFU Worker Processes**
- Media routing: publishes/subscribes video/audio between peers
5. **RTMP Streaming Subsystem**
- In-process: RtmpStreamer, RtmpFile (app/src)
- Optional external containers: nginx-rtmp, node-media-server (rtmpServers/)
6. **Webhook Service**
- Emits meeting events (join/leave/record) to external URLs (webhook/server.js)
7. **Cloud Functions / Asset Server**
- Optional: cloud/server.js for telco-level scaling or CDN integration
8. **External Services**
- Recall.ai (recording API)
- OpenAI / ChatGPT
- Slack / Discord / Mattermost integrations
- Sentry (error tracking)
- S3 (optional recording storage)
- Client → LB → Node.js: HTTPS GET/POST for UI & REST
- Client ↔ Node.js: WebSocket for signaling (SDP/ICE)
- Node.js ↔ Mediasoup Worker: media negotiation and pipe lines
- Node.js → RTMP Engines: push RTMP streams (OBS compatibility)
- Node.js → Webhook Service: HTTP callbacks on events
- Node.js → External Integrations: REST calls to Recall.ai, Slack, Discord, Sentry
- Node.js ↔ Optional Cloud Asset Server: asset upload/download and SSR endpoints
c. Architectural Patterns & Principles
- **Modular Monolith**: single codebase split into transport (app/src), API (app/api), UI (public)
- **Event-Driven**: signaling events trigger media routing & webhooks
- **Separation of Concerns**: static hosting vs. dynamic API vs. media routing
- **Containerization**: Docker + docker-compose for reproducible deployments
d. Key Technologies & Libraries
- Node.js v22+, Express (HTTP + WebSocket), Mediasoup SFU, FFmpeg (recording), nginx-rtmp/node-media-server, PWA client, JWT, OpenID Connect.

##### Detail Level
- Cross-cutting concerns: SSL termination, config (.env), Docker orchestration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients Layer
    subgraph "Clients (Browser/Mobile PWA)"
        direction TB
        Views[/"Views: Room, Landing, Login"/]:::ui
        Scripts[/"Client Scripts: RoomClient.js,\nLanding.js, Login.js"/]:::ui
        SFUClient["Mediasoup Client\n(MediasoupClient.js)"]:::ui
    end
    click Views "https://github.com/miroslavpejic85/mirotalksfu/tree/main/public/views/"
    click Scripts "https://github.com/miroslavpejic85/mirotalksfu/tree/main/public/js/"
    click SFUClient "https://github.com/miroslavpejic85/mirotalksfu/blob/main/public/sfu/MediasoupClient.js"

    %% Load Balancer / SSL
    LB["Load Balancer / SSL Terminator\n(Nginx/HAProxy)"]:::service
    SSLCert["SSL Certs\n(cert.pem, key.pem)"]:::storage
    click SSLCert "https://github.com/miroslavpejic85/mirotalksfu/tree/main/app/ssl/"

    %% Application Server
    subgraph "Node.js App Server" 
        direction TB
        Server["Server.js\n(Signaling & Mediasoup\nWorker Manager)"]:::service
        ServerAPI["ServerApi.js\n(REST & WebSocket)"]:::service
        subgraph "Business Logic"
            direction TB
            Room["Room.js"]:::service
            Peer["Peer.js"]:::service
            Validator["Validator.js"]:::service
            XSS["XSS.js"]:::service
            IPWL["IpWhitelist.js"]:::service
        end
        subgraph "Configuration"
            direction TB
            CFGTemplate["config.template.js"]:::service
            ENVTemplate[".env.template"]:::service
        end
        subgraph "RTMP In-Process"
            direction TB
            RtmpStreamer["RtmpStreamer.js"]:::service
            RtmpFile["RtmpFile.js"]:::service
            RtmpUrl["RtmpUrl.js"]:::service
        end
        subgraph "API Layer"
            direction TB
            Swagger["swagger.yaml"]:::service
            APIJoin["join/*.js"]:::service
            APIMeeting["meeting/*.js"]:::service
            APIMeetings["meetings/*.js"]:::service
            APIStats["stats/*.js"]:::service
            APIToken["token/*.js"]:::service
        end
    end
    click Server "https://github.com/miroslavpejic85/mirotalksfu/blob/main/app/src/Server.js"
    click ServerAPI "https://github.com/miroslavpejic85/mirotalksfu/blob/main/app/src/ServerApi.js"
    click Room "https://github.com/miroslavpejic85/mirotalksfu/blob/main/app/src/Room.js"
    click Peer "https://github.com/miroslavpejic85/mirotalksfu/blob/main/app/src/Peer.js"
    click Validator "https://github.com/miroslavpejic85/mirotalksfu/blob/main/app/src/Validator.js"
    click XSS "https://github.com/miroslavpejic85/mirotalksfu/blob/main/app/src/XSS.js"
    click IPWL "https://github.com/miroslavpejic85/mirotalksfu/blob/main/app/src/middleware/IpWhitelist.js"
    click CFGTemplate "https://github.com/miroslavpejic85/mirotalksfu/blob/main/app/src/config.template.js"
    click ENVTemplate "https://github.com/miroslavpejic85/mirotalksfu/blob/main/.env.template"
    click RtmpStreamer "https://github.com/miroslavpejic85/mirotalksfu/blob/main/app/src/RtmpStreamer.js"
    click RtmpFile "https://github.com/miroslavpejic85/mirotalksfu/blob/main/app/src/RtmpFile.js"
    click RtmpUrl "https://github.com/miroslavpejic85/mirotalksfu/blob/main/app/src/RtmpUrl.js"
    click Swagger "https://github.com/miroslavpejic85/mirotalksfu/blob/main/app/api/swagger.yaml"
    click APIJoin "https://github.com/miroslavpejic85/mirotalksfu/tree/main/app/api/join"
    click APIMeeting "https://github.com/miroslavpejic85/mirotalksfu/tree/main/app/api/meeting"
    click APIMeetings "https://github.com/miroslavpejic85/mirotalksfu/tree/main/app/api/meetings"
    click APIStats "https://github.com/miroslavpejic85/mirotalksfu/tree/main/app/api/stats"
    click APIToken "https://github.com/miroslavpejic85/mirotalksfu/tree/main/app/api/token"

    %% RTMP External
    subgraph "RTMP External Demos"
        direction TB
        NginxRTMP["nginx-rtmp/"]:::service
        NodeMedia["node-media-server/"]:::service
        DemoRTMP["demo/"]:::service
    end
    click NginxRTMP "https://github.com/miroslavpejic85/mirotalksfu/tree/main/rtmpServers/nginx-rtmp/"
    click NodeMedia "https://github.com/miroslavpejic85/mirotalksfu/tree/main/rtmpServers/node-media-server/"
    click DemoRTMP "https://github.com/miroslavpejic85/mirotalksfu/tree/main/rtmpServers/demo/"

    %% Webhook Service
    Webhook["Webhook Service\n(server.js)"]:::service
    click Webhook "https://github.com/miroslavpejic85/mirotalksfu/blob/main/webhook/server.js"

    %% Cloud Functions
    Cloud["Cloud Asset Server\n(server.js)"]:::service
    click Cloud "https://github.com/miroslavpejic85/mirotalksfu/blob/main/cloud/server.js"

    %% External Integrations
    subgraph "External Services"
        direction TB
        Recall["Recall.ai API"]:::external
        OpenAI["OpenAI / ChatGPT"]:::external
        Slack["Slack Integration"]:::external
        Discord["Discord Integration"]:::external
        Mattermost["Mattermost Integration"]:::external
        Sentry["Sentry Error Tracking"]:::external
        S3["S3 Storage"]:::storage
    end
    click Slack "https://github.com/miroslavpejic85/mirotalksfu/blob/main/app/src/Discord.js"
    click Discord "https://github.com/miroslavpejic85/mirotalksfu/blob/main/app/src/Discord.js"
    click Mattermost "https://github.com/miroslavpejic85/mirotalksfu/blob/main/app/src/Mattermost.js"
    click Sentry "https://github.com/miroslavpejic85/mirotalksfu/blob/main/app/src/Logger.js"

    %% Containerization & Build
    subgraph "Build & Deployment"
        direction TB
        Dockerfile["Dockerfile"]:::service
        Compose["docker-compose.yml"]:::service
        Webpack["webpack.config.js"]:::service
    end
    click Dockerfile "https://github.com/miroslavpejic85/mirotalksfu/tree/main/Dockerfile"
    click Compose "https://github.com/miroslavpejic85/mirotalksfu/blob/main/docker-compose.template.yml"
    click Webpack "https://github.com/miroslavpejic85/mirotalksfu/blob/main/webpack.config.js"

    %% Connections
    Views -->|HTTPS GET/POST| LB
    Scripts -->|HTTPS GET/POST| LB
    SFUClient -->|WSS Signaling| LB
    LB -->|HTTPS| ServerAPI
    LB -->|HTTPS| Server
    ServerAPI -->|"WebSocket"| Server
    Server -->|"spawn"| MedWorker[/"Mediasoup Workers"/]:::service
    Server -->|"invoke"| Room
    Server -->|"invoke"| Peer
    Server -->|"validate"| Validator
    Server -->|"sanitize"| XSS
    Server -->|"auth"| IPWL
    Server -->|"read/write"| Swagger
    Server -->|"REST calls"| Recall
    Server -->|"REST calls"| OpenAI
    Server -->|"POST events"| Slack
    Server -->|"POST events"| Discord
    Server -->|"POST events"| Mattermost
    Server -->|"error logs"| Sentry
    Server -->|"push RTMP"| RtmpStreamer
    Server -->|"write"| RtmpFile
    Server -->|"stream URL"| RtmpUrl
    Server -->|"HTTP callbacks"| Webhook
    Server -->|"assets"| Cloud
    Server -->|"upload/download"| S3
    Dockerfile -->|build| Server
    Compose -->|orchestrate| Dockerfile
    Webpack -->|bundle| Scripts

    %% Styles
    classDef service fill:#AED6F1,stroke:#2980B9,color:#1B4F72;
    classDef ui fill:#F9E79F,stroke:#B7950B,color:#7D6608;
    classDef storage fill:#ABEBC6,stroke:#27AE60,color:#145A32;
    classDef external fill:#D7BDE2,stroke:#8E44AD,color:#4A235A;
```
