# existentialaudio/blackhole architecture

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

- Interactive diagram: https://gitdiagram.com/existentialaudio/blackhole
- Repository: https://github.com/existentialaudio/blackhole

## Overview

##### Project type and purpose
- BlackHole is a system-level macOS virtual audio loopback driver.
- It implements a Core Audio HAL plugin (“driver”) that captures and routes audio between applications with zero added latency.
- The project includes source code (BlackHole/), tests (BlackHoleTests/), an Xcode project, installer/uninstaller scripts, and CI/CD packaging steps.

##### File structure
- Top-level:
– .github/: issue templates, funding
– BlackHole.xcodeproj/: Xcode project and workspace files
– BlackHoleTests/: C tests exerciser
– Installer/: scripts & HTML assets to create and sign the .pkg
– Uninstaller/: scripts to remove the installed driver
- Misc:
– Images/: documentation assets
– VERSION, CHANGELOG.md, README.md, LICENSE

##### README for additional insights
- Core Audio integration (no kernel extensions)
- Build targets for multiple channel versions, Intel/Apple Silicon
- Pre-compiler constants for customization (channel count, latency, sample rates, mirror device)
- CI/CD script (Installer/create_installer.sh) signs & notarizes

##### Main components
a. Development & Build
– Source Code (BlackHole.c + headers)
– Build System (Xcode & xcodebuild)
– Pre-compiler Definitions for customization
– BlackHoleTests harness
b. Packaging & Deployment
– Installer scripts → .pkg installer
– Uninstaller scripts → removal package
– Code signing & notarization (CI/CD)
c. Runtime / Host OS
– Core Audio HAL (the audio subsystem in macOS)
– BlackHole.driver bundle under /Library/Audio/Plug-Ins/HAL
– Hidden and mirrored audio devices created by the driver
d. External Applications
– Sending application (any DAW or system audio source)
– Receiving application (DAW, conferencing app, recording tool)
– Audio MIDI Setup / Sound Preferences (user interface)

##### Relationships and interactions
– Sending app → Core Audio HAL → BlackHole driver → mirrored device → Core Audio HAL → Receiving app

##### Architectural patterns and design principles
- Plugin architecture: HAL driver packaged as .driver bundle conforming to Core Audio interfaces
- Configurability via pre-compiler flags (compile-time customization)
- Separation of concerns:
– Code vs. packaging vs. testing vs. installer logic
– Driver logic vs. UI (handled externally via standard macOS tools)
- CI/CD automation for signing, notarization, and packaging

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Development & Build
    subgraph "Development & Build"
        subgraph "Source Code (Driver)"
            C["BlackHole.c"]:::build
            PL["BlackHole.plist"]:::build
            ICON["BlackHole.icns"]:::build
        end
        PC["Pre-compiler Definitions"]:::build
        BS["Xcode Build System"]:::build
        TH["Driver Test Harness"]:::build
    end

    %% Documentation & Assets
    subgraph "Docs & Assets"
        Docs["README.md, CHANGELOG.md, LICENSE, VERSION"]:::misc
        Assets["Images/"]:::misc
    end

    %% Packaging & Deployment
    subgraph "Packaging & Deployment"
        subgraph "Installer"
            InstScript["create_installer.sh"]:::pack
            Req["requirements.xml"]:::pack
            Welcome["welcome.html"]:::pack
            Conclusion["conclusion.html"]:::pack
            Pre["preinstall"]:::pack
            PostI["postinstall"]:::pack
        end
        CICD["CI/CD Automation"]:::pack
        PKG["Signed Installer .pkg"]:::pack
        subgraph "Uninstaller"
            UninstScript["create_uninstaller.sh"]:::pack
            Unpost["postinstall"]:::pack
        end
    end

    %% Installation & Runtime
    subgraph "Installation & Runtime"
        OS["Core Audio HAL"]:::runtime
        DRIVER["BlackHole.driver Bundle"]:::runtime
        Mirrored["Hidden & Mirrored Audio Devices"]:::runtime
    end

    %% External Applications
    EA["Sending Application"]:::external
    RA["Receiving Application"]:::external

    %% Build Flow
    C -->|included in| BS
    PL -->|included in| BS
    ICON -->|included in| BS
    PC -->|configures| BS
    BS -->|"builds"| DRIVER
    TH -->|tests| C

    %% Documentation Flow
    Docs -->|references| BS
    Assets -->|used by| Docs

    %% Packaging Flow
    DRIVER -->|"packaged by"| InstScript
    InstScript -->|"generates"| PKG
    CICD -->|"signs & notarizes"| PKG
    UninstScript -->|"generates Uninstaller"| Unpost

    %% Installation Flow
    PKG -->|"installs"| DRIVER

    %% Runtime Audio Flow
    EA -->|"Audio Data"| OS
    OS -->|"loads plugin"| DRIVER
    DRIVER -->|"creates"| Mirrored
    Mirrored -->|"routed through"| OS
    OS -->|"delivers audio to"| RA

    %% Uninstall Flow
    Unpost -->|"removes"| DRIVER

    %% Click Events
    click C "https://github.com/existentialaudio/blackhole/blob/master/BlackHole/BlackHole.c"
    click PL "https://github.com/existentialaudio/blackhole/blob/master/BlackHole/BlackHole.plist"
    click ICON "https://github.com/existentialaudio/blackhole/blob/master/BlackHole/BlackHole.icns"
    click PC "https://github.com/existentialaudio/blackhole/blob/master/BlackHole.xcodeproj/project.pbxproj"
    click BS "https://github.com/existentialaudio/blackhole/tree/master/BlackHole.xcodeproj/"
    click TH "https://github.com/existentialaudio/blackhole/blob/master/BlackHoleTests/main.c"
    click InstScript "https://github.com/existentialaudio/blackhole/blob/master/Installer/create_installer.sh"
    click Req "https://github.com/existentialaudio/blackhole/blob/master/Installer/requirements.xml"
    click Welcome "https://github.com/existentialaudio/blackhole/blob/master/Installer/welcome.html"
    click Conclusion "https://github.com/existentialaudio/blackhole/blob/master/Installer/conclusion.html"
    click Pre "https://github.com/existentialaudio/blackhole/tree/master/Installer/scripts/preinstall"
    click PostI "https://github.com/existentialaudio/blackhole/tree/master/Installer/scripts/postinstall"
    click CICD "https://github.com/existentialaudio/blackhole/blob/master/Installer/create_installer.sh"
    click CICD "https://github.com/existentialaudio/blackhole/tree/master/.github/ISSUE_TEMPLATE"
    click UninstScript "https://github.com/existentialaudio/blackhole/blob/master/Uninstaller/create_uninstaller.sh"
    click Unpost "https://github.com/existentialaudio/blackhole/tree/master/Uninstaller/Scripts/postinstall"
    click Docs "https://github.com/existentialaudio/blackhole/blob/master/README.md"
    click Docs "https://github.com/existentialaudio/blackhole/blob/master/CHANGELOG.md"
    click Docs "https://github.com/existentialaudio/blackhole/tree/master/LICENSE"
    click Docs "https://github.com/existentialaudio/blackhole/tree/master/VERSION"
    click Assets "https://github.com/existentialaudio/blackhole/tree/master/Images/"

    %% Styles
    classDef build fill:#e6ffe6,stroke:#2d8f2d
    classDef pack fill:#e6f0ff,stroke:#1f5fbf
    classDef runtime fill:#fff4e6,stroke:#bf6f1f
    classDef external fill:#f2f2f2,stroke:#666666
    classDef misc fill:#f9f9f9,stroke:#cccccc
```
