# voiceip/tinyphone architecture

> Architecture diagram of the GitHub repository voiceip/tinyphone, 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/voiceip/tinyphone
- Repository: https://github.com/voiceip/tinyphone

## Overview

##### Main Components

a) Core Components:
- PJSIP Integration Layer (based on lib/pjproject)
- REST API Server (port 6060)
- WebSocket Event System
- Account Management System
- Call Management System
- Audio Processing System (using lib/portaudio and lib/opus)

b) Platform-Specific Components:
- Windows UI Implementation
- MacOS UI Implementation
- Linux Console Implementation

##### Key Architectural Elements

**┌─ User Interface Layer ─────────────────────┐**
- Windows UI │ MacOS UI │ Linux Console UI   │
- API Layer ────────────────────────────────┤
- REST API Server │ WebSocket Events         │
- Core Services Layer ─────────────────────┤
- Account Manager │ Call Manager │ Config    │
- Media Layer ──────────────────────────────┤
- Audio Processing │ Codec Support           │
- PJSIP Integration Layer ─────────────────┤
- SIP Stack │ Media Stack │ NAT Traversal   │
- ┘

##### Component Relationships

- Media streams (thick lines)

##### Important Details

a) API Endpoints:
- REST endpoints (/login, /dial, /calls, etc.)
- WebSocket events endpoint
- Port number (6060)

b) External Dependencies:
- PJSIP integration
- Audio codecs (Opus, BCG729)
- Network libraries (curl)
- Logging (spdlog)
- Metrics (statsd-cpp)

##### Cross-Platform Architecture

How the core components are shared across:
- tinyphone/ (core implementation)
- tinyphone-osx/ (MacOS specific)
- tinyphone-linux/ (Linux specific)
- Windows-specific implementation

##### Additional Elements

Notes about:
- Configuration management (config.json)
- Security features (cryptopp library)
- Build system integration
- Installer packages

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef ui fill:#4a90e2,stroke:#2c3e50,color:white
    classDef api fill:#2ecc71,stroke:#27ae60,color:white
    classDef core fill:#e67e22,stroke:#d35400,color:white
    classDef media fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef lib fill:#34495e,stroke:#2c3e50,color:white

    %% UI Layer
    subgraph UI
        WinUI["Windows UI"]:::ui
        MacUI["MacOS UI"]:::ui
        LinuxUI["Linux Console"]:::ui
    end

    %% API Layer
    subgraph APILayer
        REST["REST API Server\n(Port 6060)"]:::api
        WS["WebSocket Events"]:::api
        Net["Network Handler"]:::api
    end

    %% Core Services
    subgraph CoreServices
        Phone["Phone Core"]:::core
        AccMgr["Account Manager"]:::core
        CallMgr["Call Manager"]:::core
        Config["Configuration"]:::core
        Events["Events System"]:::core
        Metrics["Metrics System"]:::core
    end

    %% Media Layer
    subgraph MediaLayer
        Audio["Audio Processing"]:::media
        Codec["Codec Support"]:::media
    end

    %% PJSIP Integration
    subgraph PJSIPLayer
        PJSIP["PJSIP Stack"]:::external
        SIPStack["SIP Stack"]:::external
        MediaStack["Media Stack"]:::external
    end

    %% Supporting Libraries
    subgraph Libraries
        Logger["Logging (spdlog)"]:::lib
        Stats["Statistics (statsd)"]:::lib
        Crypto["Encryption (cryptopp)"]:::lib
        HTTP["HTTP Client (curl)"]:::lib
        JSON["JSON Processing"]:::lib
    end

    %% Relationships
    WinUI --> REST
    MacUI --> REST
    LinuxUI --> REST
    REST --> Phone
    WS --> Events
    Phone --> AccMgr
    Phone --> CallMgr
    Phone --> Config
    AccMgr --> PJSIP
    CallMgr --> PJSIP
    PJSIP --> SIPStack
    PJSIP --> MediaStack
    Audio --> MediaStack
    Codec --> MediaStack
    Net --> HTTP

    %% Click Events
    click WinUI "https://github.com/voiceip/tinyphone/blob/master/tinyphone/winapp.cpp"
    click MacUI "https://github.com/voiceip/tinyphone/blob/master/tinyphone-osx/src/osxapp.cpp"
    click LinuxUI "https://github.com/voiceip/tinyphone/blob/master/tinyphone-linux/console.cpp"
    click REST "https://github.com/voiceip/tinyphone/blob/master/tinyphone/server.cpp"
    click Net "https://github.com/voiceip/tinyphone/blob/master/tinyphone/net.cpp"
    click Phone "https://github.com/voiceip/tinyphone/blob/master/tinyphone/phone.cpp"
    click AccMgr "https://github.com/voiceip/tinyphone/blob/master/tinyphone/account.cpp"
    click CallMgr "https://github.com/voiceip/tinyphone/blob/master/tinyphone/call.cpp"
    click Config "https://github.com/voiceip/tinyphone/blob/master/tinyphone/config.cpp"
    click Events "https://github.com/voiceip/tinyphone/blob/master/tinyphone/events.h"
    click Metrics "https://github.com/voiceip/tinyphone/blob/master/tinyphone/metrics.h"
    click PJSIP "https://github.com/voiceip/tinyphone/tree/master/lib/pjproject/"
    click Audio "https://github.com/voiceip/tinyphone/tree/master/lib/portaudio/"
    click Codec "https://github.com/voiceip/tinyphone/tree/master/lib/opus/"
    click Logger "https://github.com/voiceip/tinyphone/tree/master/lib/spdlog/"
    click Stats "https://github.com/voiceip/tinyphone/tree/master/lib/statsd-cpp/"
    click Crypto "https://github.com/voiceip/tinyphone/tree/master/lib/cryptopp/"
    click HTTP "https://github.com/voiceip/tinyphone/tree/master/lib/curl/"
    click JSON "https://github.com/voiceip/tinyphone/tree/master/lib/json/"

    %% Legend
    subgraph Legend
        L1["UI Components"]:::ui
        L2["API Components"]:::api
        L3["Core Services"]:::core
        L4["Media Components"]:::media
        L5["External Systems"]:::external
        L6["Libraries"]:::lib
    end
```
