# sippy/b2bua architecture

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

- Interactive diagram: https://gitdiagram.com/sippy/b2bua
- Repository: https://github.com/sippy/b2bua

## Overview

##### Main Components

a) Core SIP Components:
- SIP Transaction Manager (SipTransactionManager.py)
- User Agent components (UA.py, UaState* files)
- B2B Components (B2BRoute.py, B2BTransforms.py)
- State Machines (UacState*, UasState* files)

b) Network Layer:
- UDP Server (Udp_server.py)
- WebSocket Server (Wss_server.py)
- XMPP Server (XMPP_server.py)

c) Media Handling:
- RTPProxy Integration (Rtp_proxy/ directory)
- Session Management (Rtp_proxy/Session/)
- Client Implementations (Rtp_proxy/Client/)

d) Authentication & Security:
- RADIUS Integration (RadiusAccounting.py, RadiusAuthorisation.py)
- Security Components (Security/ directory)

**[Client Layer]**

**[Protocol Interfaces]**

**[Core Processing]**

**[Media Handling]**

**[External Services]**

##### Key Relationships

- Relationship between B2BUA core and RTPProxy integration
- Authentication flow with RADIUS components
- Demonstrate WebRTC to SIP gateway functionality

**┌─ Client Connections ─┐**
- SIP Clients       │
- WebRTC Clients    │
- ┬──────────┘
- ↓
**┌─ Protocol Handlers ─┐**
- UDP Server       │
- WSS Server       │
- XMPP Server      │
- ┬──────────┘
- ↓
**┌─ Core B2BUA Logic ─┐**
- Transaction Mgr  │
- State Machines   │
- B2B Routing      │
- ┬──────────┘
- ↓
**┌─ Media Handling ───┐**
- RTPProxy Client  │
- Session Control  │
- ┬──────────┘
- ↓
**┌─ External Services ┐**
- RADIUS          │
- Authentication  │
- ┬──────────┘

##### Implementation Notes

- Annotations for key performance metrics
- Scaling capabilities
- Error handling paths

##### Additional Details

- Version information
- Supported protocols (RFC3261, etc.)
- Performance metrics (150-400 call setups/tear-downs per second)
- Integration points with external systems

Remember to maintain a balance between detail and clarity, focusing on the architectural components that make this B2BUA unique, such as its media handling approach and WebRTC gateway capabilities.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef client fill:#e1f5fe,stroke:#01579b
    classDef protocol fill:#c8e6c9,stroke:#1b5e20
    classDef core fill:#bbdefb,stroke:#0d47a1
    classDef media fill:#fff3e0,stroke:#e65100
    classDef security fill:#ffcdd2,stroke:#b71c1c
    classDef state fill:#e1bee7,stroke:#4a148c
    classDef message fill:#f0f4c3,stroke:#827717
    classDef sdp fill:#ffe0b2,stroke:#ef6c00

    %% Client Layer
    subgraph Clients
        SIPClients["SIP Clients"]:::client
        WebRTCClients["WebRTC Clients"]:::client
    end

    %% Protocol Layer
    subgraph ProtocolHandlers
        UDPServer["UDP Server"]:::protocol
        WSSServer["WebSocket Server"]:::protocol
        XMPPServer["XMPP Server"]:::protocol
    end

    %% Core Layer
    subgraph CoreProcessing
        TransactionMgr["Transaction Manager"]:::core
        UACore["User Agent Core"]:::core
        B2BRoute["B2B Route"]:::core
        B2BTransforms["B2B Transforms"]:::core
        EventDispatcher["Event Dispatcher"]:::core
    end

    %% State Machines
    subgraph StateMachines
        UaConnected["UA Connected State"]:::state
        UaDead["UA Dead State"]:::state
        UacIdle["UAC Idle State"]:::state
        UasIdle["UAS Idle State"]:::state
        UasRinging["UAS Ringing State"]:::state
    end

    %% Message Processing
    subgraph MessageHandling
        SipMsg["SIP Message"]:::message
        SipRequest["SIP Request"]:::message
        SipResponse["SIP Response"]:::message
    end

    %% SDP Processing
    subgraph SDPHandling
        SdpBody["SDP Body"]:::sdp
        SdpMedia["SDP Media"]:::sdp
        SdpMediaDesc["SDP Media Description"]:::sdp
    end

    %% Media Layer
    subgraph MediaHandling
        RTPProxy["RTP Proxy Core"]:::media
        SessionMgmt["Session Management"]:::media
        ClientImpl["Client Implementations"]:::media
        WebRTCSupport["WebRTC Support"]:::media
    end

    %% Security Layer
    subgraph SecurityLayer
        RadiusAuth["RADIUS Authorization"]:::security
        RadiusAcct["RADIUS Accounting"]:::security
        RadiusClient["RADIUS Client"]:::security
        SecurityComp["Security Components"]:::security
    end

    %% Relationships
    Clients --> ProtocolHandlers
    ProtocolHandlers --> CoreProcessing
    CoreProcessing --> StateMachines
    CoreProcessing --> MessageHandling
    MessageHandling --> SDPHandling
    CoreProcessing --> MediaHandling
    CoreProcessing --> SecurityLayer

    %% Click Events
    click TransactionMgr "https://github.com/sippy/b2bua/blob/master/sippy/SipTransactionManager.py"
    click UACore "https://github.com/sippy/b2bua/blob/master/sippy/UA.py"
    click B2BRoute "https://github.com/sippy/b2bua/blob/master/sippy/B2BRoute.py"
    click B2BTransforms "https://github.com/sippy/b2bua/blob/master/sippy/B2BTransforms.py"
    click UaConnected "https://github.com/sippy/b2bua/blob/master/sippy/UaStateConnected.py"
    click UaDead "https://github.com/sippy/b2bua/blob/master/sippy/UaStateDead.py"
    click UacIdle "https://github.com/sippy/b2bua/blob/master/sippy/UacStateIdle.py"
    click UasIdle "https://github.com/sippy/b2bua/blob/master/sippy/UasStateIdle.py"
    click UasRinging "https://github.com/sippy/b2bua/blob/master/sippy/UasStateRinging.py"
    click UDPServer "https://github.com/sippy/b2bua/blob/master/sippy/Udp_server.py"
    click WSSServer "https://github.com/sippy/b2bua/blob/master/sippy/Wss_server.py"
    click XMPPServer "https://github.com/sippy/b2bua/blob/master/sippy/XMPP_server.py"
    click RTPProxy "https://github.com/sippy/b2bua/tree/master/sippy/Rtp_proxy/"
    click SessionMgmt "https://github.com/sippy/b2bua/tree/master/sippy/Rtp_proxy/Session/"
    click ClientImpl "https://github.com/sippy/b2bua/tree/master/sippy/Rtp_proxy/Client/"
    click WebRTCSupport "https://github.com/sippy/b2bua/blob/master/sippy/Rtp_proxy/Session/webrtc.py"
    click RadiusAuth "https://github.com/sippy/b2bua/blob/master/sippy/RadiusAuthorisation.py"
    click RadiusAcct "https://github.com/sippy/b2bua/blob/master/sippy/RadiusAccounting.py"
    click RadiusClient "https://github.com/sippy/b2bua/blob/master/sippy/Radius_client.py"
    click SecurityComp "https://github.com/sippy/b2bua/tree/master/sippy/Security/"
    click EventDispatcher "https://github.com/sippy/b2bua/blob/master/sippy/Core/EventDispatcher.py"
    click SipMsg "https://github.com/sippy/b2bua/blob/master/sippy/SipMsg.py"
    click SipRequest "https://github.com/sippy/b2bua/blob/master/sippy/SipRequest.py"
    click SipResponse "https://github.com/sippy/b2bua/blob/master/sippy/SipResponse.py"
    click SdpBody "https://github.com/sippy/b2bua/blob/master/sippy/SdpBody.py"
    click SdpMedia "https://github.com/sippy/b2bua/blob/master/sippy/SdpMedia.py"
    click SdpMediaDesc "https://github.com/sippy/b2bua/blob/master/sippy/SdpMediaDescription.py"
```
