# tahahssn/sanitizepy architecture

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

- Interactive diagram: https://gitdiagram.com/tahahssn/sanitizepy
- Repository: https://github.com/tahahssn/sanitizepy

## Overview

#### Purpose and Entry Points
`sanitizepy` is a Python 3.11+ library for pandas dataset inspection, explainable cleaning, feature preprocessing, validation, reporting, and workflow orchestration. Primary public entry points are `Cleaner` plus module-level `inspect`, `plan`, and `clean` conveniences in `src/sanitizepy/__init__.py` and `src/sanitizepy/api.py`. `src/sanitizepy/core.py` coordinates the high-level Detect → Explain → Recommend → Preview → Apply → Validate → Audit flow.

#### Core Facade and Configuration
`Cleaner` owns the user-facing lifecycle: inspect a DataFrame, derive a cleaning plan from results, and execute it in dry-run or apply mode. Shared configuration, constants, type definitions, and domain exceptions establish common behavior across engines.
- `src/sanitizepy/core.py`
- `src/sanitizepy/config.py`
- `src/sanitizepy/types.py`

#### Read-Only Inspection and Health Modeling
Inspection is deliberately separated from mutation. Specialized inspectors analyze missingness, duplicates, dtypes, memory, and statistics; their outputs feed dataset-health evaluation and structured inspection models. This boundary makes diagnosis reproducible before a cleaning plan is generated.
- `src/sanitizepy/inspection/health.py`
- `src/sanitizepy/inspection/detector.py`
- `src/sanitizepy/models/inspection.py`

#### Recommendations, Rules, and Planning
Issue detection and the rules subsystem classify findings by category and severity, then produce explainable recommendations. A `CleaningPlan` represents the previewable, user-adjustable bridge between recommendations and executable operations; steps can be enabled or disabled before changes occur.
- `src/sanitizepy/models/recommendations.py`
- `src/sanitizepy/rules/engine.py`
- `src/sanitizepy/cleaning/plan.py`

#### Deterministic Cleaning and Audit Boundary
The cleaning engine applies operations such as missing-value handling, duplicate removal, and column removal to pandas DataFrames. Execution supports dry runs, impact/result capture, and immutable/serializable audit information, separating proposed or simulated changes from applied transformations.
- `src/sanitizepy/cleaning/engine.py`
- `src/sanitizepy/cleaning/operations.py`
- `src/sanitizepy/cleaning/base.py`

#### Stateful Preprocessing
Feature engineering is a parallel transformation subsystem rather than part of the cleaning-plan path. Its operations use fit/transform semantics for interactions, ratios, polynomial, logarithmic, and datetime-derived features while preserving DataFrame index behavior.
- `src/sanitizepy/preprocessing/engine.py`
- `src/sanitizepy/preprocessing/operations.py`
- `src/sanitizepy/preprocessing/base.py`

#### Reports and Pipeline Orchestration
Report models are rendered as text or JSON and exported to strings or files. The pipeline engine sequences callable or transform steps, recording duration and dataset-shape metadata; it can compose inspection, cleaning, preprocessing, or user-defined stages without requiring a server runtime.
- `src/sanitizepy/reports/engine.py`
- `src/sanitizepy/reports/renderers.py`
- `src/sanitizepy/pipeline/engine.py`

#### Runtime and External Boundaries
The runtime is local, in-process Python over pandas DataFrames. Material dependencies are pandas and NumPy for tabular/numerical work, SciPy for statistical capabilities, Pydantic for structured models, and Rich for terminal presentation. The repository exposes no database, web service, queue, or cloud infrastructure boundary; distribution is through PyPI and automation is defined in `.github/workflows/ci.yml` and `.github/workflows/release.yml`.

Main entry points: [`src/sanitizepy/core.py`](https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/core.py) (Cleaner facade), [`src/sanitizepy/cleaning/engine.py`](https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/cleaning/engine.py) (Cleaning engine), [`src/sanitizepy/preprocessing/engine.py`](https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/preprocessing/engine.py) (Preprocessing engine), [`src/sanitizepy/pipeline/engine.py`](https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/pipeline/engine.py) (Pipeline engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public["Public API"]
  node_api["Convenience API<br/>public entry points<br/>[api.py]"]
  node_core["Cleaner facade<br/>lifecycle coordinator<br/>[core.py]"]
  node_config["Shared config &amp; types<br/>domain contracts<br/>[config.py]"]
end

subgraph group_inspection["Inspection &amp; Planning"]
  node_detector["Specialized detectors<br/>inspection engine<br/>[detector.py]"]
  node_health["Dataset health<br/>health evaluator<br/>[health.py]"]
  node_inspection_models["Inspection models<br/>structured results<br/>[inspection.py]"]
  node_rules["Rules engine<br/>recommendation classifier<br/>[engine.py]"]
  node_recommendations["Recommendations<br/>explainable findings<br/>[recommendations.py]"]
  node_plan["Cleaning plan<br/>adjustable execution plan<br/>[plan.py]"]
end

subgraph group_cleaning["Cleaning"]
  node_cleaning_engine["Cleaning engine<br/>plan executor<br/>[engine.py]"]
  node_cleaning_operations["Cleaning operations<br/>DataFrame mutations<br/>[operations.py]"]
  node_cleaning_base["Cleaning audit contracts<br/>execution base<br/>[base.py]"]
end

subgraph group_extensions["Transforms &amp; Delivery"]
  node_preprocessing_engine["Preprocessing engine<br/>stateful transformer<br/>[engine.py]"]
  node_preprocessing_operations["Feature operations<br/>feature transforms<br/>[operations.py]"]
  node_preprocessing_base["Transform contracts<br/>fit/transform base<br/>[base.py]"]
  node_pipeline["Pipeline engine<br/>workflow orchestrator<br/>[engine.py]"]
  node_reports["Report engine<br/>report exporter<br/>[engine.py]"]
  node_renderers["Text &amp; JSON renderers<br/>report formats<br/>[renderers.py]"]
end

node_runtime{{"Local Python runtime<br/>dependency boundary"}}

node_api -->|"delegates to"| node_core
node_core -->|"uses"| node_config
node_core -->|"inspect"| node_detector
node_detector -->|"findings feed"| node_health
node_detector -->|"produces"| node_inspection_models
node_health -->|"records"| node_inspection_models
node_core -->|"explains findings"| node_rules
node_inspection_models -->|"input"| node_rules
node_rules -->|"produces"| node_recommendations
node_recommendations -->|"becomes"| node_plan
node_core -->|"derives and previews"| node_plan
node_plan -->|"executes"| node_cleaning_engine
node_cleaning_engine -->|"applies"| node_cleaning_operations
node_cleaning_engine -->|"captures audit"| node_cleaning_base
node_preprocessing_engine -->|"runs"| node_preprocessing_operations
node_preprocessing_engine -->|"uses contracts"| node_preprocessing_base
node_pipeline -.->|"can compose"| node_core
node_pipeline -.->|"can stage"| node_cleaning_engine
node_pipeline -.->|"can stage"| node_preprocessing_engine
node_reports -->|"renders through"| node_renderers
node_core -.->|"reports results"| node_reports
node_runtime -->|"pandas DataFrames"| node_core
node_runtime -->|"tabular runtime"| node_cleaning_engine
node_runtime -->|"tabular runtime"| node_preprocessing_engine

click node_api "https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/api.py"
click node_core "https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/core.py"
click node_config "https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/config.py"
click node_detector "https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/inspection/detector.py"
click node_health "https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/inspection/health.py"
click node_inspection_models "https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/models/inspection.py"
click node_rules "https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/rules/engine.py"
click node_recommendations "https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/models/recommendations.py"
click node_plan "https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/cleaning/plan.py"
click node_cleaning_engine "https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/cleaning/engine.py"
click node_cleaning_operations "https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/cleaning/operations.py"
click node_cleaning_base "https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/cleaning/base.py"
click node_preprocessing_engine "https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/preprocessing/engine.py"
click node_preprocessing_operations "https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/preprocessing/operations.py"
click node_preprocessing_base "https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/preprocessing/base.py"
click node_pipeline "https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/pipeline/engine.py"
click node_reports "https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/reports/engine.py"
click node_renderers "https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/reports/renderers.py"

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_api,node_core,node_config toneBlue
class node_detector,node_health,node_inspection_models,node_rules,node_recommendations,node_plan toneAmber
class node_cleaning_engine,node_cleaning_operations,node_cleaning_base toneMint
class node_preprocessing_engine,node_preprocessing_operations,node_preprocessing_base,node_pipeline,node_reports,node_renderers toneRose
class node_runtime toneNeutral
```

## Components

### Public API

- [Convenience API](https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/api.py): public entry points · Module-level inspect, plan, and clean helpers. · `src/sanitizepy/api.py`
- [Cleaner facade](https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/core.py): lifecycle coordinator · Coordinates detect through audit. · `src/sanitizepy/core.py`
- [Shared config & types](https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/config.py): domain contracts · `src/sanitizepy/config.py`

### Inspection & Planning

- [Specialized detectors](https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/inspection/detector.py): inspection engine · Analyzes missingness, duplicates, dtypes, memory, and statistics. · `src/sanitizepy/inspection/detector.py`
- [Dataset health](https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/inspection/health.py): health evaluator · `src/sanitizepy/inspection/health.py`
- [Inspection models](https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/models/inspection.py): structured results · `src/sanitizepy/models/inspection.py`
- [Rules engine](https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/rules/engine.py): recommendation classifier · Classifies findings by category and severity. · `src/sanitizepy/rules/engine.py`
- [Recommendations](https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/models/recommendations.py): explainable findings · `src/sanitizepy/models/recommendations.py`
- [Cleaning plan](https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/cleaning/plan.py): adjustable execution plan · Steps can be enabled or disabled before execution. · `src/sanitizepy/cleaning/plan.py`

### Cleaning

- [Cleaning engine](https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/cleaning/engine.py): plan executor · Supports dry runs, impacts, results, and applied changes. · `src/sanitizepy/cleaning/engine.py`
- [Cleaning operations](https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/cleaning/operations.py): DataFrame mutations · Handles missing values, duplicates, and column removal. · `src/sanitizepy/cleaning/operations.py`
- [Cleaning audit contracts](https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/cleaning/base.py): execution base · Defines serializable audit and operation contracts. · `src/sanitizepy/cleaning/base.py`

### Transforms & Delivery

- [Preprocessing engine](https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/preprocessing/engine.py): stateful transformer · Runs fit/transform feature workflows independently of cleaning plans. · `src/sanitizepy/preprocessing/engine.py`
- [Feature operations](https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/preprocessing/operations.py): feature transforms · Interactions, ratios, polynomial, log, and datetime features. · `src/sanitizepy/preprocessing/operations.py`
- [Transform contracts](https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/preprocessing/base.py): fit/transform base · Preserves DataFrame index behavior. · `src/sanitizepy/preprocessing/base.py`
- [Pipeline engine](https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/pipeline/engine.py): workflow orchestrator · Sequences callable or transform stages with timing and shape metadata. · `src/sanitizepy/pipeline/engine.py`
- [Report engine](https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/reports/engine.py): report exporter · Exports report models to strings or files. · `src/sanitizepy/reports/engine.py`
- [Text & JSON renderers](https://github.com/tahahssn/sanitizepy/blob/main/src/sanitizepy/reports/renderers.py): report formats · `src/sanitizepy/reports/renderers.py`

### Other components

- **Local Python runtime**: dependency boundary · In-process pandas/NumPy execution; SciPy, Pydantic, and Rich support statistics, models, and presentation.

## Connections

- Convenience API → Cleaner facade: delegates to
- Cleaner facade → Shared config & types: uses
- Cleaner facade → Specialized detectors: inspect
- Specialized detectors → Dataset health: findings feed
- Specialized detectors → Inspection models: produces
- Dataset health → Inspection models: records
- Cleaner facade → Rules engine: explains findings
- Inspection models → Rules engine: input
- Rules engine → Recommendations: produces
- Recommendations → Cleaning plan: becomes
- Cleaner facade → Cleaning plan: derives and previews
- Cleaning plan → Cleaning engine: executes
- Cleaning engine → Cleaning operations: applies
- Cleaning engine → Cleaning audit contracts: captures audit
- Preprocessing engine → Feature operations: runs
- Preprocessing engine → Transform contracts: uses contracts
- Pipeline engine → Cleaner facade: can compose
- Pipeline engine → Cleaning engine: can stage
- Pipeline engine → Preprocessing engine: can stage
- Report engine → Text & JSON renderers: renders through
- Cleaner facade → Report engine: reports results
- Local Python runtime → Cleaner facade: pandas DataFrames
- Local Python runtime → Cleaning engine: tabular runtime
- Local Python runtime → Preprocessing engine: tabular runtime
