# thyrlian/airpdfprinter architecture

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

- Interactive diagram: https://gitdiagram.com/thyrlian/airpdfprinter
- Repository: https://github.com/thyrlian/airpdfprinter

## Overview

##### Project type and purpose
- This is a containerized, single‐service application whose sole function is to expose a virtual PDF printer via AirPrint (IPP + mDNS).
- The Docker image packages and runs CUPS (with CUPS-PDF backend) and Avahi daemon for Bonjour broadcasting.

##### File structure
- Top level:
- Dockerfile – builds the container image
- config.sh – initialization script
- cupsd.conf – custom CUPS configuration
- AirPrint-PDF.service – Avahi service definition for mDNS
- assets/ – documentation screenshots
- No “frontend” or “backend” directories: this is a single‐service (print server) container.
- Volumes are mapped at runtime:
- $(pwd)/pdf → /root/PDF (output directory)
- $(pwd)/cups-pdf → /var/spool/cups-pdf (print spool)

##### README for additional insights
- The container uses host networking (`--network=host`) so that:
- TCP port 631 (IPP) is bound to host’s CUPS port.
- UDP port 5353 (mDNS) is served by Avahi.
- DBus is required on the host for Avahi; not inside container.
- Dependencies: CUPS, cups-pdf, avahi-daemon, system init scripts.

##### Main components and interactions
a. Host environment
- Docker Engine
- systemd/dbus (for Avahi to fire on host)
b. Container
- CUPS print server (cupsd)
- CUPS-PDF backend (writes PDF output)
- Avahi daemon (reads AirPrint-PDF.service, broadcasts mDNS on 5353)
- config.sh entrypoint (starts services)
c. Runtime volumes
- PDF output directory
- CUPS-PDF spool directory
d. Clients
- iOS/macOS devices that discover the printer via mDNS and send IPP print jobs.

##### Architectural patterns & design principles
- Single responsibility: one container, one service.
- Host networking: everything binds directly to host stack—no Docker port mapping needed.
- Data persistence via host‐volume mapping.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clients
    iOS["iOS Device"]:::external
    macOS["macOS Device"]:::external

    %% Host Environment
    subgraph "Docker Host"
        Host["Docker Host"]:::compute
        DBus["systemd/dbus"]:::process
        Host --> ContainerNode
        DBus -.-> Avahi
    end

    %% Container
    subgraph "Docker Container"
        ContainerNode["Container"]:::compute
        ConfigScript["config.sh"]:::config
        CupsdConf["cupsd.conf"]:::config
        AvahiSvc["AirPrint-PDF.service"]:::config
        Cups["CUPS (631/TCP)"]:::process
        Avahi["Avahi daemon (5353/UDP)"]:::process
        Backend["CUPS-PDF backend"]:::process
        subgraph "Volumes"
            Spool["CUPS-PDF Spool Volume"]:::storage
            PDFOut["PDF Output Volume"]:::storage
        end
    end

    %% Data Flows
    iOS -->|"UDP 5353"| Avahi
    macOS -->|"UDP 5353"| Avahi
    iOS -->|"TCP 631"| Cups
    macOS -->|"TCP 631"| Cups

    ConfigScript --> Cups
    ConfigScript --> Avahi

    Cups --> Backend
    Backend --> Spool
    Spool --> PDFOut

    %% Documentation & Assets
    README["README.md"]:::external
    Assets["assets/"]:::external

    %% Click Events
    click ConfigScript "https://github.com/thyrlian/airpdfprinter/blob/master/config.sh"
    click CupsdConf "https://github.com/thyrlian/airpdfprinter/blob/master/cupsd.conf"
    click AvahiSvc "https://github.com/thyrlian/airpdfprinter/blob/master/AirPrint-PDF.service"
    click README "https://github.com/thyrlian/airpdfprinter/blob/master/README.md"
    click Assets "https://github.com/thyrlian/airpdfprinter/tree/master/assets/"
    click Dockerfile "https://github.com/thyrlian/airpdfprinter/tree/master/Dockerfile"

    %% Styles
    classDef compute fill:#D0E8FF,stroke:#0366d6,color:#0366d6
    classDef process fill:#E6FFDA,stroke:#22863a,color:#22863a
    classDef storage fill:#FFEFD5,stroke:#d15704,color:#d15704
    classDef config fill:#EDEDED,stroke:#6a737d,color:#6a737d
    classDef external fill:#FFF5B1,stroke:#735C0F,color:#735C0F
```
