# gpgtools/macgpg2 architecture

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

- Interactive diagram: https://gitdiagram.com/gpgtools/macgpg2
- Repository: https://github.com/gpgtools/macgpg2

## Overview

##### Project Type and Purpose
- MacGPG2 is a packaging/build‐orchestration project that produces a macOS‐ready distribution of GnuPG 2 (with GnuTLS, Nettle, etc.) by applying a curated set of patches and bundling binaries, configs, and helper scripts into a payload for installation.

##### High-Level Components
a. Upstream Sources
- GnuPG, GnuTLS, Nettle upstream tarballs or repos
b. Patch Management
- patches/gnupg
- patches/gnutls
- patches/nettle
c. Build Orchestration
- Makefile
- shell scripts (add_version_plist.sh, create_gpg.sh, check_for_new_versions*.sh/.py)
- Version.config, libs.json
- build tools (gcc/clang, lzip, patch, autotools)
d. Packaging & Payload
- payload/bin (convert-keyring, etc.)
- payload/libexec (fixGpgHome, shutdown-gpg-agent)
- payload/etc/skel/.gnupg (default configs)
e. Distribution & Installation
- Resulting “build/MacGPG2” directory → copy to /usr/local/MacGPG2

##### Relationships & Data Flow
1. Fetch upstream sources
2. Apply patches via patch management
3. Invoke Makefile and helper scripts to configure, compile, and link binaries
4. Generate versioned artifacts (using Version.config, add_version_plist.sh)
5. Populate payload tree with executables, libexec utilities, and config skeletons
6. Package “build/MacGPG2” for end‐user installation

##### Architectural Patterns & Principles
- Pipeline/chain of transformations: Source → Patch → Build → Package
- Single‐repository orchestration: all patches, scripts, and packaging in one cohesive tree
- Separation of concerns:
- patches/ for all source tweaks
- scripts/Makefile for orchestration
- payload/ for final install layout

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Layer 1: Upstream Sources
    subgraph "Layer 1: Upstream Sources"
        style Up_GnuPG fill:#D0E8FF,stroke:#004080
        Up_GnuPG["GnuPG Upstream"]:::upstream
        style Up_GnuTLS fill:#D0E8FF,stroke:#004080
        Up_GnuTLS["GnuTLS Upstream"]:::upstream
        style Up_Nettle fill:#D0E8FF,stroke:#004080
        Up_Nettle["Nettle Upstream"]:::upstream
    end

    %% Layer 2: Patch Manager
    subgraph "Layer 2: Patch Manager"
        style Patches_GnuPG fill:#FFF4C2,stroke:#8A6508
        Patches_GnuPG["patches/gnupg"]:::patch
        style Patches_GnuTLS fill:#FFF4C2,stroke:#8A6508
        Patches_GnuTLS["patches/gnutls"]:::patch
        style Patches_Nettle fill:#FFF4C2,stroke:#8A6508
        Patches_Nettle["patches/nettle"]:::patch
    end

    %% Layer 3: Build Orchestrator
    subgraph "Layer 3: Build Orchestrator"
        style MakefileNode fill:#D2F8D2,stroke:#1A7F1A
        MakefileNode["Makefile"]:::build
        style Script_Version fill:#D2F8D2,stroke:#1A7F1A
        Script_Version["add_version_plist.sh"]:::build
        style Script_CreateGPG fill:#D2F8D2,stroke:#1A7F1A
        Script_CreateGPG["create_gpg.sh"]:::build
        style Script_CheckSH fill:#D2F8D2,stroke:#1A7F1A
        Script_CheckSH["check_for_new_versions (FTP).sh"]:::build
        style Script_CheckPY fill:#D2F8D2,stroke:#1A7F1A
        Script_CheckPY["check_for_new_versions.py"]:::build
        style Config_Version fill:#D2F8D2,stroke:#1A7F1A
        Config_Version["Version.config"]:::build
        style Config_Libs fill:#D2F8D2,stroke:#1A7F1A
        Config_Libs["libs.json"]:::build

        %% External dependencies
        style ExtDeps fill:#E0E0E0,stroke:#606060
        ExtDeps["gcc/clang, lzip, patch, autotools"]:::external
    end

    %% Layer 4: Packaging Module
    subgraph "Layer 4: Packaging Module"
        style Payload_Bin fill:#FFE0B2,stroke:#B35900
        Payload_Bin["payload/bin"]:::payload
        style Payload_Libexec fill:#FFE0B2,stroke:#B35900
        Payload_Libexec["payload/libexec"]:::payload
        style Payload_Skel fill:#FFE0B2,stroke:#B35900
        Payload_Skel["payload/etc/skel/.gnupg"]:::payload
        style Skel_dirmngr fill:#FFE0B2,stroke:#B35900
        Skel_dirmngr["dirmngr.conf"]:::payload
        style Skel_agent fill:#FFE0B2,stroke:#B35900
        Skel_agent["gpg-agent.conf"]:::payload
        style Skel_gpg fill:#FFE0B2,stroke:#B35900
        Skel_gpg["gpg.conf"]:::payload
    end

    %% Layer 5: Installation Target
    subgraph "Layer 5: Installation Target"
        style Install_Target fill:#FFFFFF,stroke:#000000
        Install_Target["build/MacGPG2 → /usr/local/MacGPG2"]:::target
    end

    %% Relationships & Data Flow
    Up_GnuPG -->|"fetch"| Patches_GnuPG
    Up_GnuTLS -->|"fetch"| Patches_GnuTLS
    Up_Nettle -->|"fetch"| Patches_Nettle

    Patches_GnuPG -->|"apply patches"| MakefileNode
    Patches_GnuTLS -->|"apply patches"| MakefileNode
    Patches_Nettle -->|"apply patches"| MakefileNode

    MakefileNode -->|"invoke scripts"| Script_Version
    MakefileNode -->|"invoke scripts"| Script_CreateGPG
    MakefileNode -->|"invoke scripts"| Script_CheckSH
    MakefileNode -->|"invoke scripts"| Script_CheckPY
    MakefileNode -->|"use configs"| Config_Version
    MakefileNode -->|"use configs"| Config_Libs

    ExtDeps -->|"tools for build"| MakefileNode

    MakefileNode -->|"compile & link"| Payload_Bin
    MakefileNode -->|"generate helpers"| Payload_Libexec
    MakefileNode -->|"populate configs"| Payload_Skel

    Payload_Skel --> Skel_dirmngr
    Payload_Skel --> Skel_agent
    Payload_Skel --> Skel_gpg

    Payload_Bin -->|"assemble payload"| Install_Target
    Payload_Libexec -->|"assemble payload"| Install_Target
    Payload_Skel -->|"assemble payload"| Install_Target

    %% Click Events
    click Patches_GnuPG "https://github.com/gpgtools/macgpg2/tree/dev/patches/gnupg"
    click Patches_GnuTLS "https://github.com/gpgtools/macgpg2/tree/dev/patches/gnutls"
    click Patches_Nettle "https://github.com/gpgtools/macgpg2/tree/dev/patches/nettle"
    click MakefileNode "https://github.com/gpgtools/macgpg2/tree/dev/Makefile"
    click Script_Version "https://github.com/gpgtools/macgpg2/blob/dev/add_version_plist.sh"
    click Script_CreateGPG "https://github.com/gpgtools/macgpg2/blob/dev/create_gpg.sh"
    click Script_CheckSH "https://github.com/gpgtools/macgpg2/blob/dev/check_for_new_versions (FTP).sh"
    click Script_CheckPY "https://github.com/gpgtools/macgpg2/blob/dev/check_for_new_versions.py"
    click Config_Version "https://github.com/gpgtools/macgpg2/blob/dev/Version.config"
    click Config_Libs "https://github.com/gpgtools/macgpg2/blob/dev/libs.json"
    click Payload_Bin "https://github.com/gpgtools/macgpg2/tree/dev/payload/bin"
    click Payload_Libexec "https://github.com/gpgtools/macgpg2/tree/dev/payload/libexec"
    click Payload_Skel "https://github.com/gpgtools/macgpg2/blob/dev/payload/etc/skel/.gnupg"
    click Skel_dirmngr "https://github.com/gpgtools/macgpg2/blob/dev/payload/etc/skel/.gnupg/dirmngr.conf"
    click Skel_agent "https://github.com/gpgtools/macgpg2/blob/dev/payload/etc/skel/.gnupg/gpg-agent.conf"
    click Skel_gpg "https://github.com/gpgtools/macgpg2/blob/dev/payload/etc/skel/.gnupg/gpg.conf"

    %% Styles
    classDef upstream fill:#D0E8FF,stroke:#004080,stroke-width:1px
    classDef patch fill:#FFF4C2,stroke:#8A6508,stroke-width:1px
    classDef build fill:#D2F8D2,stroke:#1A7F1A,stroke-width:1px
    classDef payload fill:#FFE0B2,stroke:#B35900,stroke-width:1px
    classDef external fill:#E0E0E0,stroke:#606060,stroke-width:1px
    classDef target fill:#FFFFFF,stroke:#000000,stroke-width:1px,stroke-dasharray: 5 5
```
