How zugferd/mustangproject works
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: ZUGFeRDExporterFromA3.java Exporters · Invoice.java Invoice Model · pom.xml Root POM · FileChecker.java File Check
Components 20
Project
Maven aggregator and top-level modules
- Root POM · Aggregates the main modules and coordinates the build
pom.xml
Library
Core invoice model, conversion, and format adapters
- Invoice Model · Invoice, item, parties, totals, taxes, and related business entities
library/src/main/java/org/mustangproject/Invoice.java - Export Contracts · Exportable transaction and party/item/payment abstractions
library/src/main/java/org/mustangproject/ZUGFeRD/IExportableTransaction.java - Calculation Core · Arithmetic and invoice amount computation helpers
library/src/main/java/org/mustangproject/CalculatedInvoice.java - Profiles · Standard, profile, and version abstractions for invoice variants
library/src/main/java/org/mustangproject/ZUGFeRD/Profile.java - Exporters · Builds XML, XMP, and PDF-related invoice representations
library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA3.java - Importers · Reads invoice data back from PDF or XML sources
library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java - Format Adapters · Adapters for ZUGFeRD, Factur-X, XRechnung, UBL, and CII transformations
library/src/main/java/org/mustangproject/ZUGFeRD/XRechnungImporter.java - Stylesheets · XSLT, HTML, CSS, and JS assets for conversion and visualization
library/src/main/resources/stylesheets/ZF1ToZF2.xsl - PDF Metadata · PDF/A conformance, XMP schemas, and related embedded metadata support
library/src/main/java/org/mustangproject/ZUGFeRD/XMPSchemaZugferd.java - Runtime Assets · 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 · Shared validation result and context model
validator/src/main/java/org/mustangproject/validator/Validator.java - XML Validator · Schema-based validation for invoice XML payloads
validator/src/main/java/org/mustangproject/validator/XMLValidator.java - PDF Validator · Checks PDF structure, embedded XML, and XMP content
validator/src/main/java/org/mustangproject/validator/PDFValidator.java - ZUGFeRD Validator · Coordinates XML, PDF, and rule checks into one result
validator/src/main/java/org/mustangproject/validator/ZUGFeRDValidator.java - Rule Assets · 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 · Command-line entry point for file-oriented processing
Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java - File Walker · Traverses files and directories to find invoice inputs
Mustang-CLI/src/main/java/org/mustangproject/commandline/FileTraverser.java - File Check · Checks individual files and aggregates validation outcomes
Mustang-CLI/src/main/java/org/mustangproject/commandline/FileChecker.java - Stats Run · Produces validation and statistics output for batch runs
Mustang-CLI/src/main/java/org/mustangproject/commandline/StatRun.java
Connections 22
- 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