# ivan-kir/enterprise-data-quality-system architecture

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

- Interactive diagram: https://gitdiagram.com/ivan-kir/enterprise-data-quality-system
- Repository: https://github.com/ivan-kir/enterprise-data-quality-system

## Overview

1. **System purpose**
   This repository is an enterprise CRM data quality platform. Its core job is to ingest messy customer records, measure quality, detect duplicates, and produce consolidated “golden records” with persisted KPI history.

2. **Primary runtime surfaces**
   There are two user-facing entry points:
   - a **FastAPI API** in `app/main.py` exposed through `app/api/routes/*`
   - a separate **Streamlit dashboard** in `dashboard/app.py`
   The dashboard is read-oriented and sits on top of the same backend/data model rather than owning business logic.

3. **Request-to-domain layering**
   The backend is organized in clear layers:
   - **API routes**: HTTP endpoints, auth/token checks, request/response shapes
   - **Pipelines**: orchestration for multi-step jobs such as ingestion, quality checks, and deduplication
   - **Services**: business logic for ingestion, quality scoring, entity resolution, and golden record creation
   - **Models**: SQLAlchemy ORM entities persisted to the database
   - **Schemas**: Pydantic contracts for external API payloads
   This separation is the main architectural boundary to reflect in a diagram.

4. **Main data flow**
   The application is batch-oriented and centered around `batch_id`:
   - `POST /ingest` generates or accepts customer-like records and stores them
   - `POST /run-quality-check` loads a batch and computes data quality metrics
   - `POST /run-deduplication` runs entity resolution and creates golden records
   - `GET /metrics` and `GET /golden-records` read persisted results
   The database is the system-of-record for all downstream steps.

5. **Ingestion subsystem**
   Ingestion lives in `app/pipelines/ingestion_pipeline.py` and `app/services/ingestion_service.py`.
   The README indicates synthetic CRM data generation via utilities in `app/utils/data_generator.py`, then bulk persistence into the customer table. This is designed for repeatable demos/tests, not just raw API ingestion.

6. **Data quality subsystem**
   Quality analysis is implemented through `quality_pipeline.py` and `quality_service.py`.
   It computes multiple dimensions: completeness, uniqueness, validity, consistency, and outliers. Results are persisted in the `quality_metrics` model/table so historical quality can be queried later, not only returned in the API response.

7. **Entity resolution and deduplication subsystem**
   Deduplication is a distinct pipeline (`deduplication_pipeline.py`) backed by `entity_resolution_service.py`.
   The matching flow is:
   - blocking by exact normalized email/phone
   - fuzzy similarity for name/address, using RapidFuzz with fallback logic
   - composite thresholding to flag duplicate pairs
   - clustering with union-find to form entity groups
   This subsystem transforms many customer rows into clustered identity groups.

8. **Golden record creation**
   After clustering, `golden_record_service.py` merges each cluster into a canonical record. The merge policy is deterministic: choose the most complete base record, prefer stronger string values, keep the most recent date, and aggregate revenue. Output is persisted in the `golden_record` model/table and later exposed by `GET /golden-records`.

9. **Persistence and database boundary**
   The data layer is SQLAlchemy-based (`app/core/database.py` plus `app/models/*`). The repo supports **SQLite by default** and **PostgreSQL** via configuration. Alembic migrations are present, which means the schema is intended to evolve in a controlled way rather than being recreated ad hoc.

10. **Configuration, auth, and operational concerns**
   `app/core/config.py` centralizes environment-driven settings such as database URLs, scoring weights, logging format, and API token auth. `app/api/dependencies.py` provides shared request dependencies like DB sessions and token enforcement. Logging is treated as an infrastructure concern in `app/core/logging.py`.

11. **Utilities and validation boundaries**
   `app/utils/normalizers.py` and `app/utils/validators.py` hold reusable field cleaning and validation logic, while `data_generator.py` supports synthetic test data. These utilities are shared across ingestion, quality, and resolution, which keeps canonical normalization rules outside the service layer.

12. **Test and delivery architecture**
   The test suite is broad and maps to the system boundaries: API integration, fuzzy matching, entity resolution, quality scoring, golden records, and validators. CI in `.github/workflows/ci.yml`, Dockerfiles, and `docker-compose.yml` show the repo is designed for containerized local execution and automated validation rather than a single-script workflow.

Main entry points: [`app/api/router.py`](https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/api/router.py) (Router), [`app/models/__init__.py`](https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/models/__init__.py) (ORM models), [`app/api/dependencies.py`](https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/api/dependencies.py) (Dependencies), [`app/core/database.py`](https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/core/database.py) (Database)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["FastAPI backend"]
  node_main["API app<br/>FastAPI entry<br/>[main.py]"]
  node_api_router["Router<br/>API composition<br/>[router.py]"]
  node_api_deps["Dependencies<br/>request deps<br/>[dependencies.py]"]
  node_ingest_route["Ingest<br/>HTTP route<br/>[ingest.py]"]
  node_quality_route["Quality<br/>HTTP route<br/>[quality.py]"]
  node_dedup_route["Dedup<br/>HTTP route<br/>[deduplication.py]"]
  node_golden_route["Golden records<br/>HTTP route<br/>[golden_records.py]"]
  node_metrics_route["Metrics<br/>HTTP route<br/>[metrics.py]"]
  node_ingest_pipe["Ingestion pipeline<br/>orchestration"]
  node_quality_pipe["Quality pipeline<br/>orchestration"]
  node_dedup_pipe["Dedup pipeline<br/>orchestration"]
  node_ingest_service["Ingestion service<br/>domain service"]
  node_quality_service["Quality service<br/>domain service<br/>[quality_service.py]"]
  node_resolution_service["Resolution service<br/>domain service"]
  node_golden_service["Golden service<br/>domain service"]
end

subgraph group_data["Data layer"]
  node_models[("ORM models<br/>persistence models<br/>[__init__.py]")]
  node_schemas["API schemas<br/>contracts<br/>[__init__.py]"]
  node_database[("Database<br/>SQLAlchemy DB<br/>[database.py]")]
end

subgraph group_ops["Ops & delivery"]
  node_config["Config<br/>settings<br/>[config.py]"]
  node_logging["Logging<br/>infra<br/>[logging.py]"]
  node_migration["Migrations<br/>schema evolution<br/>[env.py]"]
end

subgraph group_ui["Dashboard"]
  node_dashboard["Dashboard<br/>Streamlit app<br/>[app.py]"]
end

node_main -->|"includes"| node_api_router
node_api_router -->|"registers"| node_ingest_route
node_api_router -->|"registers"| node_quality_route
node_api_router -->|"registers"| node_dedup_route
node_api_router -->|"registers"| node_golden_route
node_api_router -->|"registers"| node_metrics_route
node_ingest_route -->|"uses"| node_api_deps
node_quality_route -->|"uses"| node_api_deps
node_dedup_route -->|"uses"| node_api_deps
node_ingest_route -->|"starts"| node_ingest_pipe
node_quality_route -->|"starts"| node_quality_pipe
node_dedup_route -->|"starts"| node_dedup_pipe
node_ingest_pipe -->|"orchestrates"| node_ingest_service
node_quality_pipe -->|"orchestrates"| node_quality_service
node_dedup_pipe -->|"orchestrates"| node_resolution_service
node_dedup_pipe -->|"orchestrates"| node_golden_service
node_ingest_service -->|"persists"| node_models
node_quality_service -->|"persists"| node_models
node_golden_service -->|"persists"| node_models
node_models -->|"uses"| node_database
node_schemas -->|"shapes"| node_api_router
node_config -->|"configures"| node_database
node_config -->|"configures"| node_api_deps
node_logging -->|"informs"| node_main
node_migration -->|"evolves"| node_database
node_dashboard -->|"reads"| node_database
node_dashboard -->|"follows"| node_schemas

click node_main "https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/main.py"
click node_api_router "https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/api/router.py"
click node_api_deps "https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/api/dependencies.py"
click node_ingest_route "https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/api/routes/ingest.py"
click node_quality_route "https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/api/routes/quality.py"
click node_dedup_route "https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/api/routes/deduplication.py"
click node_golden_route "https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/api/routes/golden_records.py"
click node_metrics_route "https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/api/routes/metrics.py"
click node_ingest_pipe "https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/pipelines/ingestion_pipeline.py"
click node_quality_pipe "https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/pipelines/quality_pipeline.py"
click node_dedup_pipe "https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/pipelines/deduplication_pipeline.py"
click node_ingest_service "https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/services/ingestion_service.py"
click node_quality_service "https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/services/quality_service.py"
click node_resolution_service "https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/services/entity_resolution_service.py"
click node_golden_service "https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/services/golden_record_service.py"
click node_models "https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/models/__init__.py"
click node_schemas "https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/schemas/__init__.py"
click node_database "https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/core/database.py"
click node_config "https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/core/config.py"
click node_logging "https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/core/logging.py"
click node_migration "https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/alembic/env.py"
click node_dashboard "https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/dashboard/app.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_main,node_api_router,node_api_deps,node_ingest_route,node_quality_route,node_dedup_route,node_golden_route,node_metrics_route,node_ingest_pipe,node_quality_pipe,node_dedup_pipe,node_ingest_service,node_quality_service,node_resolution_service,node_golden_service toneBlue
class node_models,node_schemas,node_database toneAmber
class node_config,node_logging,node_migration toneMint
class node_dashboard toneRose
```

## Components

### FastAPI backend

HTTP API, orchestration pipelines, and domain services.

- [API app](https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/main.py): FastAPI entry · Application bootstrap and server entry point. · `app/main.py`
- [Router](https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/api/router.py): API composition · Wires route modules into the FastAPI application. · `app/api/router.py`
- [Dependencies](https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/api/dependencies.py): request deps · Shared request/session/auth dependencies for API routes. · `app/api/dependencies.py`
- [Ingest](https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/api/routes/ingest.py): HTTP route · Batch ingestion endpoint and request handling. · `app/api/routes/ingest.py`
- [Quality](https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/api/routes/quality.py): HTTP route · Quality check endpoint for batch metrics. · `app/api/routes/quality.py`
- [Dedup](https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/api/routes/deduplication.py): HTTP route · Deduplication endpoint for entity resolution jobs. · `app/api/routes/deduplication.py`
- [Golden records](https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/api/routes/golden_records.py): HTTP route · Read endpoint for consolidated canonical records. · `app/api/routes/golden_records.py`
- [Metrics](https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/api/routes/metrics.py): HTTP route · Read endpoint for persisted quality metrics. · `app/api/routes/metrics.py`
- [Ingestion pipeline](https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/pipelines/ingestion_pipeline.py): orchestration · Coordinates record generation, normalization, and persistence. · `app/pipelines/ingestion_pipeline.py`
- [Quality pipeline](https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/pipelines/quality_pipeline.py): orchestration · Runs batch quality analysis and stores results. · `app/pipelines/quality_pipeline.py`
- [Dedup pipeline](https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/pipelines/deduplication_pipeline.py): orchestration · Coordinates blocking, matching, clustering, and record merging. · `app/pipelines/deduplication_pipeline.py`
- [Ingestion service](https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/services/ingestion_service.py): domain service · Builds and persists customer batches, including synthetic demo data. · `app/services/ingestion_service.py`
- [Quality service](https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/services/quality_service.py): domain service · Computes completeness, uniqueness, validity, consistency, and outlier metrics. · `app/services/quality_service.py`
- [Resolution service](https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/services/entity_resolution_service.py): domain service · Performs blocking, fuzzy matching, thresholding, and clustering. · `app/services/entity_resolution_service.py`
- [Golden service](https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/services/golden_record_service.py): domain service · Merges clusters into deterministic canonical records. · `app/services/golden_record_service.py`

### Data layer

ORM models, schemas, and database boundary.

- [ORM models](https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/models/__init__.py): persistence models · Customer, quality metrics, and golden record entities. · `app/models/__init__.py`
- [API schemas](https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/schemas/__init__.py): contracts · Pydantic payload contracts for customers, metrics, and records. · `app/schemas/__init__.py`
- [Database](https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/core/database.py): SQLAlchemy DB · SQLite/PostgreSQL persistence boundary and session management. · `app/core/database.py`

### Ops & delivery

Containerization, migrations, and CI/CD.

- [Config](https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/core/config.py): settings · Environment-driven settings for DB, scoring, logging, and auth. · `app/core/config.py`
- [Logging](https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/app/core/logging.py): infra · Centralized application logging configuration. · `app/core/logging.py`
- [Migrations](https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/alembic/env.py): schema evolution · Alembic migration system for controlled database changes. · `alembic/env.py`

### Dashboard

Read-oriented Streamlit surface.

- [Dashboard](https://github.com/ivan-kir/enterprise-data-quality-system/blob/main/dashboard/app.py): Streamlit app · Read-oriented UI over the shared backend data model. · `dashboard/app.py`

## Connections

- API app → Router: includes · Bootstraps the API with routed endpoints.
- Router → Ingest: registers · Exposes ingestion endpoint.
- Router → Quality: registers · Exposes quality endpoint.
- Router → Dedup: registers · Exposes deduplication endpoint.
- Router → Golden records: registers · Exposes golden record read endpoint.
- Router → Metrics: registers · Exposes metrics read endpoint.
- Ingest → Dependencies: uses · Applies shared auth/session dependencies.
- Quality → Dependencies: uses · Applies shared auth/session dependencies.
- Dedup → Dependencies: uses · Applies shared auth/session dependencies.
- Ingest → Ingestion pipeline: starts · Dispatches batch ingestion work.
- Quality → Quality pipeline: starts · Dispatches batch quality analysis.
- Dedup → Dedup pipeline: starts · Dispatches deduplication workflow.
- Ingestion pipeline → Ingestion service: orchestrates · Delegates record generation and persistence.
- Quality pipeline → Quality service: orchestrates · Delegates metric computation and persistence.
- Dedup pipeline → Resolution service: orchestrates · Delegates matching and clustering.
- Dedup pipeline → Golden service: orchestrates · Delegates cluster merge into canonical records.
- Ingestion service → ORM models: persists · Writes customer batches to the database model.
- Quality service → ORM models: persists · Stores quality metrics history.
- Golden service → ORM models: persists · Stores consolidated golden records.
- ORM models → Database: uses · ORM entities are backed by the shared database session.
- API schemas → Router: shapes · Defines request and response contracts for endpoints.
- Config → Database: configures · Provides database URL and runtime settings.
- Config → Dependencies: configures · Provides token auth and shared settings.
- Logging → API app: informs · Supplies application logging configuration.
- Migrations → Database: evolves · Manages schema changes for the persistent store.
- Dashboard → Database: reads · Presents persisted batches, metrics, and records.
- Dashboard → API schemas: follows · Aligns with the shared data contracts.
