How oleg-agapov/tablediff works
Project type & purpose (what you’re diagramming)
tablediff is a Python CLI tool that performs data diffs and schema diffs between:
• two tables in the same DB,
• tables across two different DBs (--conn + --conn2),
• two CSV files (tablediff files).
It delegates the heavy lifting of cross-database connectivity/diffing to reladiff (per README), and focuses on:
• CLI UX (commands/options),
• orchestration (“engine”),
• domain models (diff results),
• rendering results to terminal (and possibly a UI via start-ui.py).
• user interaction layer (CLI),
• orchestration layer (engine),
• integration layer (reladiff + DB adapters),
• sources/targets (DBs/CSV),
• output rendering.
How to read the repo structure into architectural components
From the file tree, the “real system” lives in tablediff/:
• tablediff/cli.py
Entry point / command definitions: parses args, maps subcommands (compare, schema, files) to engine functions, validates options (--pk, --conn, --conn2, --where, --extended).
• tablediff/engine.py
Core orchestration: builds connections, configures reladiff, executes diff operations, handles cross-db logic, applies --where, picks correct workflow for schema-vs-data-vs-files.
• tablediff/models.py
• tablediff/renderers.py
Presentation layer: converts models/results into terminal output (tables, summaries, extended sections). This is the output boundary.
• tablediff/__init__.py
Package metadata; not a component.
• pyproject.toml, uv.lock → packaging, dependency management, extras for adapters ([snowflake], [postgresql], [all]).
• scripts/generate_duckdb_test_data.py (+ .sql) → dev tooling to create sample data.
• tests/… → validates behavior across CLI, engine, CSV, cross-database, and reladiff integration.
• start-ui.py + img/demo.cast → indicates there may be an additional UI runner (even if it’s just a demo wrapper). Include it as an *optional entrypoint* if it’s actually used.
tablediff compare TABLE_A TABLE_B --pk … --conn … [--conn2 …] [--where …] [--extended]
Flow (high level):
Engine → reladiff
• instantiate adapters/drivers based on connection strings
• perform row-level diff keyed by --pk
• apply optional --where filter on both sides
CLI → Renderer prints results to terminal
Cross-db variant adds: Engine creates two connections (possibly different adapter types).
tablediff schema TABLE_A TABLE_B --conn … [--conn2 …]
Similar to compare, but the engine invokes schema inspection path and yields schema diff models (including types, per README).
tablediff files FILE_A FILE_B --pk …
This is a separate source type:
Results → Renderer
You want these three flows explicit, because they are the “product surface area”.
External dependencies & boundaries (must be
• reladiff library (core diff engine and DB abstraction)
• Database systems (DuckDB, Snowflake, Postgres, etc.)
• DB drivers/adapters enabled by install extras (e.g., tablediff-cli[snowflake])
• File system for CSV inputs and DuckDB local file
In other words: tablediff is an orchestrator + UX wrapper around reladiff + adapters.
Purpose: show who uses it and what it talks to.
Include:
• Actor: “Data engineer / analyst”
• System: “tablediff CLI tool”
• External: “Databases (DuckDB/Snowflake/…)”
• External: “CSV files (filesystem)”
• External: “reladiff library” (as a dependency boundary)
• User → tablediff: invokes commands
• tablediff → DBs: connect/query/inspect schema
• tablediff → filesystem: read CSV
Purpose: show major runtime modules and responsibilities.
• CLI Layer (tablediff/cli.py)
• Engine / Orchestration (tablediff/engine.py)
• Domain Models (tablediff/models.py)
• Renderers (tablediff/renderers.py)
• Integration: reladiff (external dependency, but show it adjacent)
• Connectors/Adapters (as part of reladiff + installed extras)
• Data Sources (DB A, DB B, CSV A, CSV B)
• CLI → Engine (command invocation)
• Engine ↔ reladiff (diff computation + schema inspection)
• Engine → Models (construct/return results)
• CLI/Engine → Renderer (format output)
• Renderer → Terminal (stdout)
• --pk affects diff key
• --where affects query/filter
• --extended affects renderer verbosity/model detail
• --conn/--conn2 decide whether one or two DB endpoints are created
Purpose: show internal responsibilities to help future changes.
Decompose like this (even if some are functions, it helps):
• In cli.py:
• Command routing: compare, schema, files
• Option parsing/validation
• Error handling/user messaging
• In engine.py:
• Connection factory (from conn strings)
• Diff job builder (table identifiers, pk, where)
• Execution paths:
• data diff path
• schema diff path
• CSV diff path
• Result normalization into models
• In renderers.py:
• Summary renderer
• Extended renderer sections
• Schema diff renderer
Then link each component to the relevant external interaction (DB/CSV/reladiff).