# tolgerx/lakehouse-doctor architecture

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

- Interactive diagram: https://gitdiagram.com/tolgerx/lakehouse-doctor
- Repository: https://github.com/tolgerx/lakehouse-doctor

## Overview

Lakehouse Doctor is an offline SQL auditing and lakehouse-diagnostics toolkit for Doris, StarRocks, Paimon, and Flink SQL. Its main workflow accepts SQL through the CLI or MCP server, parses it and builds a schema catalog, then runs audits or derives lineage, impact, and DQC output; Query Profile analysis is a separate input-to-diagnostics path. The graph also includes report generation and optional live catalog backfill. Source excerpts are partial, so some subsystem links rely on the README or the supplied SOURCE INDEX rather than inspected call sites.

Main entry points: [`src/lakehouse_doctor/cli.py`](https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/cli.py) (CLI), [`src/lakehouse_doctor/models.py`](https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/models.py) (Domain Models), [`src/lakehouse_doctor/mcp_server.py`](https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/mcp_server.py) (MCP Server), [`src/lakehouse_doctor/rules/__init__.py`](https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/rules/__init__.py) (Audit Registry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry Points"]
  node_cli["CLI<br/>[cli.py]"]
  node_mcp["MCP Server<br/>[mcp_server.py]"]
end

subgraph group_sql["SQL Analysis"]
  node_parser["SQL Parser<br/>[parser.py]"]
  node_templates["Template Preprocessor"]
  node_catalog[("Metadata Catalog<br/>[catalog.py]")]
  node_online["Live Catalog Backfill<br/>[online.py]"]
  node_rules["Audit Registry<br/>[__init__.py]"]
  node_ddl_rules["DDL Rules<br/>[ddl_rules.py]"]
  node_dml_rules["DML Rules<br/>[dml_rules.py]"]
  node_rule_base["Rule Interface<br/>[base.py]"]
end

subgraph group_insights["Lineage And Quality"]
  node_lineage["Lineage And Impact<br/>[lineage.py]"]
  node_dqc["DQC Generator<br/>[dqc.py]"]
end

subgraph group_profile["Profile Diagnostics"]
  node_profile["Profile Analyzer"]
end

subgraph group_shared["Shared Output"]
  node_models["Domain Models<br/>[models.py]"]
  node_formatters["Text And Data Formatters<br/>[formatters.py]"]
  node_lineage_html["Lineage HTML Report<br/>[html_report.py]"]
  node_profile_html["Profile HTML Report<br/>[profile_html.py]"]
end

node_user(("Engineer / Agent"))

node_user -->|"runs commands"| node_cli
node_user -->|"calls tools"| node_mcp
node_cli -->|"loads SQL"| node_parser
node_cli -->|"builds catalog"| node_catalog
node_cli -->|"runs audit"| node_rules
node_cli -->|"traces impact"| node_lineage
node_cli -->|"generates checks"| node_dqc
node_cli -->|"analyzes profile"| node_profile
node_cli -->|"formats results"| node_formatters
node_cli -->|"renders report"| node_lineage_html
node_cli -->|"renders report"| node_profile_html
node_parser -->|"preprocesses templates"| node_templates
node_parser -->|"creates statements"| node_models
node_catalog -->|"stores schemas"| node_models
node_online -->|"parses DDL"| node_catalog
node_online -->|"parses fetched DDL"| node_parser
node_rules -->|"registers rules"| node_ddl_rules
node_rules -->|"registers rules"| node_dml_rules
node_ddl_rules -->|"implements"| node_rule_base
node_dml_rules -->|"implements"| node_rule_base
node_rules -->|"returns diagnostics"| node_models
node_lineage -->|"resolves tables"| node_catalog
node_lineage -->|"builds graph"| node_models
node_dqc -->|"uses schemas"| node_models
node_dqc -->|"uses dependencies"| node_lineage
node_profile -->|"produces findings"| node_models
node_formatters -->|"formats data"| node_models
node_lineage_html -->|"renders graph"| node_models
node_profile_html -->|"renders findings"| node_models
node_mcp -->|"loads SQL"| node_parser
node_mcp -->|"analyzes profile"| node_profile
node_mcp -->|"inspects catalog"| node_catalog
node_mcp -->|"traces impact"| node_lineage
node_mcp -->|"generates checks"| node_dqc
node_mcp -->|"audits SQL"| node_rules
node_cli -.->|"backfills metadata"| node_online

click node_cli "https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/cli.py"
click node_mcp "https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/mcp_server.py"
click node_parser "https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/parser.py"
click node_templates "https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/template_preprocessor.py"
click node_catalog "https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/catalog.py"
click node_online "https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/online.py"
click node_rules "https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/rules/__init__.py"
click node_ddl_rules "https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/rules/ddl_rules.py"
click node_dml_rules "https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/rules/dml_rules.py"
click node_rule_base "https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/rules/base.py"
click node_lineage "https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/lineage.py"
click node_dqc "https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/dqc.py"
click node_profile "https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/profile_analyzer.py"
click node_models "https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/models.py"
click node_formatters "https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/formatters.py"
click node_lineage_html "https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/html_report.py"
click node_profile_html "https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/profile_html.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_cli,node_mcp toneBlue
class node_parser,node_templates,node_catalog,node_online,node_rules,node_ddl_rules,node_dml_rules,node_rule_base toneAmber
class node_lineage,node_dqc toneMint
class node_profile toneRose
class node_models,node_formatters,node_lineage_html,node_profile_html,node_user toneIndigo
```

## Components

### Entry Points

- [CLI](https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/cli.py): `src/lakehouse_doctor/cli.py`
- [MCP Server](https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/mcp_server.py): `src/lakehouse_doctor/mcp_server.py`

### SQL Analysis

- [SQL Parser](https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/parser.py): `src/lakehouse_doctor/parser.py`
- [Template Preprocessor](https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/template_preprocessor.py): `src/lakehouse_doctor/template_preprocessor.py`
- [Metadata Catalog](https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/catalog.py): `src/lakehouse_doctor/catalog.py`
- [Live Catalog Backfill](https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/online.py): `src/lakehouse_doctor/online.py`
- [Audit Registry](https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/rules/__init__.py): `src/lakehouse_doctor/rules/__init__.py`
- [DDL Rules](https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/rules/ddl_rules.py): `src/lakehouse_doctor/rules/ddl_rules.py`
- [DML Rules](https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/rules/dml_rules.py): `src/lakehouse_doctor/rules/dml_rules.py`
- [Rule Interface](https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/rules/base.py): `src/lakehouse_doctor/rules/base.py`

### Lineage And Quality

- [Lineage And Impact](https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/lineage.py): `src/lakehouse_doctor/lineage.py`
- [DQC Generator](https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/dqc.py): `src/lakehouse_doctor/dqc.py`

### Profile Diagnostics

- [Profile Analyzer](https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/profile_analyzer.py): `src/lakehouse_doctor/profile_analyzer.py`

### Shared Output

- [Domain Models](https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/models.py): `src/lakehouse_doctor/models.py`
- [Text And Data Formatters](https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/formatters.py): `src/lakehouse_doctor/formatters.py`
- [Lineage HTML Report](https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/html_report.py): `src/lakehouse_doctor/html_report.py`
- [Profile HTML Report](https://github.com/tolgerx/lakehouse-doctor/blob/main/src/lakehouse_doctor/profile_html.py): `src/lakehouse_doctor/profile_html.py`

### Other components

- **Engineer / Agent**

## Connections

- Engineer / Agent → CLI: runs commands (evidence: `README.md`)
- Engineer / Agent → MCP Server: calls tools (evidence: `README.md`)
- CLI → SQL Parser: loads SQL (evidence: `src/lakehouse_doctor/cli.py`)
- CLI → Metadata Catalog: builds catalog (evidence: `src/lakehouse_doctor/cli.py`)
- CLI → Audit Registry: runs audit (evidence: `src/lakehouse_doctor/cli.py`)
- CLI → Lineage And Impact: traces impact (evidence: `src/lakehouse_doctor/cli.py`)
- CLI → DQC Generator: generates checks (evidence: `src/lakehouse_doctor/cli.py`)
- CLI → Profile Analyzer: analyzes profile (evidence: `src/lakehouse_doctor/cli.py`)
- CLI → Text And Data Formatters: formats results (evidence: `src/lakehouse_doctor/cli.py`)
- CLI → Lineage HTML Report: renders report (evidence: `src/lakehouse_doctor/cli.py`)
- CLI → Profile HTML Report: renders report (evidence: `src/lakehouse_doctor/cli.py`)
- SQL Parser → Template Preprocessor: preprocesses templates (evidence: `src/lakehouse_doctor/parser.py`)
- SQL Parser → Domain Models: creates statements (evidence: `src/lakehouse_doctor/parser.py`)
- Metadata Catalog → Domain Models: stores schemas (evidence: `src/lakehouse_doctor/catalog.py`)
- Live Catalog Backfill → Metadata Catalog: parses DDL (evidence: `src/lakehouse_doctor/online.py`)
- Live Catalog Backfill → SQL Parser: parses fetched DDL (evidence: `src/lakehouse_doctor/online.py`)
- Audit Registry → DDL Rules: registers rules (evidence: `src/lakehouse_doctor/rules/__init__.py`)
- Audit Registry → DML Rules: registers rules (evidence: `src/lakehouse_doctor/rules/__init__.py`)
- DDL Rules → Rule Interface: implements (evidence: `src/lakehouse_doctor/rules/ddl_rules.py`)
- DML Rules → Rule Interface: implements (evidence: `src/lakehouse_doctor/rules/dml_rules.py`)
- Audit Registry → Domain Models: returns diagnostics (evidence: `src/lakehouse_doctor/rules/__init__.py`)
- Lineage And Impact → Metadata Catalog: resolves tables (evidence: `src/lakehouse_doctor/lineage.py`)
- Lineage And Impact → Domain Models: builds graph (evidence: `src/lakehouse_doctor/lineage.py`)
- DQC Generator → Domain Models: uses schemas (evidence: `src/lakehouse_doctor/dqc.py`)
- DQC Generator → Lineage And Impact: uses dependencies (evidence: `src/lakehouse_doctor/dqc.py`)
- Profile Analyzer → Domain Models: produces findings (evidence: `src/lakehouse_doctor/profile_analyzer.py`)
- Text And Data Formatters → Domain Models: formats data (evidence: `src/lakehouse_doctor/formatters.py`)
- Lineage HTML Report → Domain Models: renders graph (evidence: `src/lakehouse_doctor/html_report.py`)
- Profile HTML Report → Domain Models: renders findings (evidence: `src/lakehouse_doctor/profile_html.py`)
- MCP Server → SQL Parser: loads SQL (evidence: `src/lakehouse_doctor/mcp_server.py`)
- MCP Server → Profile Analyzer: analyzes profile (evidence: `src/lakehouse_doctor/mcp_server.py`)
- MCP Server → Metadata Catalog: inspects catalog (evidence: `src/lakehouse_doctor/mcp_server.py`)
- MCP Server → Lineage And Impact: traces impact (evidence: `src/lakehouse_doctor/mcp_server.py`)
- MCP Server → DQC Generator: generates checks (evidence: `src/lakehouse_doctor/mcp_server.py`)
- MCP Server → Audit Registry: audits SQL (evidence: `src/lakehouse_doctor/mcp_server.py`)
- CLI → Live Catalog Backfill: backfills metadata (evidence: `src/lakehouse_doctor/cli.py`)
