# emiago/diago architecture

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

- Interactive diagram: https://gitdiagram.com/emiago/diago
- Repository: https://github.com/emiago/diago

## Overview

##### Main Architectural Components
- SIP Signaling Module:
- External dependency on the SIPgo library.
- How Diago initializes with a SIP User Agent (UA) object from the SIPgo library.
- Dialog/Call Control Module:
- Components like dialog_server_session, dialog_client_session, and dialog_session.
- These manage the call signaling, registration, progressing calls (as seen in the usage example with Progress() and Answer() methods), and bridge processing.
- Media Processing Module:
- Encompass the “media” directory, which contains RTP session handling, RTP packet management, and SDP parsing.
- Rtp_dtmf handling components, RTP sequencer, and RTP stats. Show how these interact with the dialog module.
- Audio Codec and Processing Module:
- “audio” directory with its implementations for codecs (G711, Opus, PCM, WAV readers/writers and tests).
- That these components are responsible for encoding/decoding audio streams used during calls.
- Additional Service Components:
- Playback mechanisms (playback.go and playback_control.* files) that handle playing back media in calls.
- Registration and DTMF modules (e.g., register_transaction.go, dtmf_reader_writer.go)
- Bridge functionality (bridge.go) that might be enabling call bridging or session interaction.
- Examples / Usage Layer:
- A node or section for the “examples” directory to illustrate how developers use Diago.
- How these examples integrate the above components to deliver complete VOIP flows.

##### Structure Relationships and Interactions
- Data Flow:
- Session Management:
- How dialog sessions (server and client) manage call states and then invoke media sessions.
- Integration with External Resources:
- That the Diago library also interacts with external media assets (for example, the WAV file in the echotest example).
- Support for logging and debugging (SIPDebug, RTPDebug, RTCPDebug flags) that help trace these interactions.

##### Important Architectural Patterns and Principles
- Layered Architecture:
- The separation between call signaling (SIP and dialog sessions) and media processing (RTP, audio codecs) is a key design principle.
- Modularity & Extensibility:
- The use of distinct packages for dialog, media, and audio shows modular design allowing each to evolve independently.
- Testing and Example Driven Development:

## Diagram (Mermaid)

```mermaid
graph TD
    %% External Dependency
    SIP["SIPgo (External)"]:::external

    %% Diago Core Engine
    subgraph "Diago Core Engine"
        CORE["diago.go"]:::core
        CORE_TEST["diago_test.go"]:::core
        CORE_TEST_UTIL["diago_test_utils.go"]:::core
    end

    %% Dialog/Call Control Module
    subgraph "Dialog/Call Control Module"
        DIALOG["dialog_session.go"]:::dialog
        DIALOG_CLIENT["dialog_client_session.go"]:::dialog
        DIALOG_SERVER["dialog_server_session.go"]:::dialog
        DIALOG_CACHE["dialog_cache.go"]:::dialog
        DIALOG_TEST["dialog_session_test.go"]:::dialog
        DIALOG_CLIENT_TEST["dialog_client_session_test.go"]:::dialog
        DIALOG_SERVER_TEST["dialog_server_session_test.go"]:::dialog
    end

    %% Media Processing Module
    subgraph "Media Processing Module"
        MEDIA_SESSION["media_session.go"]:::media
        MEDIA_STREAM["media_stream.go"]:::media
        subgraph "RTP Handling"
            RTP_DTMF["rtp_dtmf.go"]:::media
            RTP_READER["rtp_packet_reader.go"]:::media
            RTP_WRITER["rtp_packet_writer.go"]:::media
            RTP_PARSE["rtp_parse.go"]:::media
            RTP_SEQUENCER["rtp_sequencer.go"]:::media
            RTP_SESSION["rtp_session.go"]:::media
        end
        subgraph "SDP Processing"
            SDP["media/sdp/sdp.go"]:::media
            FORMATS["media/sdp/formats.go"]:::media
            SDP_TEST["media/sdp/sdp_test.go"]:::media
            SDP_UTILS["media/sdp/utils.go"]:::media
        end
        RTP_STATS["rtp_stats_reader_writer.go"]:::media
        RTP_UTILS["rtp_utils.go"]:::media
    end

    %% Audio Codec and Processing Module
    subgraph "Audio Codec and Processing Module"
        G711["audio/g711.go"]:::audio
        OPUS["audio/opus.go"]:::audio
        OPUS_C["audio/opus_c.go"]:::audio
        OPUS_C_TEST["audio/opus_c_test.go"]:::audio
        PCM_ENCODER["audio/pcm_encoder.go"]:::audio
        PCM_ENCODER_TEST["audio/pcm_encoder_test.go"]:::audio
        WAV["audio/wav.go"]:::audio
        WAV_READER["audio/wav_reader.go"]:::audio
        WAV_WRITER["audio/wav_writer.go"]:::audio
        WAV_WRITER_TEST["audio/wav_writer_test.go"]:::audio
    end

    %% Additional Service Components
    subgraph "Additional Services"
        PLAYBACK["playback.go"]:::service
        PLAYBACK_CONTROL["playback_control.go"]:::service
        PLAYBACK_URL["playback_url.go"]:::service
        PLAYBACK_TEST["playback_test.go"]:::service
        PLAYBACK_CONTROL_TEST["playback_control_test.go"]:::service
        PLAYBACK_URL_TEST["playback_url_test.go"]:::service
        REGISTRATION["register_transaction.go"]:::service
        DTMF["dtmf_reader_writer.go"]:::service
        BRIDGE["bridge.go"]:::service
        BRIDGE_TEST["bridge_test.go"]:::service
    end

    %% Examples / Usage Layer
    subgraph "Examples / Usage Layer"
        EX_BRIDGE["examples/bridge"]:::examples
        EX_DTMF["examples/dtmf"]:::examples
        EX_PLAYBACK["examples/playback"]:::examples
        EX_PLAYBACK_CONTROL["examples/playback_control"]:::examples
        EX_READMEDIA["examples/readmedia"]:::examples
        EX_REGISTER["examples/register"]:::examples
        EX_LOGGER["examples/logger.go"]:::examples
    end

    %% Relationships and Data Flow
    SIP -->|"initSIPUA"| CORE
    CORE -->|"initDialog"| DIALOG
    DIALOG -->|"triggerMedia"| MEDIA_SESSION
    MEDIA_SESSION -->|"audioProcessing"| G711
    DIALOG -->|"invokeBridge"| BRIDGE
    MEDIA_SESSION -->|"controlPlayback"| PLAYBACK
    CORE -->|"useAPI"| EX_LOGGER
    PLAYBACK -->|"demoPlayback"| EX_PLAYBACK

    %% Click Events - Diago Core Engine
    click CORE "https://github.com/emiago/diago/blob/main/diago.go"
    click CORE_TEST "https://github.com/emiago/diago/blob/main/diago_test.go"
    click CORE_TEST_UTIL "https://github.com/emiago/diago/blob/main/diago_test_utils.go"

    %% Click Events - Dialog/Call Control Module
    click DIALOG "https://github.com/emiago/diago/blob/main/dialog_session.go"
    click DIALOG_CLIENT "https://github.com/emiago/diago/blob/main/dialog_client_session.go"
    click DIALOG_SERVER "https://github.com/emiago/diago/blob/main/dialog_server_session.go"
    click DIALOG_CACHE "https://github.com/emiago/diago/blob/main/dialog_cache.go"
    click DIALOG_TEST "https://github.com/emiago/diago/blob/main/dialog_session_test.go"
    click DIALOG_CLIENT_TEST "https://github.com/emiago/diago/blob/main/dialog_client_session_test.go"
    click DIALOG_SERVER_TEST "https://github.com/emiago/diago/blob/main/dialog_server_session_test.go"

    %% Click Events - Media Processing Module
    click MEDIA_SESSION "https://github.com/emiago/diago/blob/main/media/media_session.go"
    click MEDIA_STREAM "https://github.com/emiago/diago/blob/main/media/media_stream.go"
    click RTP_DTMF "https://github.com/emiago/diago/blob/main/rtp_dtmf.go"
    click RTP_READER "https://github.com/emiago/diago/blob/main/rtp_packet_reader.go"
    click RTP_WRITER "https://github.com/emiago/diago/blob/main/rtp_packet_writer.go"
    click RTP_PARSE "https://github.com/emiago/diago/blob/main/rtp_parse.go"
    click RTP_SEQUENCER "https://github.com/emiago/diago/blob/main/rtp_sequencer.go"
    click RTP_SESSION "https://github.com/emiago/diago/blob/main/rtp_session.go"
    click SDP "https://github.com/emiago/diago/blob/main/media/sdp/sdp.go"
    click FORMATS "https://github.com/emiago/diago/blob/main/media/sdp/formats.go"
    click SDP_TEST "https://github.com/emiago/diago/blob/main/media/sdp/sdp_test.go"
    click SDP_UTILS "https://github.com/emiago/diago/blob/main/media/sdp/utils.go"
    click RTP_STATS "https://github.com/emiago/diago/blob/main/rtp_stats_reader_writer.go"
    click RTP_UTILS "https://github.com/emiago/diago/blob/main/rtp_utils.go"

    %% Click Events - Audio Codec and Processing Module
    click G711 "https://github.com/emiago/diago/blob/main/audio/g711.go"
    click OPUS "https://github.com/emiago/diago/blob/main/audio/opus.go"
    click OPUS_C "https://github.com/emiago/diago/blob/main/audio/opus_c.go"
    click OPUS_C_TEST "https://github.com/emiago/diago/blob/main/audio/opus_c_test.go"
    click PCM_ENCODER "https://github.com/emiago/diago/blob/main/audio/pcm_encoder.go"
    click PCM_ENCODER_TEST "https://github.com/emiago/diago/blob/main/audio/pcm_encoder_test.go"
    click WAV "https://github.com/emiago/diago/blob/main/audio/wav.go"
    click WAV_READER "https://github.com/emiago/diago/blob/main/audio/wav_reader.go"
    click WAV_WRITER "https://github.com/emiago/diago/blob/main/audio/wav_writer.go"
    click WAV_WRITER_TEST "https://github.com/emiago/diago/blob/main/audio/wav_writer_test.go"

    %% Click Events - Additional Services
    click PLAYBACK "https://github.com/emiago/diago/blob/main/playback.go"
    click PLAYBACK_CONTROL "https://github.com/emiago/diago/blob/main/playback_control.go"
    click PLAYBACK_URL "https://github.com/emiago/diago/blob/main/playback_url.go"
    click PLAYBACK_TEST "https://github.com/emiago/diago/blob/main/playback_test.go"
    click PLAYBACK_CONTROL_TEST "https://github.com/emiago/diago/blob/main/playback_control_test.go"
    click PLAYBACK_URL_TEST "https://github.com/emiago/diago/blob/main/playback_url_test.go"
    click REGISTRATION "https://github.com/emiago/diago/blob/main/register_transaction.go"
    click DTMF "https://github.com/emiago/diago/blob/main/dtmf_reader_writer.go"
    click BRIDGE "https://github.com/emiago/diago/blob/main/bridge.go"
    click BRIDGE_TEST "https://github.com/emiago/diago/blob/main/bridge_test.go"

    %% Click Events - Examples / Usage Layer
    click EX_BRIDGE "https://github.com/emiago/diago/tree/main/examples/bridge"
    click EX_DTMF "https://github.com/emiago/diago/tree/main/examples/dtmf"
    click EX_PLAYBACK "https://github.com/emiago/diago/tree/main/examples/playback"
    click EX_PLAYBACK_CONTROL "https://github.com/emiago/diago/tree/main/examples/playback_control"
    click EX_READMEDIA "https://github.com/emiago/diago/tree/main/examples/readmedia"
    click EX_REGISTER "https://github.com/emiago/diago/tree/main/examples/register"
    click EX_LOGGER "https://github.com/emiago/diago/blob/main/examples/logger.go"

    %% Styles
    classDef external fill:#f96,stroke:#333,stroke-width:2px;
    classDef core fill:#bbf,stroke:#333,stroke-width:2px;
    classDef dialog fill:#cfc,stroke:#333,stroke-width:2px;
    classDef media fill:#fcf,stroke:#333,stroke-width:2px;
    classDef audio fill:#cff,stroke:#333,stroke-width:2px;
    classDef service fill:#ffc,stroke:#333,stroke-width:2px;
    classDef examples fill:#ddd,stroke:#333,stroke-width:2px;
```
