# nics-tw/petsard architecture

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

- Interactive diagram: https://gitdiagram.com/nics-tw/petsard
- Repository: https://github.com/nics-tw/petsard

## Overview

#### Purpose and entry points
PETsARD is a Python 3.10/3.11 library for configurable tabular synthetic-data generation, constraint handling, and fidelity/utility/privacy evaluation. Primary entry points are the programmatic workflow API in `petsard/executor.py` and YAML-driven executions illustrated by `demo/getting-started/default-synthesis-default-evaluation.yaml`. Public package exports begin at `petsard/__init__.py`.

#### Workflow orchestration and configuration
`Executor` coordinates configured stages, tracks completion, results, inferred schema, and timing. Configuration parsing and object construction are centralized in `petsard/config.py` and `petsard/config_base.py`; YAML represents the pipeline boundary, while Python APIs provide direct composition. The documented execution model is depth-first, allowing multiple experiments/stages from one configuration.
Paths: `petsard/executor.py`, `petsard/config.py`, `demo/petsard-yaml/synthesizer-yaml/multiple-experiments.yaml`.

#### Data ingestion, splitting, and schema
Loaders turn local/tabular or benchmark inputs into the internal data flow; benchmark support includes a catalog and downloader. Splitters create controlled or non-overlapping subsets for synthesis/evaluation. The metadater layer infers, stores, aligns, and compares schema/statistical metadata, forming the contract between raw data, transforms, synthesizers, and evaluators.
Paths: `petsard/loader/loader.py`, `petsard/loader/benchmarker.py`, `petsard/metadater/metadater.py`, `petsard/metadater/schema_inferencer.py`.

#### Transformation pipeline
The processor subsystem provides fit/transform/inverse-transform stages for missing values, outliers, discretization, encoding, scaling, and schema transformation. `mediator.py` and `registry.py` indicate a composable processor/registration boundary: preprocessors adapt source data for model training, and postprocessors restore generated data to the expected schema/domain.
Paths: `petsard/processor/base.py`, `petsard/processor/mediator.py`, `petsard/processor/schema_transform.py`.

#### Synthesis and extensibility
The synthesizer abstraction separates common create/fit/sample lifecycle from implementations. Included engines are PETsARD Gaussian Copula and SDV-backed synthesis; custom synthesis is supported. Adapters provide a higher-level integration boundary across pipeline roles, and external Python modules can be referenced by YAML demos.
Paths: `petsard/synthesizer/synthesizer_base.py`, `petsard/synthesizer/petsard_gaussian_copula.py`, `petsard/synthesizer/sdv.py`, `petsard/adapter.py`.

#### Constraints, evaluation, and outputs
Constrainers validate generated records or resample until field, field-combination, proportion, and NaN-group rules are satisfied. Evaluators produce diagnostic/fidelity metrics, ML utility measurements, and privacy-risk metrics via integrations named for SDMetrics, Anonymeter, and MPUCCS. Reporters persist generated data, schemas, timing, validation results, and reports.
Paths: `petsard/constrainer/constrainer.py`, `petsard/evaluator/evaluator.py`, `petsard/evaluator/anonymeter.py`, `petsard/reporter/reporter.py`.

#### Runtime and delivery boundaries
The core runtime is a Python package distributed through PyPI and runnable in Docker/Compose. CI publishes images and PyPI releases and performs vulnerability/SBOM workflows. Documentation is a separate Hugo/Go site, published through GitHub Pages. External services/material dependencies include PyPI, Docker, GitHub Actions/Pages, benchmark-data retrieval, SDV, SDMetrics, Anonymeter, and MPUCCS.
Paths: `pyproject.toml`, `Dockerfile`, `compose.yml`, `.github/workflows/semantic-release-pypi.yml`.

Main entry points: [`petsard/synthesizer/synthesizer_base.py`](https://github.com/nics-tw/petsard/blob/dev/petsard/synthesizer/synthesizer_base.py) (Synthesizer abstraction), [`petsard/processor/mediator.py`](https://github.com/nics-tw/petsard/blob/dev/petsard/processor/mediator.py) (Processor mediator), [`petsard/executor.py`](https://github.com/nics-tw/petsard/blob/dev/petsard/executor.py) (Executor), [`petsard/loader/loader.py`](https://github.com/nics-tw/petsard/blob/dev/petsard/loader/loader.py) (Loaders)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_orchestration["Workflow"]
  node_public_api["Public package API<br/>Python package<br/>[__init__.py]"]
  node_yaml_workflow["YAML workflow<br/>pipeline config"]
  node_executor["Executor<br/>workflow runtime<br/>[executor.py]"]
  node_config["Configuration builder<br/>config parser<br/>[config.py]"]
end

subgraph group_data["Data &amp; Schema"]
  node_loader["Loaders<br/>data ingestion<br/>[loader.py]"]
  node_benchmark[("Benchmark catalog<br/>data retrieval<br/>[benchmarker.py]")]
  node_metadater["Metadata contract<br/>schema metadata<br/>[metadater.py]"]
  node_schema_inference["Schema inference<br/>metadata inference"]
end

subgraph group_generation["Generation"]
  node_processor_base["Processor pipeline<br/>transform lifecycle<br/>[base.py]"]
  node_processor_mediator["Processor mediator<br/>processor composition<br/>[mediator.py]"]
  node_schema_transform["Schema transform<br/>processor"]
  node_synth_base["Synthesizer abstraction<br/>generation lifecycle"]
  node_gaussian_copula["Gaussian Copula<br/>synthesis engine"]
  node_sdv_synth["SDV synthesizer<br/>external adapter<br/>[sdv.py]"]
  node_adapter["Pipeline adapters<br/>integration boundary<br/>[adapter.py]"]
  node_constrainer["Constrainer<br/>record validation<br/>[constrainer.py]"]
end

subgraph group_assessment["Assessment &amp; Output"]
  node_evaluator["Evaluator<br/>metrics runtime<br/>[evaluator.py]"]
  node_anonymeter["Anonymeter metrics<br/>privacy integration<br/>[anonymeter.py]"]
  node_reporter["Reporter<br/>artifact persistence<br/>[reporter.py]"]
end

subgraph group_delivery["Delivery"]
  node_package_release["PyPI release<br/>package delivery<br/>[pyproject.toml]"]
  node_docker_runtime["Docker runtime<br/>container delivery"]
  node_release_ci["Release CI<br/>GitHub Actions"]
end

node_public_api -->|"starts"| node_executor
node_yaml_workflow -->|"defines"| node_config
node_config -->|"constructs stages for"| node_executor
node_executor -->|"loads source data"| node_loader
node_loader -->|"retrieves benchmarks via"| node_benchmark
node_loader -->|"provides data"| node_schema_inference
node_schema_inference -->|"creates metadata"| node_metadater
node_metadater -->|"guides transforms"| node_processor_mediator
node_processor_mediator -->|"orchestrates"| node_processor_base
node_processor_mediator -->|"applies"| node_schema_transform
node_processor_mediator -->|"preprocessed training data"| node_synth_base
node_synth_base -->|"implemented by"| node_gaussian_copula
node_synth_base -->|"implemented by"| node_sdv_synth
node_adapter -.->|"extends"| node_synth_base
node_synth_base -->|"generated samples"| node_constrainer
node_constrainer -->|"validated synthetic data"| node_evaluator
node_evaluator -->|"privacy metrics"| node_anonymeter
node_evaluator -->|"evaluation reports"| node_reporter
node_constrainer -->|"validation results"| node_reporter
node_executor -->|"data, schema, and timing"| node_reporter
node_package_release -.->|"packages runtime"| node_docker_runtime
node_release_ci -->|"publishes"| node_package_release
node_release_ci -->|"publishes image"| node_docker_runtime

click node_public_api "https://github.com/nics-tw/petsard/blob/dev/petsard/__init__.py"
click node_yaml_workflow "https://github.com/nics-tw/petsard/blob/dev/demo/petsard-yaml/synthesizer-yaml/multiple-experiments.yaml"
click node_executor "https://github.com/nics-tw/petsard/blob/dev/petsard/executor.py"
click node_config "https://github.com/nics-tw/petsard/blob/dev/petsard/config.py"
click node_loader "https://github.com/nics-tw/petsard/blob/dev/petsard/loader/loader.py"
click node_benchmark "https://github.com/nics-tw/petsard/blob/dev/petsard/loader/benchmarker.py"
click node_metadater "https://github.com/nics-tw/petsard/blob/dev/petsard/metadater/metadater.py"
click node_schema_inference "https://github.com/nics-tw/petsard/blob/dev/petsard/metadater/schema_inferencer.py"
click node_processor_base "https://github.com/nics-tw/petsard/blob/dev/petsard/processor/base.py"
click node_processor_mediator "https://github.com/nics-tw/petsard/blob/dev/petsard/processor/mediator.py"
click node_schema_transform "https://github.com/nics-tw/petsard/blob/dev/petsard/processor/schema_transform.py"
click node_synth_base "https://github.com/nics-tw/petsard/blob/dev/petsard/synthesizer/synthesizer_base.py"
click node_gaussian_copula "https://github.com/nics-tw/petsard/blob/dev/petsard/synthesizer/petsard_gaussian_copula.py"
click node_sdv_synth "https://github.com/nics-tw/petsard/blob/dev/petsard/synthesizer/sdv.py"
click node_adapter "https://github.com/nics-tw/petsard/blob/dev/petsard/adapter.py"
click node_constrainer "https://github.com/nics-tw/petsard/blob/dev/petsard/constrainer/constrainer.py"
click node_evaluator "https://github.com/nics-tw/petsard/blob/dev/petsard/evaluator/evaluator.py"
click node_anonymeter "https://github.com/nics-tw/petsard/blob/dev/petsard/evaluator/anonymeter.py"
click node_reporter "https://github.com/nics-tw/petsard/blob/dev/petsard/reporter/reporter.py"
click node_package_release "https://github.com/nics-tw/petsard/blob/dev/pyproject.toml"
click node_docker_runtime "https://github.com/nics-tw/petsard/blob/dev/Dockerfile"
click node_release_ci "https://github.com/nics-tw/petsard/blob/dev/.github/workflows/semantic-release-pypi.yml"

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_public_api,node_yaml_workflow,node_executor,node_config toneBlue
class node_loader,node_benchmark,node_metadater,node_schema_inference toneAmber
class node_processor_base,node_processor_mediator,node_schema_transform,node_synth_base,node_gaussian_copula,node_sdv_synth,node_adapter,node_constrainer toneMint
class node_evaluator,node_anonymeter,node_reporter toneRose
class node_package_release,node_docker_runtime,node_release_ci toneIndigo
```

## Components

### Workflow

Configured execution and pipeline composition.

- [Public package API](https://github.com/nics-tw/petsard/blob/dev/petsard/__init__.py): Python package · `petsard/__init__.py`
- [YAML workflow](https://github.com/nics-tw/petsard/blob/dev/demo/petsard-yaml/synthesizer-yaml/multiple-experiments.yaml): pipeline config · Supports multiple configured experiments. · `demo/petsard-yaml/synthesizer-yaml/multiple-experiments.yaml`
- [Executor](https://github.com/nics-tw/petsard/blob/dev/petsard/executor.py): workflow runtime · Coordinates depth-first stages, results, schema, and timing. · `petsard/executor.py`
- [Configuration builder](https://github.com/nics-tw/petsard/blob/dev/petsard/config.py): config parser · Parses configuration and constructs pipeline objects. · `petsard/config.py`

### Data & Schema

Input preparation and metadata contract.

- [Loaders](https://github.com/nics-tw/petsard/blob/dev/petsard/loader/loader.py): data ingestion · Loads local/tabular and benchmark inputs. · `petsard/loader/loader.py`
- [Benchmark catalog](https://github.com/nics-tw/petsard/blob/dev/petsard/loader/benchmarker.py): data retrieval · Catalogs and downloads benchmark datasets. · `petsard/loader/benchmarker.py`
- [Metadata contract](https://github.com/nics-tw/petsard/blob/dev/petsard/metadater/metadater.py): schema metadata · Stores, aligns, and compares schema and statistics. · `petsard/metadater/metadater.py`
- [Schema inference](https://github.com/nics-tw/petsard/blob/dev/petsard/metadater/schema_inferencer.py): metadata inference · `petsard/metadater/schema_inferencer.py`

### Generation

Transformation, synthesis, and constraints.

- [Processor pipeline](https://github.com/nics-tw/petsard/blob/dev/petsard/processor/base.py): transform lifecycle · Fit, transform, and inverse-transform contract. · `petsard/processor/base.py`
- [Processor mediator](https://github.com/nics-tw/petsard/blob/dev/petsard/processor/mediator.py): processor composition · Composes registered pre- and post-processing stages. · `petsard/processor/mediator.py`
- [Schema transform](https://github.com/nics-tw/petsard/blob/dev/petsard/processor/schema_transform.py): processor · Adapts data to the model-facing schema. · `petsard/processor/schema_transform.py`
- [Synthesizer abstraction](https://github.com/nics-tw/petsard/blob/dev/petsard/synthesizer/synthesizer_base.py): generation lifecycle · Common create, fit, and sample contract. · `petsard/synthesizer/synthesizer_base.py`
- [Gaussian Copula](https://github.com/nics-tw/petsard/blob/dev/petsard/synthesizer/petsard_gaussian_copula.py): synthesis engine · `petsard/synthesizer/petsard_gaussian_copula.py`
- [SDV synthesizer](https://github.com/nics-tw/petsard/blob/dev/petsard/synthesizer/sdv.py): external adapter · SDV-backed synthesis implementation. · `petsard/synthesizer/sdv.py`
- [Pipeline adapters](https://github.com/nics-tw/petsard/blob/dev/petsard/adapter.py): integration boundary · Integrates custom roles and external Python modules. · `petsard/adapter.py`
- [Constrainer](https://github.com/nics-tw/petsard/blob/dev/petsard/constrainer/constrainer.py): record validation · Validates or resamples generated records against rules. · `petsard/constrainer/constrainer.py`

### Assessment & Output

Evaluation and persisted artifacts.

- [Evaluator](https://github.com/nics-tw/petsard/blob/dev/petsard/evaluator/evaluator.py): metrics runtime · Runs fidelity, utility, and privacy assessments. · `petsard/evaluator/evaluator.py`
- [Anonymeter metrics](https://github.com/nics-tw/petsard/blob/dev/petsard/evaluator/anonymeter.py): privacy integration · `petsard/evaluator/anonymeter.py`
- [Reporter](https://github.com/nics-tw/petsard/blob/dev/petsard/reporter/reporter.py): artifact persistence · Writes data, schemas, timing, validation, and reports. · `petsard/reporter/reporter.py`

### Delivery

Packaging, containers, and release automation.

- [PyPI release](https://github.com/nics-tw/petsard/blob/dev/pyproject.toml): package delivery · Python distribution and release workflow. · `pyproject.toml`
- [Docker runtime](https://github.com/nics-tw/petsard/blob/dev/Dockerfile): container delivery · Containerized package execution. · `Dockerfile`
- [Release CI](https://github.com/nics-tw/petsard/blob/dev/.github/workflows/semantic-release-pypi.yml): GitHub Actions · Publishes PyPI releases and images. · `.github/workflows/semantic-release-pypi.yml`

## Connections

- Public package API → Executor: starts
- YAML workflow → Configuration builder: defines
- Configuration builder → Executor: constructs stages for
- Executor → Loaders: loads source data
- Loaders → Benchmark catalog: retrieves benchmarks via
- Loaders → Schema inference: provides data
- Schema inference → Metadata contract: creates metadata
- Metadata contract → Processor mediator: guides transforms
- Processor mediator → Processor pipeline: orchestrates
- Processor mediator → Schema transform: applies
- Processor mediator → Synthesizer abstraction: preprocessed training data
- Synthesizer abstraction → Gaussian Copula: implemented by
- Synthesizer abstraction → SDV synthesizer: implemented by
- Pipeline adapters → Synthesizer abstraction: extends
- Synthesizer abstraction → Constrainer: generated samples
- Constrainer → Evaluator: validated synthetic data
- Evaluator → Anonymeter metrics: privacy metrics
- Evaluator → Reporter: evaluation reports
- Constrainer → Reporter: validation results
- Executor → Reporter: data, schema, and timing
- PyPI release → Docker runtime: packages runtime
- Release CI → PyPI release: publishes
- Release CI → Docker runtime: publishes image
