# h4r1z1b4mx/audsync architecture

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

- Interactive diagram: https://gitdiagram.com/h4r1z1b4mx/audsync
- Repository: https://github.com/h4r1z1b4mx/audsync

## Overview

##### Project Type and Purpose
- AudSync is a cross-platform, real-time audio streaming application implemented in C++17.
- It follows a classic client-server architecture: multiple clients capture/play back audio locally and stream audio packets to/from a central server instance over TCP.

##### File Structure Analysis
- Top-Level Build and Config
- CMakeLists.txt, cmake/, build.sh/.bat – cross-platform build scripts & configs.
- install_deps.* – automated dependency installers (PortAudio, ALSA, etc.).
- Core Code
- / – public headers defining the key abstractions: AudioBuffer, AudioClient, AudioProcessor, AudioServer, NetworkManager.
- src/ – corresponding implementations plus two entry points: main_client.cpp and main_server.cpp.
- Documentation and Guides
- README.md, CROSS_PLATFORM_GUIDE.md, MIGRATION_SUMMARY.md, functionality.md – describe features, setup, architecture notes.

##### README Insights
- Lists five core components: NetworkManager (TCP), AudioProcessor (PortAudio wrapper), AudioServer, AudioClient, AudioBuffer (thread-safe queue).
- Emphasizes low-latency real-time streaming; multi-client support; cross-platform abstractions.

- Use clear, descriptive labels for each component block (e.g., “AudioClient”, “AudioBuffer”).
- Green: Audio subsystem (AudioProcessor, OS audio)
- Blue: Buffering (AudioBuffer)
- Orange: Networking (NetworkManager, TCP)
- Purple: Coordination (AudioServer, AudioClient)
- Rounded rectangles for processes/services.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Subsystem
    subgraph "Client Subsystem"
        direction TB
        AClient["AudioClient"]:::coord
        AProc["AudioProcessor"]:::audio
        OSClient["OS Audio (PortAudio → ALSA/CoreAudio/WASAPI)"]:::external
        ABuff[(AudioBuffer)]:::buffer
        NMgrClient["NetworkManager (TCP)"]:::network
        mainClient["main_client.cpp"]:::coord
    end

    %% Server Subsystem
    subgraph "Server Subsystem"
        direction TB
        mainServer["main_server.cpp"]:::coord
        NMgrServer["NetworkManager (TCP Listener)"]:::network
        ABuffSrv[(AudioBuffer)]:::buffer
        AServer["AudioServer"]:::coord
        OSSrv["OS Audio (Optional Mixing)"]:::external
    end

    %% Network Cloud
    Net((Network)):::external

    %% Connections - Client Flow
    AClient -->|"init capture/playback"| AProc
    AProc -->|"captures PCM frames"| ABuff
    ABuff -->|"provides frames"| NMgrClient
    NMgrClient -->|"sends TCP packets"| Net

    %% Connections - Server Flow
    Net -->|"receives packets"| NMgrServer
    NMgrServer -->|"pushes to buffer"| ABuffSrv
    ABuffSrv -->|"streams to"| AServer
    AServer -->|"distributes packets"| NMgrServer
    NMgrServer -->|"sends to clients"| Net

    %% Connections - Client Receive Flow
    Net -->|"incoming packets"| NMgrClient
    NMgrClient -->|"pushes to buffer"| ABuff
    ABuff -->|"provides to processor"| AProc
    AProc -->|"plays audio"| OSClient

    %% Entry Points to Components
    mainClient --> AClient
    mainServer --> NMgrServer

    %% Click Events
    click ABuff "https://github.com/h4r1z1b4mx/audsync/blob/main/include/AudioBuffer.h"
    click ABuff "https://github.com/h4r1z1b4mx/audsync/blob/main/src/AudioBuffer.cpp"
    click AClient "https://github.com/h4r1z1b4mx/audsync/blob/main/include/AudioClient.h"
    click AClient "https://github.com/h4r1z1b4mx/audsync/blob/main/src/AudioClient.cpp"
    click AProc "https://github.com/h4r1z1b4mx/audsync/blob/main/include/AudioProcessor.h"
    click AProc "https://github.com/h4r1z1b4mx/audsync/blob/main/src/AudioProcessor.cpp"
    click AServer "https://github.com/h4r1z1b4mx/audsync/blob/main/include/AudioServer.h"
    click AServer "https://github.com/h4r1z1b4mx/audsync/blob/main/src/AudioServer.cpp"
    click NMgrClient "https://github.com/h4r1z1b4mx/audsync/blob/main/include/NetworkManager.h"
    click NMgrClient "https://github.com/h4r1z1b4mx/audsync/blob/main/src/NetworkManager.cpp"
    click mainClient "https://github.com/h4r1z1b4mx/audsync/blob/main/src/main_client.cpp"
    click mainServer "https://github.com/h4r1z1b4mx/audsync/blob/main/src/main_server.cpp"
    click CMake "https://github.com/h4r1z1b4mx/audsync/blob/main/CMakeLists.txt"
    click CMake "https://github.com/h4r1z1b4mx/audsync/tree/main/cmake/"

    %% Styles
    classDef audio fill:#a8e6cf,stroke:#379683,color:#054a29
    classDef buffer fill:#dcedc1,stroke:#8ac926,color:#52734d
    classDef network fill:#ffd3b6,stroke:#ff8b94,color:#9e2a2b
    classDef coord fill:#ffaaa5,stroke:#ff6f69,color:#882d17
    classDef external fill:#eeeeee,stroke:#cccccc,color:#555555
```
