# arc42/pdfminion architecture

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

- Interactive diagram: https://gitdiagram.com/arc42/pdfminion
- Repository: https://github.com/arc42/pdfminion

## Overview

##### Project type and purpose
- PDFminion is a cross-platform command-line tool (written in Go) for PDF manipulations (add page numbers, headers/footers, merging).
- It also includes a static website (Jekyll-based) under `docs/`, architectural decision records in `documentation/adr/`, and CI/CD workflows in `.github/workflows/`.

##### File structure
Top-level:
- `.github/workflows/`: CI jobs (linting, testing, FOSSA security scan).
- `go-app/`: the CLI application.
– `cmd/`: entry points for each subcommand (e.g. `detectSystemLanguage`).
– `internal/config/`: flag & YAML config parsing and wiring.
– `internal/domain/`: core commands, types, validation, language logic.
– `internal/pdf/`: PDF processing pipelines (single file or batch).
– `internal/util/`: helper routines.
– `sample-files-for-testing/`: test fixtures.
– `Dockerfile.linux-test`, `Makefile`: build/test scripts.
- `docs/`: static site (Jekyll) source for user documentation.

##### README
- Confirms it’s a CLI “minion” for mundane PDF tasks, built in Go, tested on macOS/Linux/Windows.
- Points to a publicly hosted Jekyll site.

##### Main components & relationships
A. User Interface
– “Terminal / CLI” – user invokes commands (e.g. `pdfminion --add-page-numbers …`).
B. Configuration Layer (`internal/config`)
– Parses flags, reads `myconfig.yaml` (layered config).
– Supplies structured config to Domain layer.
C. Command Dispatcher (`internal/domain`)
– Selects one of the basic commands (add headers, merge PDFs, etc.).
– Performs validation (via `validate.go`).
D. PDF Processing Layer (`internal/pdf`)
– `processSingleFile.go` / `processFiles.go` pipelines.
– Invokes external PDF library (e.g. `pdfcpu`).
– Reads from file system (input PDFs), writes new PDFs.
E. Utility Layer (`internal/util`)
– Provides shared helpers (logging, file ops).
– Called by both Config and PDF Processing.
F. External Dependencies
– Third-party Go modules: `xuanwo-go-locale`, `flag` package, `pdfcpu`.
– OS file system.
G. CI/CD & Build
– GitHub Actions workflows: lint (golangci-lint), test (go-test), FOSSA security scan.
– Makefile / Dockerfile.linux-test – for local builds and tests.
H. Documentation Site
– Jekyll source in `docs/` → static HTML.

##### Architectural patterns & design principles
- Layered architecture: CLI → Config → Domain → Processing → External libs
- Dependency inversion: Domain code is free of I/O; injected services handle I/O.
- Single-responsibility: each `internal/` package has a clear concern.
- ADR-driven design: documented trade-offs in `documentation/adr`.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Interface
    User["User (Shell)"]:::actor
    subgraph "CLI Layer"
        CLI["Terminal / CLI"]:::cli
        CMD["Entry Points (go-app/cmd/)"]:::cli
    end
    User -->|"invokes commands"| CLI
    CLI --> CMD

    %% Configuration Layer
    subgraph "Configuration Layer"
        CFG1["config.go"]:::config
        CFG2["setupAllCommands.go"]:::config
    end
    CMD -->|"loads flags/config"| CFG1
    CMD --> CFG2

    %% Domain / Command Dispatcher
    subgraph "Domain Layer"
        DC1["basicCommands.go"]:::domain
        DC2["validate.go"]:::domain
        DC3["language.go"]:::domain
        DC4["minionTypes.go"]:::domain
    end
    CFG2 -->|"provides config"| DC1
    CFG2 --> DC2
    CFG2 --> DC3
    CFG2 --> DC4

    %% PDF Processing Layer
    subgraph "PDF Processing Layer"
        PDF1["process.go"]:::pdf
        PDF2["processFiles.go"]:::pdf
        PDF3["processSingleFile.go"]:::pdf
    end
    DC1 -->|"dispatches"| PDF1
    DC1 --> PDF2
    DC1 --> PDF3

    %% Utility Layer
    subgraph "Utility Layer"
        UTIL["util.go"]:::util
    end
    CFG1 --> UTIL
    PDF1 --> UTIL
    PDF2 --> UTIL
    PDF3 --> UTIL

    %% External Dependencies
    FS["File System / PDFs"]:::external
    LIB["pdfcpu (Go Module)"]:::external
    PDF1 -->|"read/write PDFs"| FS
    PDF2 --> FS
    PDF3 --> FS
    PDF1 -->|"invokes"| LIB
    PDF2 --> LIB
    PDF3 --> LIB

    %% CI/CD & Build
    subgraph "CI/CD & Build" 
        LINT["golangci-lint.yml"]:::cicd
        TEST["go-test.yml"]:::cicd
        FOSSA["fossa-scan.yml"]:::cicd
        MAKE["Makefile"]:::build
        DOCK["Dockerfile.linux-test"]:::build
        LINT -.-> CMD
        TEST -.-> CMD
        FOSSA -.-> CMD
        MAKE -.-> CMD
        DOCK -.-> CMD
    end

    %% Documentation
    subgraph "Documentation"
        JEKYLL["docs/ (Jekyll site)"]:::docs
        ADR["documentation/adr/"]:::docs
        DIAGS["documentation/*.puml & functions/"]:::docs
    end

    %% Click Events
    click CMD "https://github.com/arc42/pdfminion/tree/main/go-app/cmd/"
    click CFG1 "https://github.com/arc42/pdfminion/blob/main/go-app/internal/config/config.go"
    click CFG2 "https://github.com/arc42/pdfminion/blob/main/go-app/internal/config/setupAllCommands.go"
    click DC1 "https://github.com/arc42/pdfminion/blob/main/go-app/internal/domain/basicCommands.go"
    click DC2 "https://github.com/arc42/pdfminion/blob/main/go-app/internal/domain/validate.go"
    click DC3 "https://github.com/arc42/pdfminion/blob/main/go-app/internal/domain/language.go"
    click DC4 "https://github.com/arc42/pdfminion/blob/main/go-app/internal/domain/minionTypes.go"
    click PDF1 "https://github.com/arc42/pdfminion/blob/main/go-app/internal/pdf/process.go"
    click PDF2 "https://github.com/arc42/pdfminion/blob/main/go-app/internal/pdf/processFiles.go"
    click PDF3 "https://github.com/arc42/pdfminion/blob/main/go-app/internal/pdf/processSingleFile.go"
    click UTIL "https://github.com/arc42/pdfminion/blob/main/go-app/internal/util/util.go"
    click LINT "https://github.com/arc42/pdfminion/blob/main/.github/workflows/golangci-lint.yml"
    click TEST "https://github.com/arc42/pdfminion/blob/main/.github/workflows/go-test.yml"
    click FOSSA "https://github.com/arc42/pdfminion/blob/main/.github/workflows/fossa-scan.yml"
    click MAKE "https://github.com/arc42/pdfminion/tree/main/go-app/Makefile"
    click DOCK "https://github.com/arc42/pdfminion/blob/main/go-app/Dockerfile.linux-test"
    click JEKYLL "https://github.com/arc42/pdfminion/tree/main/docs/"
    click ADR "https://github.com/arc42/pdfminion/tree/main/documentation/adr/"
    click DIAGS "https://github.com/arc42/pdfminion/tree/main/documentation/"

    %% Styles
    classDef actor fill:#EFEFEF,stroke:#333,stroke-width:1px
    classDef cli fill:#D0E1FF,stroke:#0366d6,stroke-width:1px
    classDef config fill:#DFFFE0,stroke:#2e8b57,stroke-width:1px
    classDef domain fill:#E0FFFF,stroke:#20b2aa,stroke-width:1px
    classDef pdf fill:#FFE4B5,stroke:#ff8c00,stroke-width:1px
    classDef util fill:#D3E5FF,stroke:#4169e1,stroke-width:1px
    classDef external fill:#FFD6D6,stroke:#d14,stroke-width:1px,stroke-dasharray: 5 5
    classDef cicd fill:#E8D7FF,stroke:#800080,stroke-width:1px,stroke-dasharray: 2 2
    classDef build fill:#F0E68C,stroke:#b8860b,stroke-width:1px,stroke-dasharray: 2 2
    classDef docs fill:#F2F2F2,stroke:#666,stroke-width:1px,stroke-dasharray: 2 2
```
