# zugferd/mustangproject architecture

> Architecture diagram of the GitHub repository zugferd/mustangproject, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zugferd/mustangproject
- Repository: https://github.com/zugferd/mustangproject

## Overview

1. The repository is a multi-module Maven project centered on ZUGFeRD/Factur-X and XRechnung electronic invoices. The root `pom.xml` aggregates three main runtime modules: `library`, `validator`, and `Mustang-CLI`.

2. `library` is the core domain module. It contains the invoice object model (`Invoice`, `Item`, `TradeParty`, `CalculatedInvoice`, tax/discount/payment entities), plus interfaces that define exportable transaction data and adapters for different invoice profiles and standards.

3. The library’s main responsibility is bidirectional conversion: it can build invoice metadata from business objects, export it into embedded XML/XMP/PDF-related representations, and import existing invoices back from PDF or XML. The `ZUGFeRD` package holds most of these import/export entry points and format-specific providers.

4. Format handling is a major boundary in the library. The code distinguishes between multiple standards and profiles: ZUGFeRD 1/2, Factur-X, XRechnung, UBL, and CII. There are exporters, importers, and conversion helpers for these variants, plus profile/version abstractions such as `Profile`, `Profiles`, and `EStandard`.

5. Validation is separated into its own `validator` module. It provides `XMLValidator`, `PDFValidator`, and the higher-level `ZUGFeRDValidator`, which combine schema checks, schematron-style business rule checks, and PDF/XMP content inspection into a single validation result model.

6. The validator’s resources are a key part of the architecture. It ships the schema and rule assets needed for offline validation: XSDs, Schematron files, and precompiled XSLT transformations for ZUGFeRD, Factur-X, XRechnung, and UBL. These resources are not just supporting files; they are the validation engine’s rule base.

7. `Mustang-CLI` is a thin command-line subsystem over the library/validator capabilities. Its classes (`Main`, `FileTraverser`, `ValidatorFileWalker`, `FileChecker`, `StatRun`) indicate a file-oriented workflow for walking directories, checking invoice files, and producing validation/statistics output rather than serving requests or exposing an API.

8. The primary data flow is file-centric: PDF or XML invoice input enters through the CLI or validator, is parsed by the library/validator classes, validated against embedded schemas/rules, and may be converted or visualized using the library’s XSLT/HTML assets. The workflow is designed for offline batch processing and local inspection.

9. PDF handling is an important integration boundary. The presence of PDF-related exporters, XMP schema classes, ICC color profiles, and PDF validation resources indicates the project reads and writes PDF/A-style documents with embedded invoice metadata, not just standalone XML.

10. The repository includes a large set of transformation and visualization resources under `library/src/main/resources/stylesheets` and related files. These XSLT/CSS/JS assets support rendering invoice XML into HTML or PDF-oriented outputs and transforming between invoice dialects and profile versions.

11. Testing is extensive and fixture-driven. The `library` and `validator` modules both contain many sample PDFs/XMLs and JUnit tests covering import/export, arithmetic, backward compatibility, profile rules, and validation edge cases. This suggests the architecture relies heavily on golden-file regression tests for standard compliance.

12. The `doc` directory contains architecture diagrams and development documentation, reinforcing that the project treats standards compatibility and transformation paths as first-class architectural concerns. The overall system is best understood as a standards-processing engine with a CLI wrapper, not as a general-purpose application server.

Main entry points: [`library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA3.java`](https://github.com/zugferd/mustangproject/blob/master/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA3.java) (Exporters), [`library/src/main/java/org/mustangproject/Invoice.java`](https://github.com/zugferd/mustangproject/blob/master/library/src/main/java/org/mustangproject/Invoice.java) (Invoice Model), [`pom.xml`](https://github.com/zugferd/mustangproject/blob/master/pom.xml) (Root POM), [`Mustang-CLI/src/main/java/org/mustangproject/commandline/FileChecker.java`](https://github.com/zugferd/mustangproject/blob/master/Mustang-CLI/src/main/java/org/mustangproject/commandline/FileChecker.java) (File Check)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_root["Project"]
  node_pom["Root POM<br/>maven aggregator<br/>[pom.xml]"]
end

subgraph group_library["Library"]
  node_lib_model["Invoice Model<br/>domain model<br/>[Invoice.java]"]
  node_lib_contracts["Export Contracts<br/>interfaces"]
  node_lib_calculation["Calculation Core"]
  node_lib_profiles["Profiles<br/>profile/version<br/>[Profile.java]"]
  node_lib_export["Exporters<br/>xml/pdf export"]
  node_lib_import["Importers<br/>xml/pdf import"]
  node_lib_formats["Format Adapters<br/>standards adapters"]
  node_lib_xslt["Stylesheets<br/>transform resources<br/>[ZF1ToZF2.xsl]"]
  node_lib_pdf["PDF Metadata<br/>pdf/xmp"]
  node_lib_resources["Runtime Assets<br/>icc/fonts/config<br/>[fop-config.xconf]"]
end

subgraph group_validator["Validator"]
  node_val_api["Validation API<br/>validation core<br/>[Validator.java]"]
  node_val_xml["XML Validator<br/>schema validation<br/>[XMLValidator.java]"]
  node_val_pdf["PDF Validator<br/>pdf inspection<br/>[PDFValidator.java]"]
  node_val_zugferd["ZUGFeRD Validator<br/>combined validation"]
  node_val_rules["Rule Assets<br/>schemas/schematron/xslt"]
end

subgraph group_cli["CLI"]
  node_cli_main(("Main<br/>cli entrypoint<br/>[Main.java]"))
  node_cli_walk["File Walker<br/>directory traversal<br/>[FileTraverser.java]"]
  node_cli_check["File Check<br/>batch validation<br/>[FileChecker.java]"]
  node_cli_stats["Stats Run<br/>reporting<br/>[StatRun.java]"]
end

node_pom -->|"builds"| node_lib_model
node_pom -->|"builds"| node_val_api
node_pom -->|"builds"| node_cli_main
node_lib_model -->|"implements"| node_lib_contracts
node_lib_model -->|"uses"| node_lib_calculation
node_lib_contracts -->|"feeds"| node_lib_export
node_lib_calculation -->|"feeds"| node_lib_export
node_lib_profiles -->|"selects"| node_lib_export
node_lib_formats -->|"specializes"| node_lib_export
node_lib_formats -->|"specializes"| node_lib_import
node_lib_import -->|"populates"| node_lib_model
node_lib_export -->|"renders with"| node_lib_xslt
node_lib_export -->|"embeds"| node_lib_pdf
node_lib_pdf -->|"uses"| node_lib_resources
node_val_zugferd -->|"includes"| node_val_xml
node_val_zugferd -->|"includes"| node_val_pdf
node_val_xml -->|"loads"| node_val_rules
node_val_pdf -->|"loads"| node_val_rules
node_cli_main -->|"orchestrates"| node_cli_walk
node_cli_walk -->|"invokes"| node_cli_check
node_cli_check -->|"validates"| node_val_zugferd
node_cli_check -->|"reports to"| node_cli_stats

click node_pom "https://github.com/zugferd/mustangproject/blob/master/pom.xml"
click node_lib_model "https://github.com/zugferd/mustangproject/blob/master/library/src/main/java/org/mustangproject/Invoice.java"
click node_lib_contracts "https://github.com/zugferd/mustangproject/blob/master/library/src/main/java/org/mustangproject/ZUGFeRD/IExportableTransaction.java"
click node_lib_calculation "https://github.com/zugferd/mustangproject/blob/master/library/src/main/java/org/mustangproject/CalculatedInvoice.java"
click node_lib_profiles "https://github.com/zugferd/mustangproject/blob/master/library/src/main/java/org/mustangproject/ZUGFeRD/Profile.java"
click node_lib_export "https://github.com/zugferd/mustangproject/blob/master/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA3.java"
click node_lib_import "https://github.com/zugferd/mustangproject/blob/master/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java"
click node_lib_formats "https://github.com/zugferd/mustangproject/blob/master/library/src/main/java/org/mustangproject/ZUGFeRD/XRechnungImporter.java"
click node_lib_xslt "https://github.com/zugferd/mustangproject/blob/master/library/src/main/resources/stylesheets/ZF1ToZF2.xsl"
click node_lib_pdf "https://github.com/zugferd/mustangproject/blob/master/library/src/main/java/org/mustangproject/ZUGFeRD/XMPSchemaZugferd.java"
click node_lib_resources "https://github.com/zugferd/mustangproject/blob/master/library/src/main/resources/fop-config.xconf"
click node_val_api "https://github.com/zugferd/mustangproject/blob/master/validator/src/main/java/org/mustangproject/validator/Validator.java"
click node_val_xml "https://github.com/zugferd/mustangproject/blob/master/validator/src/main/java/org/mustangproject/validator/XMLValidator.java"
click node_val_pdf "https://github.com/zugferd/mustangproject/blob/master/validator/src/main/java/org/mustangproject/validator/PDFValidator.java"
click node_val_zugferd "https://github.com/zugferd/mustangproject/blob/master/validator/src/main/java/org/mustangproject/validator/ZUGFeRDValidator.java"
click node_val_rules "https://github.com/zugferd/mustangproject/blob/master/validator/src/main/resources/schematron/ZF_240/FACTUR-X_EN16931.sch"
click node_cli_main "https://github.com/zugferd/mustangproject/blob/master/Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java"
click node_cli_walk "https://github.com/zugferd/mustangproject/blob/master/Mustang-CLI/src/main/java/org/mustangproject/commandline/FileTraverser.java"
click node_cli_check "https://github.com/zugferd/mustangproject/blob/master/Mustang-CLI/src/main/java/org/mustangproject/commandline/FileChecker.java"
click node_cli_stats "https://github.com/zugferd/mustangproject/blob/master/Mustang-CLI/src/main/java/org/mustangproject/commandline/StatRun.java"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_pom toneBlue
class node_lib_model,node_lib_contracts,node_lib_calculation,node_lib_profiles,node_lib_export,node_lib_import,node_lib_formats,node_lib_xslt,node_lib_pdf,node_lib_resources toneAmber
class node_val_api,node_val_xml,node_val_pdf,node_val_zugferd,node_val_rules toneMint
class node_cli_main,node_cli_walk,node_cli_check,node_cli_stats toneRose
```

## Components

### Project

Maven aggregator and top-level modules

- [Root POM](https://github.com/zugferd/mustangproject/blob/master/pom.xml): maven aggregator · Aggregates the main modules and coordinates the build · `pom.xml`

### Library

Core invoice model, conversion, and format adapters

- [Invoice Model](https://github.com/zugferd/mustangproject/blob/master/library/src/main/java/org/mustangproject/Invoice.java): domain model · Invoice, item, parties, totals, taxes, and related business entities · `library/src/main/java/org/mustangproject/Invoice.java`
- [Export Contracts](https://github.com/zugferd/mustangproject/blob/master/library/src/main/java/org/mustangproject/ZUGFeRD/IExportableTransaction.java): interfaces · Exportable transaction and party/item/payment abstractions · `library/src/main/java/org/mustangproject/ZUGFeRD/IExportableTransaction.java`
- [Calculation Core](https://github.com/zugferd/mustangproject/blob/master/library/src/main/java/org/mustangproject/CalculatedInvoice.java): calculation · Arithmetic and invoice amount computation helpers · `library/src/main/java/org/mustangproject/CalculatedInvoice.java`
- [Profiles](https://github.com/zugferd/mustangproject/blob/master/library/src/main/java/org/mustangproject/ZUGFeRD/Profile.java): profile/version · Standard, profile, and version abstractions for invoice variants · `library/src/main/java/org/mustangproject/ZUGFeRD/Profile.java`
- [Exporters](https://github.com/zugferd/mustangproject/blob/master/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA3.java): xml/pdf export · Builds XML, XMP, and PDF-related invoice representations · `library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA3.java`
- [Importers](https://github.com/zugferd/mustangproject/blob/master/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java): xml/pdf import · Reads invoice data back from PDF or XML sources · `library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java`
- [Format Adapters](https://github.com/zugferd/mustangproject/blob/master/library/src/main/java/org/mustangproject/ZUGFeRD/XRechnungImporter.java): standards adapters · Adapters for ZUGFeRD, Factur-X, XRechnung, UBL, and CII transformations · `library/src/main/java/org/mustangproject/ZUGFeRD/XRechnungImporter.java`
- [Stylesheets](https://github.com/zugferd/mustangproject/blob/master/library/src/main/resources/stylesheets/ZF1ToZF2.xsl): transform resources · XSLT, HTML, CSS, and JS assets for conversion and visualization · `library/src/main/resources/stylesheets/ZF1ToZF2.xsl`
- [PDF Metadata](https://github.com/zugferd/mustangproject/blob/master/library/src/main/java/org/mustangproject/ZUGFeRD/XMPSchemaZugferd.java): pdf/xmp · PDF/A conformance, XMP schemas, and related embedded metadata support · `library/src/main/java/org/mustangproject/ZUGFeRD/XMPSchemaZugferd.java`
- [Runtime Assets](https://github.com/zugferd/mustangproject/blob/master/library/src/main/resources/fop-config.xconf): icc/fonts/config · Fonts, ICC profiles, logging, and FOP configuration for rendering/output · `library/src/main/resources/fop-config.xconf`

### Validator

XML, PDF, and rule-based validation engine

- [Validation API](https://github.com/zugferd/mustangproject/blob/master/validator/src/main/java/org/mustangproject/validator/Validator.java): validation core · Shared validation result and context model · `validator/src/main/java/org/mustangproject/validator/Validator.java`
- [XML Validator](https://github.com/zugferd/mustangproject/blob/master/validator/src/main/java/org/mustangproject/validator/XMLValidator.java): schema validation · Schema-based validation for invoice XML payloads · `validator/src/main/java/org/mustangproject/validator/XMLValidator.java`
- [PDF Validator](https://github.com/zugferd/mustangproject/blob/master/validator/src/main/java/org/mustangproject/validator/PDFValidator.java): pdf inspection · Checks PDF structure, embedded XML, and XMP content · `validator/src/main/java/org/mustangproject/validator/PDFValidator.java`
- [ZUGFeRD Validator](https://github.com/zugferd/mustangproject/blob/master/validator/src/main/java/org/mustangproject/validator/ZUGFeRDValidator.java): combined validation · Coordinates XML, PDF, and rule checks into one result · `validator/src/main/java/org/mustangproject/validator/ZUGFeRDValidator.java`
- [Rule Assets](https://github.com/zugferd/mustangproject/blob/master/validator/src/main/resources/schematron/ZF_240/FACTUR-X_EN16931.sch): schemas/schematron/xslt · Offline schemas, schematron files, and compiled XSLT rule base · `validator/src/main/resources/schematron/ZF_240/FACTUR-X_EN16931.sch`

### CLI

Command-line batch workflow over files

- [Main](https://github.com/zugferd/mustangproject/blob/master/Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java): cli entrypoint · Command-line entry point for file-oriented processing · `Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java`
- [File Walker](https://github.com/zugferd/mustangproject/blob/master/Mustang-CLI/src/main/java/org/mustangproject/commandline/FileTraverser.java): directory traversal · Traverses files and directories to find invoice inputs · `Mustang-CLI/src/main/java/org/mustangproject/commandline/FileTraverser.java`
- [File Check](https://github.com/zugferd/mustangproject/blob/master/Mustang-CLI/src/main/java/org/mustangproject/commandline/FileChecker.java): batch validation · Checks individual files and aggregates validation outcomes · `Mustang-CLI/src/main/java/org/mustangproject/commandline/FileChecker.java`
- [Stats Run](https://github.com/zugferd/mustangproject/blob/master/Mustang-CLI/src/main/java/org/mustangproject/commandline/StatRun.java): reporting · Produces validation and statistics output for batch runs · `Mustang-CLI/src/main/java/org/mustangproject/commandline/StatRun.java`

## Connections

- Root POM → Invoice Model: builds · Aggregates the core library module
- Root POM → Validation API: builds · Aggregates the validator module
- Root POM → Main: builds · Aggregates the CLI module
- Invoice Model → Export Contracts: implements · Domain objects satisfy exportable interfaces
- Invoice Model → Calculation Core: uses · Invoice totals and arithmetic are computed from the model
- Export Contracts → Exporters: feeds · Exporters consume the transaction contracts
- Calculation Core → Exporters: feeds · Computed amounts are serialized into output formats
- Profiles → Exporters: selects · Profiles steer which exporter/profile variant is used
- Format Adapters → Exporters: specializes · Format-specific adapters implement export paths
- Format Adapters → Importers: specializes · Format-specific adapters implement import paths
- Importers → Invoice Model: populates · Imported XML/PDF content becomes invoice objects
- Exporters → Stylesheets: renders with · Exports and visualizations rely on stylesheet assets
- Exporters → PDF Metadata: embeds · Exports write invoice metadata into PDF/XMP structures
- PDF Metadata → Runtime Assets: uses · PDF output depends on runtime rendering assets
- ZUGFeRD Validator → XML Validator: includes · Combined validation delegates to XML checks
- ZUGFeRD Validator → PDF Validator: includes · Combined validation delegates to PDF checks
- XML Validator → Rule Assets: loads · XML validation uses schemas and schematron-derived rules
- PDF Validator → Rule Assets: loads · PDF validation uses embedded rule and schema assets
- Main → File Walker: orchestrates · The entry point starts directory traversal
- File Walker → File Check: invokes · Traversed files are passed to file checking
- File Check → ZUGFeRD Validator: validates · CLI checks files through the validator subsystem
- File Check → Stats Run: reports to · Validation outcomes feed statistics and summary output
