# paz-rangelr/erp-snowflake-elt architecture

> Architecture diagram of the GitHub repository paz-rangelr/erp-snowflake-elt, 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/paz-rangelr/erp-snowflake-elt
- Repository: https://github.com/paz-rangelr/erp-snowflake-elt

## Overview

This repository is an ERP-to-Snowflake ELT pipeline. Its main workflow reads entity definitions from a declarative catalog, fetches paginated ERP records, flattens them into warehouse rows, and merges by content hash so unchanged data is not rewritten. Separate operational paths cover incremental sync, historical backfill, reconciliation, verification and re-queuing; read-only probes measure drift. The README documents the DQ-view capability. Some orchestration internals were not fully sampled, so uncertain call links are omitted; unsampled subsystems are represented only where the README or source index supports them.

Main entry points: [`src/extraer.py`](https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/extraer.py) (Extract and flatten), [`src/erp_client.py`](https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/erp_client.py) (ERP API client), [`src/verificar.py`](https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/verificar.py) (Load verification), [`src/entidades.py`](https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/entidades.py) (Entity catalog)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Ingestion engine"]
  node_catalog["Entity catalog<br/>[entidades.py]"]
  node_client["ERP API client<br/>[erp_client.py]"]
  node_extract["Extract and flatten<br/>[extraer.py]"]
  node_memory["Memory guard<br/>[memoria.py]"]
end

subgraph group_operations["Load operations"]
  node_sync["Incremental sync<br/>[sync.py]"]
  node_backfill["Historical backfill<br/>[backfill.py]"]
  node_reconcile["History reconciler<br/>[reconciliar.py]"]
  node_nightly["Nightly runner<br/>[nocturno.py]"]
end

subgraph group_quality["Verification and drift"]
  node_verify["Load verification<br/>[verificar.py]"]
  node_requeue["Re-queue gaps<br/>[reencolar.py]"]
  node_status["Status report<br/>[estado.py]"]
  node_drift["Drift probe<br/>[deriva.py]"]
  node_driftdetail["Field-change probe<br/>[deriva_detalle.py]"]
end

subgraph group_warehouse["Warehouse and state"]
  node_merge["Hash merge<br/>[sf.py]"]
  node_snowflake[("Snowflake warehouse")]
  node_dqviews["DQ views<br/>[04_vistas_dq.sql]"]
end

node_operator(("Operator"))
node_erp[("Leasing ERP API")]

node_erp -->|"serves pages"| node_client
node_catalog -.->|"configures requests"| node_client
node_catalog -->|"defines mappings"| node_extract
node_client -->|"supplies records"| node_extract
node_extract -->|"submits rows"| node_merge
node_merge -->|"merges rows"| node_snowflake
node_snowflake -->|"feeds views"| node_dqviews
node_sync -->|"runs incremental load"| node_extract
node_reconcile -->|"re-reads history"| node_extract
node_backfill -.->|"loads windows"| node_extract
node_nightly -.->|"coordinates phases"| node_backfill
node_nightly -.->|"runs checks"| node_verify
node_verify -->|"counts API records"| node_client
node_verify -->|"compares counts"| node_snowflake
node_verify -->|"re-queues gaps"| node_requeue
node_status -->|"reads status"| node_snowflake
node_drift -->|"reads current data"| node_client
node_drift -->|"compares hashes"| node_snowflake
node_driftdetail -->|"fetches records"| node_client
node_driftdetail -->|"reads saved JSON"| node_snowflake
node_operator -->|"starts update"| node_sync
node_operator -->|"starts reconciliation"| node_reconcile
node_operator -->|"requests status"| node_status
node_extract -.->|"uses guard"| node_memory

click node_catalog "https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/entidades.py"
click node_client "https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/erp_client.py"
click node_extract "https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/extraer.py"
click node_memory "https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/memoria.py"
click node_merge "https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/sf.py"
click node_dqviews "https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/sql/04_vistas_dq.sql"
click node_sync "https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/sync.py"
click node_backfill "https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/backfill.py"
click node_reconcile "https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/reconciliar.py"
click node_nightly "https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/nocturno.py"
click node_verify "https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/verificar.py"
click node_requeue "https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/reencolar.py"
click node_status "https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/estado.py"
click node_drift "https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/sondas/deriva.py"
click node_driftdetail "https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/sondas/deriva_detalle.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_catalog,node_client,node_extract,node_memory toneBlue
class node_sync,node_backfill,node_reconcile,node_nightly,node_erp toneAmber
class node_verify,node_requeue,node_status,node_drift,node_driftdetail toneMint
class node_merge,node_snowflake,node_dqviews toneRose
class node_operator toneIndigo
```

## Components

### Ingestion engine

- [Entity catalog](https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/entidades.py): `src/entidades.py`
- [ERP API client](https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/erp_client.py): `src/erp_client.py`
- [Extract and flatten](https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/extraer.py): `src/extraer.py`
- [Memory guard](https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/memoria.py): `src/memoria.py`

### Load operations

- [Incremental sync](https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/sync.py): `src/sync.py`
- [Historical backfill](https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/backfill.py): `src/backfill.py`
- [History reconciler](https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/reconciliar.py): `src/reconciliar.py`
- [Nightly runner](https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/nocturno.py): `src/nocturno.py`

### Verification and drift

- [Load verification](https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/verificar.py): `src/verificar.py`
- [Re-queue gaps](https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/reencolar.py): `src/reencolar.py`
- [Status report](https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/estado.py): `src/estado.py`
- [Drift probe](https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/sondas/deriva.py): `sondas/deriva.py`
- [Field-change probe](https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/sondas/deriva_detalle.py): `sondas/deriva_detalle.py`

### Warehouse and state

- [Hash merge](https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/src/sf.py): `src/sf.py`
- **Snowflake warehouse**
- [DQ views](https://github.com/paz-rangelr/erp-snowflake-elt/blob/main/sql/04_vistas_dq.sql): `sql/04_vistas_dq.sql`

### Other components

- **Operator**
- **Leasing ERP API**

## Connections

- Leasing ERP API → ERP API client: serves pages (evidence: `README.md`)
- Entity catalog → ERP API client: configures requests (evidence: `README.md`)
- Entity catalog → Extract and flatten: defines mappings (evidence: `README.md`)
- ERP API client → Extract and flatten: supplies records (evidence: `README.md`)
- Extract and flatten → Hash merge: submits rows (evidence: `README.md`)
- Hash merge → Snowflake warehouse: merges rows (evidence: `README.md`)
- Snowflake warehouse → DQ views: feeds views (evidence: `README.md`)
- Incremental sync → Extract and flatten: runs incremental load (evidence: `README.md`)
- History reconciler → Extract and flatten: re-reads history (evidence: `README.md`)
- Historical backfill → Extract and flatten: loads windows (evidence: `src/backfill.py`)
- Nightly runner → Historical backfill: coordinates phases (evidence: `src/nocturno.py`)
- Nightly runner → Load verification: runs checks (evidence: `src/nocturno.py`)
- Load verification → ERP API client: counts API records (evidence: `src/verificar.py`)
- Load verification → Snowflake warehouse: compares counts (evidence: `src/verificar.py`)
- Load verification → Re-queue gaps: re-queues gaps (evidence: `src/verificar.py`)
- Status report → Snowflake warehouse: reads status (evidence: `src/estado.py`)
- Drift probe → ERP API client: reads current data (evidence: `sondas/deriva.py`)
- Drift probe → Snowflake warehouse: compares hashes (evidence: `sondas/deriva.py`)
- Field-change probe → ERP API client: fetches records (evidence: `sondas/deriva_detalle.py`)
- Field-change probe → Snowflake warehouse: reads saved JSON (evidence: `sondas/deriva_detalle.py`)
- Operator → Incremental sync: starts update (evidence: `README.md`)
- Operator → History reconciler: starts reconciliation (evidence: `README.md`)
- Operator → Status report: requests status (evidence: `README.md`)
- Extract and flatten → Memory guard: uses guard (evidence: `src/extraer.py`)
