# sharif-basha/clickhouse_sync architecture

> Architecture diagram of the GitHub repository sharif-basha/clickhouse_sync, 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/sharif-basha/clickhouse_sync
- Repository: https://github.com/sharif-basha/clickhouse_sync

## Overview

ClickHouse Sync is a Frappe app that copies configured ERPNext DocTypes into ClickHouse for analytics. Users configure a connection and DocTypes, then start syncs manually or rely on scheduled jobs. Jobs create and reconcile schemas, stream batches and track progress; monitoring, reports and optional Telegram alerts expose outcomes. The README documents child-table sync, delete strategies, retries, cancellation and resumable cursors. Some subsystem links are based on the SOURCE INDEX or README because their full implementation was not sampled.

Main entry points: [`clickhouse_sync/clickhouse/sync_engine.py`](https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/clickhouse/sync_engine.py) (Sync engine), [`clickhouse_sync/tasks.py`](https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/tasks.py) (Job scheduler), [`clickhouse_sync/clickhouse_warehouse/page/clickhouse_sync_dashboard/clickhouse_sync_dashboard.js`](https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/clickhouse_warehouse/page/clickhouse_sync_dashboard/clickhouse_sync_dashboard.js) (Dashboard UI), [`clickhouse_sync/api/dashboard.py`](https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/api/dashboard.py) (Dashboard API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_setup["Configuration"]
  node_config["Sync configuration"]
  node_settings["Connection settings"]
end

subgraph group_sync["Sync runtime"]
  node_api["User API<br/>[api.py]"]
  node_tasks["Job scheduler<br/>[tasks.py]"]
  node_engine["Sync engine<br/>[sync_engine.py]"]
  node_schema["Schema reconcile<br/>[schema.py]"]
  node_types["Type conversion<br/>[type_mapping.py]"]
  node_errors["Retry classification<br/>[exceptions.py]"]
end

subgraph group_observe["Monitoring"]
  node_dashboard_ui["Dashboard UI"]
  node_dashboard_api["Dashboard API<br/>[dashboard.py]"]
  node_status[("Live run state<br/>[live_status.py]")]
  node_logs[("Sync logs")]
  node_alerts["Telegram alerts<br/>[alerts.py]"]
  node_warehouse_stats["Warehouse statistics<br/>[warehouse_stats.py]"]
  node_reports["Analytics reports"]
end

subgraph group_integrations["Data services"]
  node_connection["Connection manager<br/>[connection.py]"]
  node_mariadb[("ERP database")]
  node_clickhouse[("ClickHouse warehouse")]
  node_redis[("Frappe Redis")]
end

node_user(("Frappe user"))
node_scheduler(("Frappe scheduler"))
node_telegram["Telegram"]
node_analytics(("BI and SQL consumers"))

node_user -->|"configures"| node_settings
node_user -->|"defines DocTypes"| node_config
node_user -->|"starts sync"| node_dashboard_ui
node_dashboard_ui -.->|"requests sync"| node_api
node_api -->|"enqueues job"| node_tasks
node_scheduler -->|"checks schedule"| node_tasks
node_tasks -->|"runs sync"| node_engine
node_config -->|"supplies settings"| node_engine
node_engine -->|"connects"| node_connection
node_engine -->|"reconciles schema"| node_schema
node_schema -->|"maps fields"| node_types
node_engine -->|"converts rows"| node_types
node_engine -.->|"classifies failures"| node_errors
node_mariadb -->|"provides records"| node_engine
node_engine -->|"writes batches"| node_clickhouse
node_connection -->|"opens session"| node_clickhouse
node_engine -->|"publishes progress"| node_status
node_status -->|"stores run state"| node_redis
node_dashboard_api -->|"reads run state"| node_status
node_dashboard_ui -.->|"loads dashboard"| node_dashboard_api
node_dashboard_api -->|"gets table metrics"| node_warehouse_stats
node_warehouse_stats -->|"queries parts"| node_clickhouse
node_reports -.->|"queries warehouse"| node_clickhouse
node_reports -.->|"summarizes runs"| node_logs
node_engine -->|"records outcome"| node_logs
node_engine -->|"reports run"| node_alerts
node_tasks -->|"sends digest"| node_alerts
node_alerts -->|"sends alert"| node_telegram
node_analytics -->|"queries copy"| node_clickhouse

click node_config "https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/clickhouse_warehouse/doctype/clickhouse_sync_configuration/clickhouse_sync_configuration.py"
click node_settings "https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/clickhouse_warehouse/doctype/clickhouse_settings/clickhouse_settings.py"
click node_dashboard_ui "https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/clickhouse_warehouse/page/clickhouse_sync_dashboard/clickhouse_sync_dashboard.js"
click node_api "https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/api/api.py"
click node_dashboard_api "https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/api/dashboard.py"
click node_tasks "https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/tasks.py"
click node_engine "https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/clickhouse/sync_engine.py"
click node_schema "https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/clickhouse/schema.py"
click node_types "https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/clickhouse/type_mapping.py"
click node_errors "https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/clickhouse/exceptions.py"
click node_connection "https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/clickhouse/connection.py"
click node_status "https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/clickhouse/live_status.py"
click node_logs "https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/clickhouse_warehouse/doctype/clickhouse_sync_log/clickhouse_sync_log.py"
click node_alerts "https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/clickhouse/alerts.py"
click node_warehouse_stats "https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/clickhouse/warehouse_stats.py"
click node_reports "https://github.com/sharif-basha/clickhouse_sync/tree/main/clickhouse_sync/clickhouse_warehouse/report"

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_config,node_settings,node_user toneBlue
class node_api,node_tasks,node_engine,node_schema,node_types,node_errors toneAmber
class node_dashboard_ui,node_dashboard_api,node_status,node_logs,node_alerts,node_warehouse_stats,node_reports toneMint
class node_connection,node_mariadb,node_clickhouse,node_redis,node_scheduler toneRose
class node_telegram,node_analytics toneIndigo
```

## Components

### Configuration

- [Sync configuration](https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/clickhouse_warehouse/doctype/clickhouse_sync_configuration/clickhouse_sync_configuration.py): `clickhouse_sync/clickhouse_warehouse/doctype/clickhouse_sync_configuration/clickhouse_sync_configuration.py`
- [Connection settings](https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/clickhouse_warehouse/doctype/clickhouse_settings/clickhouse_settings.py): `clickhouse_sync/clickhouse_warehouse/doctype/clickhouse_settings/clickhouse_settings.py`

### Sync runtime

- [User API](https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/api/api.py): `clickhouse_sync/api/api.py`
- [Job scheduler](https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/tasks.py): `clickhouse_sync/tasks.py`
- [Sync engine](https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/clickhouse/sync_engine.py): `clickhouse_sync/clickhouse/sync_engine.py`
- [Schema reconcile](https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/clickhouse/schema.py): `clickhouse_sync/clickhouse/schema.py`
- [Type conversion](https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/clickhouse/type_mapping.py): `clickhouse_sync/clickhouse/type_mapping.py`
- [Retry classification](https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/clickhouse/exceptions.py): `clickhouse_sync/clickhouse/exceptions.py`

### Monitoring

- [Dashboard UI](https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/clickhouse_warehouse/page/clickhouse_sync_dashboard/clickhouse_sync_dashboard.js): `clickhouse_sync/clickhouse_warehouse/page/clickhouse_sync_dashboard/clickhouse_sync_dashboard.js`
- [Dashboard API](https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/api/dashboard.py): `clickhouse_sync/api/dashboard.py`
- [Live run state](https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/clickhouse/live_status.py): `clickhouse_sync/clickhouse/live_status.py`
- [Sync logs](https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/clickhouse_warehouse/doctype/clickhouse_sync_log/clickhouse_sync_log.py): `clickhouse_sync/clickhouse_warehouse/doctype/clickhouse_sync_log/clickhouse_sync_log.py`
- [Telegram alerts](https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/clickhouse/alerts.py): `clickhouse_sync/clickhouse/alerts.py`
- [Warehouse statistics](https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/clickhouse/warehouse_stats.py): `clickhouse_sync/clickhouse/warehouse_stats.py`
- [Analytics reports](https://github.com/sharif-basha/clickhouse_sync/tree/main/clickhouse_sync/clickhouse_warehouse/report): `clickhouse_sync/clickhouse_warehouse/report`

### Data services

- [Connection manager](https://github.com/sharif-basha/clickhouse_sync/blob/main/clickhouse_sync/clickhouse/connection.py): `clickhouse_sync/clickhouse/connection.py`
- **ERP database**
- **ClickHouse warehouse**
- **Frappe Redis**

### Other components

- **Frappe user**
- **Frappe scheduler**
- **Telegram**
- **BI and SQL consumers**

## Connections

- Frappe user → Connection settings: configures
- Frappe user → Sync configuration: defines DocTypes
- Frappe user → Dashboard UI: starts sync
- Dashboard UI → User API: requests sync
- User API → Job scheduler: enqueues job (evidence: `clickhouse_sync/api/api.py`)
- Frappe scheduler → Job scheduler: checks schedule (evidence: `clickhouse_sync/tasks.py`)
- Job scheduler → Sync engine: runs sync (evidence: `clickhouse_sync/tasks.py`)
- Sync configuration → Sync engine: supplies settings (evidence: `clickhouse_sync/clickhouse_warehouse/doctype/clickhouse_sync_configuration/clickhouse_sync_configuration.py`)
- Sync engine → Connection manager: connects (evidence: `clickhouse_sync/clickhouse/sync_engine.py`)
- Sync engine → Schema reconcile: reconciles schema (evidence: `clickhouse_sync/clickhouse/sync_engine.py`)
- Schema reconcile → Type conversion: maps fields (evidence: `clickhouse_sync/clickhouse/schema.py`)
- Sync engine → Type conversion: converts rows (evidence: `clickhouse_sync/clickhouse/sync_engine.py`)
- Sync engine → Retry classification: classifies failures (evidence: `clickhouse_sync/clickhouse/sync_engine.py`)
- ERP database → Sync engine: provides records
- Sync engine → ClickHouse warehouse: writes batches
- Connection manager → ClickHouse warehouse: opens session (evidence: `clickhouse_sync/clickhouse/connection.py`)
- Sync engine → Live run state: publishes progress (evidence: `clickhouse_sync/clickhouse/live_status.py`)
- Live run state → Frappe Redis: stores run state (evidence: `clickhouse_sync/clickhouse/live_status.py`)
- Dashboard API → Live run state: reads run state (evidence: `clickhouse_sync/api/dashboard.py`)
- Dashboard UI → Dashboard API: loads dashboard
- Dashboard API → Warehouse statistics: gets table metrics (evidence: `clickhouse_sync/api/dashboard.py`)
- Warehouse statistics → ClickHouse warehouse: queries parts (evidence: `clickhouse_sync/clickhouse/warehouse_stats.py`)
- Analytics reports → ClickHouse warehouse: queries warehouse
- Analytics reports → Sync logs: summarizes runs
- Sync engine → Sync logs: records outcome
- Sync engine → Telegram alerts: reports run (evidence: `clickhouse_sync/clickhouse/sync_engine.py`)
- Job scheduler → Telegram alerts: sends digest (evidence: `clickhouse_sync/tasks.py`)
- Telegram alerts → Telegram: sends alert (evidence: `clickhouse_sync/clickhouse/alerts.py`)
- BI and SQL consumers → ClickHouse warehouse: queries copy
