# signalapp/signal-calling-service architecture

> Architecture diagram of the GitHub repository signalapp/signal-calling-service, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/signalapp/signal-calling-service
- Repository: https://github.com/signalapp/signal-calling-service

## Overview

##### Main Components
a. Frontend (Signaling Server):
- Located in the frontend directory.
- Responsible for directing client requests to the appropriate backend servers.
- Components include API handlers (see files like frontend/src/api.rs, frontend/src/internal_api.rs), authentication, load balancing (frontend/src/load_balancer.rs), and metrics exposure (frontend/src/metrics_server.rs).

b. Backend (Media Forwarding Server):
- Found in the backend directory.
- Handles media forwarding from one source to multiple receivers.
- Contains diverse modules: call management (backend/src/call.rs plus its submodules), protocol components for WebRTC (rtp, rtcp, sfu, ice, googcc, etc.), and even fuzz testing support (backend/fuzz) for robustness.
- Also includes modules for congestion control (googcc) and various transport protocols.

c. Shared/Common Libraries:
- The common directory holds reusable code such as bits manipulation, serialization, and timing functions that both frontend and backend might use.

d. Metrics Service:
- There’s a dedicated metrics module (in metrics/) which likely abstracts the data reporting, histograms, and integration (e.g., Datadog via metrics/src/datadog_statsd.rs). This interacts with either the frontend or backend to expose runtime statistics.

e. Docker and CI/CD/Build Support:
- Dockerfiles, docker-compose.yml, and GitHub workflow configurations indicate containerized deployment and continuous integration testing.
- The docker and .github directories should be included as supporting infrastructure components in the overall architecture (e.g., for deployment and automated testing).

##### Relationships and Interactions
- The Backend manages media flows between participants. Represent internal modules (like the media server, call lifecycle, congestion control) as subcomponents of the Backend.
- Deployment and container orchestration (via Docker and docker-compose) can be shown as an outer layer that houses both the Frontend and Backend services.

##### Architectural Patterns and Design Principles
- Separation of concerns: distinct modules for signaling (frontend) and media forwarding (backend).
- Modular design: multiple subdirectories indicate a clean modular breakdown (e.g., separate modules for call management, congestion control, and metrics).
- Use of fuzzing (backend/fuzz) points to an emphasis on robustness and security testing.
- Containerization: Dockerfiles and GitHub workflows show that the system is built with CI/CD and containerized deployment in mind.

##### Relevant Technologies and Frameworks
- Rust as the underlying programming language (Cargo.toml and Cargo.lock files).
- Docker for containerization.
- GitHub Actions for automated CI/CD pipelines.
- Integration with external libraries (WebRTC, Datadog for metrics, and possibly others for cryptography and network protocols).

## Diagram (Mermaid)

```mermaid
flowchart TD
    Clients["Client Devices"]:::external

    subgraph "Frontend (Signaling Server)"
        A_API["API Handlers"]:::frontend
        A_LB["Load Balancer"]:::frontend
        A_MS["Metrics Server"]:::frontend
    end

    subgraph "Backend (Media Forwarding Server)"
        B_Call["Call Management"]:::backend
        B_RTP["RTP Processing"]:::backend
        B_CC["Congestion Control"]:::backend
        B_ICE["ICE Module"]:::backend
        B_Sig["Signaling"]:::backend
        B_Fuzz["Fuzz Testing"]:::backend
    end

    Common["Common Libraries"]:::common
    M_Svc["Metrics Service"]:::metrics

    subgraph "Deployment & CI/CD"
        D_Docker["Docker"]:::deploy
        D_CICD["CI/CD & Build"]:::deploy
    end

    %% Data Flow Connections
    Clients -->|"initiates"| A_API
    A_API -->|"calls"| A_LB
    A_LB -->|"forwards"| B_Sig
    A_MS -->|"reports"| M_Svc

    B_Sig -->|"triggers"| B_Call
    B_Call -->|"manages"| B_RTP
    B_RTP -->|"processes"| B_CC
    B_ICE -->|"supports"| B_Sig
    B_Fuzz -->|"tests"| B_Call
    B_Call -->|"reports"| M_Svc

    A_API -->|"uses"| Common
    B_Sig -->|"uses"| Common

    D_Docker -->|"deploys"| A_API
    D_Docker -->|"deploys"| B_Sig
    D_CICD -->|"builds"| D_Docker

    %% Click Events
    click A_API "https://github.com/signalapp/signal-calling-service/blob/main/frontend/src/api.rs"
    click A_LB "https://github.com/signalapp/signal-calling-service/blob/main/frontend/src/load_balancer.rs"
    click A_MS "https://github.com/signalapp/signal-calling-service/blob/main/frontend/src/metrics_server.rs"
    click B_Call "https://github.com/signalapp/signal-calling-service/blob/main/backend/src/call.rs"
    click B_RTP "https://github.com/signalapp/signal-calling-service/blob/main/backend/src/rtp.rs"
    click B_CC "https://github.com/signalapp/signal-calling-service/blob/main/backend/src/googcc.rs"
    click B_ICE "https://github.com/signalapp/signal-calling-service/blob/main/backend/src/ice.rs"
    click B_Sig "https://github.com/signalapp/signal-calling-service/blob/main/backend/src/signaling_server.rs"
    click B_Fuzz "https://github.com/signalapp/signal-calling-service/tree/main/backend/fuzz/"
    click Common "https://github.com/signalapp/signal-calling-service/tree/main/common/"
    click M_Svc "https://github.com/signalapp/signal-calling-service/tree/main/metrics/"
    click D_Docker "https://github.com/signalapp/signal-calling-service/tree/main/docker/"
    click D_CICD "https://github.com/signalapp/signal-calling-service/tree/main/.github/"

    %% Styles
    classDef frontend fill:#ccf,stroke:#333,stroke-width:2px;
    classDef backend fill:#cfc,stroke:#333,stroke-width:2px;
    classDef common fill:#fcf,stroke:#333,stroke-width:2px;
    classDef metrics fill:#cff,stroke:#333,stroke-width:2px;
    classDef deploy fill:#ffc,stroke:#333,stroke-width:2px;
    classDef external fill:#f9f,stroke:#333,stroke-width:2px;
```
