How ivan-kir/enterprise-data-quality-system works
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: router.py Router · __init__.py ORM models · dependencies.py Dependencies · database.py Database
Components 22
FastAPI backend
HTTP API, orchestration pipelines, and domain services.
- API app · Application bootstrap and server entry point.
app/main.py - Router · Wires route modules into the FastAPI application.
app/api/router.py - Dependencies · Shared request/session/auth dependencies for API routes.
app/api/dependencies.py - Ingest · Batch ingestion endpoint and request handling.
app/api/routes/ingest.py - Quality · Quality check endpoint for batch metrics.
app/api/routes/quality.py - Dedup · Deduplication endpoint for entity resolution jobs.
app/api/routes/deduplication.py - Golden records · Read endpoint for consolidated canonical records.
app/api/routes/golden_records.py - Metrics · Read endpoint for persisted quality metrics.
app/api/routes/metrics.py - Ingestion pipeline · Coordinates record generation, normalization, and persistence.
app/pipelines/ingestion_pipeline.py - Quality pipeline · Runs batch quality analysis and stores results.
app/pipelines/quality_pipeline.py - Dedup pipeline · Coordinates blocking, matching, clustering, and record merging.
app/pipelines/deduplication_pipeline.py - Ingestion service · Builds and persists customer batches, including synthetic demo data.
app/services/ingestion_service.py - Quality service · Computes completeness, uniqueness, validity, consistency, and outlier metrics.
app/services/quality_service.py - Resolution service · Performs blocking, fuzzy matching, thresholding, and clustering.
app/services/entity_resolution_service.py - Golden service · Merges clusters into deterministic canonical records.
app/services/golden_record_service.py
Data layer
ORM models, schemas, and database boundary.
- ORM models · Customer, quality metrics, and golden record entities.
app/models/__init__.py - API schemas · Pydantic payload contracts for customers, metrics, and records.
app/schemas/__init__.py - Database · SQLite/PostgreSQL persistence boundary and session management.
app/core/database.py
Ops & delivery
Containerization, migrations, and CI/CD.
- Config · Environment-driven settings for DB, scoring, logging, and auth.
app/core/config.py - Logging · Centralized application logging configuration.
app/core/logging.py - Migrations · Alembic migration system for controlled database changes.
alembic/env.py
Dashboard
Read-oriented Streamlit surface.
- Dashboard · Read-oriented UI over the shared backend data model.
dashboard/app.py
Connections 27
- 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.