# sipsorcery-org/sipsorcery architecture

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

- Interactive diagram: https://gitdiagram.com/sipsorcery-org/sipsorcery
- Repository: https://github.com/sipsorcery-org/sipsorcery

## Overview

##### Main Components
- Core Library Modules:
– SIP Protocol stack, including SIP message construction, SIP channels (UDP, TCP, TLS, WebSocket), SIP transactions (invite/non-invite), and SIP events (dialog, presence, CDR, etc.)
– Media Handling and Codecs: Modules in “src/app/Media”, “src/net” (e.g., RTP, RTCP, video depacketisation, and DSP like G711/G722/G729 codecs), along with details for additional media sources and sinks.
- Networking & Transport Subsystems:
– Core networking layers in “src/net” such as ICE, STUN, DTLS/SRTP, RTP, RTCP, SCTP, RTSP, SDP, WebRTC signaling (WebSocket-based, as shown in the WebRTC examples)
– DNS integration and SIP endpoint management.
- Application-Level and SIP User Agents:
– Components in “src/app/SIPUserAgents” that implement SIP client and server behaviors, SIP call management and SIP request authentication.
- Examples and Demonstrations:
– A multitude of example projects (in the “examples” folder) demonstrate both VoIP and WebRTC scenarios using different media back ends (e.g., Windows audio capture, FFmpeg integration, Unity, etc.) and platforms.
- Test and Integration Suites:
– A comprehensive test suite in “test” shows integration and unit tests covering SIP, media, transport, and network protocol components.

##### Relationships and Interactions
- At the center is the SIPSorcery core library, which provides the backbone for SIP signaling (using SIP request/response handling and SIP transactions) and media stream management (via RTP/RTCP sessions).
- The SIP User Agent components build on the core stack to manage calls, authentication, and session control. They interact with the transport layer (using SIP Channels for UDP/TCP/TLS/WebSocket).
- The media side interfaces with codec implementations, media sources/sinks, and test-pattern generators. This includes interaction with external media libraries (e.g., SIPSorceryMedia.Encoders, SIPSorceryMedia.Windows) that encapsulate platform-specific audio/video capture and rendering.
- For WebRTC support, the library’s RTC components (in “src/net/WebRTC”) work in conjunction with external signaling components (e.g., simple JSON messages over WebSockets as shown in the WebRTC examples) and the video track/source components.
- Additional protocols like ICE, STUN, DTLS/SRTP provide connectivity and security, wiring external network interfaces to the real-time media streams.
- The examples (both VoIP and WebRTC) act as client applications that initialize these subsystems, while testing infrastructure verifies that each integration point behaves correctly.

##### Architectural Patterns and Design Principles
- Layered Architecture:
– At the lowest level, you have protocol implementations (RTCP, RTP, SCTP, STUN, ICE in “src/net”/“src/core”) which provide network communication and media transport.
– Above this, application-logic layers (SIP User Agents, SIP Request Authorisers) leverage these protocols.
- Separation of Concerns:
– The library is separated into discrete domains (protocol handling, media processing, application services) which makes it easier to swap in alternate implementations (for example, different media device back ends).
- Extensibility:
– The multiple example projects each demonstrate different integration scenarios, showing a design that favors plug‐in extensibility for media endpoints and signaling.

##### Technologies, Frameworks, and External Dependencies
- .NET (Framework and Core variants): The entire project is written in C# for .NET Framework 4.6.1 and later.
- External Media/Codec Libraries: Examples include integration with FFmpeg, SDL2, native VP8 via SIPSorceryMedia.Encoders, etc.
- GitHub Actions workflows and Dockerfiles indicate CI/CD and containerization aspects that can be noted as deployment/configuration artifacts.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% SIPSorcery Core Library
    subgraph "SIPSorcery Core Library"
        SIPCore["SIP Core Implementation"]:::core
        SIPTrans["SIP Transactions"]:::core
        SIPEvents["SIP Events"]:::core
        SIPCore -->|"uses"| SIPTrans
        SIPCore -->|"uses"| SIPEvents
    end

    %% Media Handling and Codecs
    subgraph "Media Handling and Codecs"
        MediaHandling["Media Sessions & Codecs"]:::media
    end

    %% Networking & Transport Subsystems
    subgraph "Networking & Transport Subsystems"
        ICE["ICE"]:::network
        STUN["STUN"]:::network
        DtlsSrtp["DTLS/SRTP"]:::network
        RTP["RTP"]:::network
        RTCP["RTCP"]:::network
        SCTP["SCTP"]:::network
        RTSP["RTSP"]:::network
        SDP["SDP"]:::network
        WebRTC["WebRTC Support"]:::network
    end

    %% SIP User Agents & Application-Level Components
    subgraph "SIP User Agents & Application Components"
        SIPUA["SIP User Agents"]:::app
        RequestAuth["SIP Request Authorization"]:::app
    end

    %% Examples and Demonstrations
    subgraph "Examples & Demonstrations"
        SIPExamples["SIP Examples (VoIP)"]:::app
        sipcmdline["SIP Cmdline"]:::app
        WebRTCExamples["WebRTC Examples"]:::app
        webrtccmdline["WebRTC Cmdline"]:::app
    end

    %% Test and Integration Suites
    subgraph "Test and Integration Suites"
        Tests["Test Suites"]:::network
    end

    %% Connections between major components
    SIPCore -->|"signals"| SIPUA
    SIPCore -->|"integrates"| MediaHandling
    MediaHandling -->|"relies_on"| RTP
    MediaHandling -->|"relies_on"| RTCP
    SIPUA -->|"triggers"| SIPTrans
    SIPUA -->|"validates"| RequestAuth

    %% Core Library using Networking components
    SIPCore -->|"communicates_via"| DtlsSrtp
    SIPCore -->|"communicates_via"| RTP
    SIPCore -->|"communicates_via"| RTCP
    SIPCore -->|"communicates_via"| ICE
    SIPCore -->|"communicates_via"| STUN
    SIPCore -->|"communicates_via"| SDP
    SIPCore -->|"communicates_via"| WebRTC

    %% WebRTC specific flow
    WebRTC -->|"signaling"| SIPUA

    %% Examples demonstrating usage
    SIPExamples -->|"demonstrates"| SIPUA
    sipcmdline -->|"demonstrates"| SIPUA
    WebRTCExamples -->|"demonstrates"| WebRTC
    webrtccmdline -->|"demonstrates"| WebRTC

    %% Test Suite validation flows
    Tests -->|"validates"| SIPCore
    Tests -->|"validates"| MediaHandling
    Tests -->|"validates"| SIPUA
    Tests -->|"validates"| ICE

    %% Styles
    classDef core fill:#ADD8E6,stroke:#0000FF,stroke-width:2px;
    classDef media fill:#FFA500,stroke:#FF8C00,stroke-width:2px;
    classDef network fill:#D3D3D3,stroke:#808080,stroke-width:2px;
    classDef app fill:#90EE90,stroke:#008000,stroke-width:2px;

    %% Click Events
    click SIPCore "https://github.com/sipsorcery-org/sipsorcery/tree/master/src/core/SIP"
    click SIPTrans "https://github.com/sipsorcery-org/sipsorcery/tree/master/src/core/SIPTransactions"
    click SIPEvents "https://github.com/sipsorcery-org/sipsorcery/tree/master/src/core/SIPEvents"
    click MediaHandling "https://github.com/sipsorcery-org/sipsorcery/tree/master/src/app/Media"
    click ICE "https://github.com/sipsorcery-org/sipsorcery/tree/master/src/net/ICE"
    click STUN "https://github.com/sipsorcery-org/sipsorcery/tree/master/src/net/STUN"
    click DtlsSrtp "https://github.com/sipsorcery-org/sipsorcery/tree/master/src/net/DtlsSrtp"
    click RTP "https://github.com/sipsorcery-org/sipsorcery/tree/master/src/net/RTP"
    click RTCP "https://github.com/sipsorcery-org/sipsorcery/tree/master/src/net/RTCP"
    click SCTP "https://github.com/sipsorcery-org/sipsorcery/tree/master/src/net/SCTP"
    click RTSP "https://github.com/sipsorcery-org/sipsorcery/tree/master/src/net/RTSP"
    click SDP "https://github.com/sipsorcery-org/sipsorcery/tree/master/src/net/SDP"
    click WebRTC "https://github.com/sipsorcery-org/sipsorcery/tree/master/src/net/WebRTC"
    click SIPUA "https://github.com/sipsorcery-org/sipsorcery/tree/master/src/app/SIPUserAgents"
    click RequestAuth "https://github.com/sipsorcery-org/sipsorcery/tree/master/src/app/SIPRequestAuthoriser"
    click SIPExamples "https://github.com/sipsorcery-org/sipsorcery/tree/master/examples/SIPExamples"
    click sipcmdline "https://github.com/sipsorcery-org/sipsorcery/tree/master/examples/sipcmdline"
    click WebRTCExamples "https://github.com/sipsorcery-org/sipsorcery/tree/master/examples/WebRTCExamples"
    click webrtccmdline "https://github.com/sipsorcery-org/sipsorcery/tree/master/examples/webrtccmdline"
    click Tests "https://github.com/sipsorcery-org/sipsorcery/tree/master/test"
```
