# oliverepper/libphone architecture

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

- Interactive diagram: https://gitdiagram.com/oliverepper/libphone
- Repository: https://github.com/oliverepper/libphone

## Overview

##### Main Components

a. Core Library Components:
- libphone Core (C++ implementation)
- C API Wrapper
- Language Bindings (Python, Java, C++)
- PJSIP Integration Layer
- Audio Device Management
- SIP Communication Layer

b. External Dependencies:
- PJSIP Project
- Opus Codec
- SSL/Crypto Libraries
- Platform-specific Audio APIs

##### Architectural Layers (from top to bottom)

a. Client Applications Layer:
- Different CLI implementations (Python, Java, C, C++)
- TestApp (Darwin/iOS)

b. API Layer:
- C API Interface
- C++ API Interface
- Language Bindings

c. Core Implementation Layer:
- Phone Instance Management
- Call Management
- Account Management
- Audio Device Handling
- Callback System
- Configuration Management

d. Integration Layer:
- PJSIP Integration
- Platform-specific Audio Implementations
- Network Management

##### Key Relationships to Highlight

a. Client Applications → API Layer:
- How different language implementations connect through the C API
- Demonstrate the relationship between C++ applications and the native C++ API

b. API Layer → Core Implementation:
- Bridge between C API and C++ implementation
- Callback registration system

c. Core Implementation → Integration Layer:
- PJSIP integration points
- Audio device management flow
- Network handling (IP changes, SRV lookups)

##### Special Features

- Call handling system with dual referencing (index and ID)
- Audio device selection and management
- DTMF handling
- IP address change handling
- SIP registration and connection flow
- Callback system architecture

##### Implementation Details

Classes/structures:
- phone_instance_t
- call_t
- account_t
- IfAddrs
- log_writer_t
- tone_generator_helper

- Version information
- Platform support indicators

This system design should emphasize the library's role as a high-level wrapper around PJSIP while showing its extensive cross-platform support and multiple language bindings.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and classes
    classDef core fill:#b3d1ff,stroke:#333
    classDef api fill:#90EE90,stroke:#333
    classDef platform fill:#FFB366,stroke:#333
    classDef external fill:#E6E6E6,stroke:#333
    classDef client fill:#DDA0DD,stroke:#333
    classDef audio fill:#FFD700,stroke:#333

    %% Client Applications Layer
    subgraph ClientApps
        PythonCLI["Python CLI"]:::client
        JavaCLI["Java CLI"]:::client
        CCLI["C CLI"]:::client
        CppCLI["C++ CLI"]:::client
        TestApp["TestApp (Darwin/iOS)"]:::client
    end

    %% API Layer
    subgraph APILayer
        CAPI["C API Interface"]:::api
        CppAPI["C++ API Interface"]:::api
        LangBindings["Language Bindings"]:::api
    end

    %% Core Implementation Layer
    subgraph CoreLayer
        PhoneCore["Phone Core"]:::core
        CallMgmt["Call Management"]:::core
        AcctMgmt["Account Management"]:::core
        AudioMgmt["Audio Device Handling"]:::core
        CallbackSys["Callback System"]:::core
        ConfigMgmt["Configuration Management"]:::core
    end

    %% Integration Layer
    subgraph IntegrationLayer
        PJSIPInt["PJSIP Integration"]:::core
        PlatformAudio["Platform Audio"]:::platform
        NetworkMgmt["Network Management"]:::core
    end

    %% External Dependencies
    subgraph ExternalDeps
        PJSIP["PJSIP Project"]:::external
        OpusCodec["Opus Codec"]:::external
        SSLLibs["SSL/Crypto Libraries"]:::external
        PlatformAPIs["Platform Audio APIs"]:::external
    end

    %% Relationships
    PythonCLI --> CAPI
    JavaCLI --> CAPI
    CCLI --> CAPI
    CppCLI --> CppAPI
    TestApp --> CppAPI

    CAPI --> PhoneCore
    CppAPI --> PhoneCore
    LangBindings --> CAPI

    PhoneCore --> CallMgmt
    PhoneCore --> AcctMgmt
    PhoneCore --> AudioMgmt
    PhoneCore --> CallbackSys
    PhoneCore --> ConfigMgmt

    CallMgmt --> PJSIPInt
    AcctMgmt --> PJSIPInt
    AudioMgmt --> PlatformAudio
    NetworkMgmt --> PJSIPInt

    PJSIPInt --> PJSIP
    PlatformAudio --> PlatformAPIs
    PJSIP --> OpusCodec
    PJSIP --> SSLLibs

    %% Click events for component mapping
    click PhoneCore "https://github.com/oliverepper/libphone/blob/main/src/phone/phone.cpp"
    click CallMgmt "https://github.com/oliverepper/libphone/blob/main/src/phone/include/private/call_t.h"
    click AcctMgmt "https://github.com/oliverepper/libphone/blob/main/src/phone/include/private/account_t.h"
    click NetworkMgmt "https://github.com/oliverepper/libphone/blob/main/src/phone/include/private/IfAddrs.h"
    click PythonCLI "https://github.com/oliverepper/libphone/blob/main/src/python_cli/python_cli.py"
    click JavaCLI "https://github.com/oliverepper/libphone/blob/main/src/java_cli/Cli/src/main/java/de/oliver_epper/libphone/Main.java"
    click CCLI "https://github.com/oliverepper/libphone/blob/main/src/c_cli/main.c"
    click CppCLI "https://github.com/oliverepper/libphone/blob/main/src/cpp_cli/main.cpp"
    click TestApp "https://github.com/oliverepper/libphone/tree/main/darwin/TestApp/TestApp"
    click PJSIP "https://github.com/oliverepper/libphone/tree/main/third-party/pjproject"
    click OpusCodec "https://github.com/oliverepper/libphone/tree/main/third-party/opus"
    click CAPI "https://github.com/oliverepper/libphone/blob/main/src/phone/include/phone.h"

    %% Legend
    subgraph Legend
        L1["Client Application"]:::client
        L2["API Component"]:::api
        L3["Core Component"]:::core
        L4["Platform Specific"]:::platform
        L5["External Dependency"]:::external
    end
```
