# gannettdigital/data-diff architecture

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

- Interactive diagram: https://gitdiagram.com/gannettdigital/data-diff
- Repository: https://github.com/gannettdigital/data-diff

## Overview

##### Main Components
- CLI Entry Point: At the very top is the executable layer (mainly represented by data_diff/__main__.py). This is where the command line interface receives user arguments, configuration files (like the TOML file for the job configuration), and kicks off the diffing process.
- Configuration & Environment: The configuration module (data_diff/config.py, and support via TOML files) shows how database connection details and run parameters are provided. Illustrate how configuration and environment variables feed into the system.
- Diff Engine: The core logic splits into two diffing methods:
- joindiff (for same-database or testing environments)
- hashdiff (for cross-database or large data differences)
Diff_tables.py, hashdiff_tables.py, and joindiff modules (e.g., in data_diff/joindiff_tables.py if present) to show these as central processing components.
- Abstract Base Classes (abcs): The abcs module (with compiler.py and database_types.py) defines interfaces and data type abstractions. This is critical for standardizing behavior and makes for an additional architectural layer supporting extensibility.
- Cloud Integration: The cloud directory (data_diff/cloud) and its modules (data_source.py, datafold_api.py) indicate integration points for scaling or leveraging Datafold Cloud. This should be represented as an external service component that interacts with the CLI tool.

##### Relationships and Interactions
- For projects using dbt, show a separate data flow from the dbt integration module to the diff engine, indicating that dbt artifacts (manifests, profiles, etc.) are parsed and then used to generate a diff job.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The division between data retrieval, diff computation, and external integration (cloud, dbt) should be clearly delineated.
- Extensibility: Highlight the role of abstract base classes (abcs) that allow for easy addition of new functionalities or database drivers.

##### Relevant Technologies and Frameworks
- Python-based CLI with an emphasis on stateless diffing.
- Usage of TOML configuration files for run parameters.
- Integration with external databases via standardized connection strings, as well as support for multiple database drivers.
- dbt integration for handling SQL transformation artifacts.

##### Specific Elements
- Core processing components (e.g., CLI, diff engine)
- External service components (e.g., Database Adapters, Cloud API, dbt)
- Supporting libraries/utilities (e.g., abcs, utils)
- Optionally, include a section highlighting CI/CD and testing components (from the .github and tests directories) to demonstrate overall project quality assurance support.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main Components
    CLI["CLI Entry Point"]:::cli
    CONFIG["Configuration Manager"]:::config
    DIFF["Diff Engine (General)"]:::diff
    JOINDIFF["Diff Engine – joindiff"]:::diff
    HASHDIFF["Diff Engine – hashdiff"]:::diff
    ADAPTER["Database Adapters"]:::adapter
    ABCS["Abstract Base Classes"]:::abcs
    CLOUD["Cloud Integration"]:::cloud
    DBT["dbt Integration"]:::dbt
    UTIL["Auxiliary Utilities"]:::util
    CI["CI/CD & Testing"]:::ci

    %% Data Flow & Interactions
    CLI -->|"loads"| CONFIG
    CONFIG -->|"feeds"| DIFF
    DIFF -->|"invokes"| JOINDIFF
    DIFF -->|"invokes"| HASHDIFF
    DIFF -->|"queries"| ADAPTER
    DIFF -->|"integrates"| CLOUD
    DBT -->|"provides_artifacts"| DIFF
    ABCS ---|"supports"| DIFF
    ABCS ---|"defines_interface_for"| ADAPTER
    CI ---|"ensures_quality_on"| DIFF
    CI ---|"ensures_stability_on"| ADAPTER

    %% Styling Classes
    classDef cli fill:#b3e5fc,stroke:#000,stroke-width:1px;
    classDef config fill:#c8e6c9,stroke:#000,stroke-width:1px;
    classDef diff fill:#ffccbc,stroke:#000,stroke-width:1px;
    classDef adapter fill:#ffe082,stroke:#000,stroke-width:1px;
    classDef abcs fill:#f8bbd0,stroke:#000,stroke-width:1px;
    classDef cloud fill:#fff9c4,stroke:#000,stroke-width:1px;
    classDef dbt fill:#d1c4e9,stroke:#000,stroke-width:1px;
    classDef util fill:#f0f4c3,stroke:#000,stroke-width:1px;
    classDef ci fill:#eeeeee,stroke:#000,stroke-width:1px;

    %% Click Events
    click CLI "https://github.com/gannettdigital/data-diff/blob/master/data_diff/__main__.py"
    click CONFIG "https://github.com/gannettdigital/data-diff/blob/master/data_diff/config.py"
    click JOINDIFF "https://github.com/gannettdigital/data-diff/blob/master/data_diff/joindiff_tables.py"
    click HASHDIFF "https://github.com/gannettdigital/data-diff/blob/master/data_diff/hashdiff_tables.py"
    click DIFF "https://github.com/gannettdigital/data-diff/blob/master/data_diff/diff_tables.py"
    click ADAPTER "https://github.com/gannettdigital/data-diff/tree/master/data_diff/databases"
    click ABCS "https://github.com/gannettdigital/data-diff/tree/master/data_diff/abcs"
    click CLOUD "https://github.com/gannettdigital/data-diff/tree/master/data_diff/cloud"
    click DBT "https://github.com/gannettdigital/data-diff/blob/master/data_diff/dbt.py"
    click UTIL "https://github.com/gannettdigital/data-diff/blob/master/data_diff/errors.py"
```
