# kamil10x/hubspot-deals-etl architecture

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

- Interactive diagram: https://gitdiagram.com/kamil10x/hubspot-deals-etl
- Repository: https://github.com/kamil10x/hubspot-deals-etl

## Overview

This is a Flask REST API for asynchronous HubSpot Deals extraction into PostgreSQL through DLT. A client starts a scan, the API validates and dispatches it, extraction coordinates source ingestion and job/checkpoint tracking, and clients can query status and stored results. The README also documents scan management, maintenance, pipeline information, health checks, and monitoring. Relationships involving unsampled implementation details are included only where the README or source index supports them.

Main entry points: [`api/routes.py`](https://github.com/kamil10x/hubspot-deals-etl/blob/main/api/routes.py) (Scan and results API), [`services/extraction_service.py`](https://github.com/kamil10x/hubspot-deals-etl/blob/main/services/extraction_service.py) (Scan orchestration), [`app.py`](https://github.com/kamil10x/hubspot-deals-etl/blob/main/app.py) (Flask application), [`services/job_service.py`](https://github.com/kamil10x/hubspot-deals-etl/blob/main/services/job_service.py) (Job and checkpoint management)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and application"]
  node_application["Flask application<br/>[app.py]"]
  node_routes["Scan and results API<br/>[routes.py]"]
  node_validation["Request validation<br/>[schemas.py]"]
  node_swagger["API documentation schemas<br/>[swagger_schemas.py]"]
  node_configuration["Environment configuration<br/>[config.py]"]
  node_logging["Logging and monitoring<br/>[loki_logger.py]"]
end

subgraph group_extract["Extraction workflow"]
  node_extraction["Scan orchestration"]
  node_source["Data source and pagination<br/>[data_source.py]"]
end

subgraph group_state["Jobs and persistence"]
  node_jobs["Job and checkpoint management<br/>[job_service.py]"]
  node_encryption["Configuration encryption<br/>[encrypter.py]"]
  node_models["Job and checkpoint models<br/>[models.py]"]
  node_database["Database connection manager<br/>[database.py]"]
  node_data_access["Scan results and maintenance"]
end

subgraph group_integrations["External systems"]
  node_hubspot_client["HubSpot API client<br/>[api_service.py]"]
  node_hubspot["HubSpot Deals API"]
  node_postgres[("PostgreSQL via DLT")]
end

node_client(("API client"))

node_client -->|"calls endpoints"| node_routes
node_application -->|"loads settings"| node_configuration
node_application -->|"registers API"| node_routes
node_application -->|"initializes tables"| node_database
node_application -->|"configures logging"| node_logging
node_routes -->|"validates input"| node_validation
node_routes -->|"uses schemas"| node_swagger
node_routes -->|"dispatches scans"| node_extraction
node_extraction -->|"creates source"| node_source
node_source -->|"requests data"| node_hubspot_client
node_hubspot_client -->|"fetches records"| node_hubspot
node_extraction -->|"tracks scan jobs"| node_jobs
node_extraction -->|"queries scan data"| node_data_access
node_extraction -->|"loads with DLT"| node_postgres
node_data_access -->|"reads and cleans"| node_postgres
node_jobs -->|"opens sessions"| node_database
node_jobs -->|"uses job models"| node_models
node_database -->|"gets DB settings"| node_configuration
node_database -->|"creates tables"| node_models
node_jobs -->|"encrypts config"| node_encryption
node_routes -->|"records API events"| node_logging
node_hubspot_client -->|"logs API calls"| node_logging

click node_application "https://github.com/kamil10x/hubspot-deals-etl/blob/main/app.py"
click node_routes "https://github.com/kamil10x/hubspot-deals-etl/blob/main/api/routes.py"
click node_validation "https://github.com/kamil10x/hubspot-deals-etl/blob/main/api/schemas.py"
click node_swagger "https://github.com/kamil10x/hubspot-deals-etl/blob/main/api/swagger_schemas.py"
click node_extraction "https://github.com/kamil10x/hubspot-deals-etl/blob/main/services/extraction_service.py"
click node_source "https://github.com/kamil10x/hubspot-deals-etl/blob/main/services/data_source.py"
click node_hubspot_client "https://github.com/kamil10x/hubspot-deals-etl/blob/main/services/api_service.py"
click node_jobs "https://github.com/kamil10x/hubspot-deals-etl/blob/main/services/job_service.py"
click node_encryption "https://github.com/kamil10x/hubspot-deals-etl/blob/main/encrypter.py"
click node_models "https://github.com/kamil10x/hubspot-deals-etl/blob/main/models/models.py"
click node_database "https://github.com/kamil10x/hubspot-deals-etl/blob/main/models/database.py"
click node_data_access "https://github.com/kamil10x/hubspot-deals-etl/blob/main/services/database_service.py"
click node_configuration "https://github.com/kamil10x/hubspot-deals-etl/blob/main/config.py"
click node_logging "https://github.com/kamil10x/hubspot-deals-etl/blob/main/loki_logger.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_application,node_routes,node_validation,node_swagger,node_configuration,node_logging,node_client toneBlue
class node_extraction,node_source toneAmber
class node_jobs,node_encryption,node_models,node_database,node_data_access toneMint
class node_hubspot_client,node_hubspot,node_postgres toneRose
```

## Components

### API and application

- [Flask application](https://github.com/kamil10x/hubspot-deals-etl/blob/main/app.py): `app.py`
- [Scan and results API](https://github.com/kamil10x/hubspot-deals-etl/blob/main/api/routes.py): `api/routes.py`
- [Request validation](https://github.com/kamil10x/hubspot-deals-etl/blob/main/api/schemas.py): `api/schemas.py`
- [API documentation schemas](https://github.com/kamil10x/hubspot-deals-etl/blob/main/api/swagger_schemas.py): `api/swagger_schemas.py`
- [Environment configuration](https://github.com/kamil10x/hubspot-deals-etl/blob/main/config.py): `config.py`
- [Logging and monitoring](https://github.com/kamil10x/hubspot-deals-etl/blob/main/loki_logger.py): `loki_logger.py`

### Extraction workflow

- [Scan orchestration](https://github.com/kamil10x/hubspot-deals-etl/blob/main/services/extraction_service.py): `services/extraction_service.py`
- [Data source and pagination](https://github.com/kamil10x/hubspot-deals-etl/blob/main/services/data_source.py): `services/data_source.py`

### Jobs and persistence

- [Job and checkpoint management](https://github.com/kamil10x/hubspot-deals-etl/blob/main/services/job_service.py): `services/job_service.py`
- [Configuration encryption](https://github.com/kamil10x/hubspot-deals-etl/blob/main/encrypter.py): `encrypter.py`
- [Job and checkpoint models](https://github.com/kamil10x/hubspot-deals-etl/blob/main/models/models.py): `models/models.py`
- [Database connection manager](https://github.com/kamil10x/hubspot-deals-etl/blob/main/models/database.py): `models/database.py`
- [Scan results and maintenance](https://github.com/kamil10x/hubspot-deals-etl/blob/main/services/database_service.py): `services/database_service.py`

### External systems

- [HubSpot API client](https://github.com/kamil10x/hubspot-deals-etl/blob/main/services/api_service.py): `services/api_service.py`
- **HubSpot Deals API**
- **PostgreSQL via DLT**

### Other components

- **API client**

## Connections

- API client → Scan and results API: calls endpoints (evidence: `readme.md`)
- Flask application → Environment configuration: loads settings (evidence: `app.py`)
- Flask application → Scan and results API: registers API (evidence: `app.py`)
- Flask application → Database connection manager: initializes tables (evidence: `app.py`)
- Flask application → Logging and monitoring: configures logging (evidence: `app.py`)
- Scan and results API → Request validation: validates input (evidence: `api/routes.py`)
- Scan and results API → API documentation schemas: uses schemas (evidence: `api/routes.py`)
- Scan and results API → Scan orchestration: dispatches scans (evidence: `api/routes.py`)
- Scan orchestration → Data source and pagination: creates source (evidence: `services/extraction_service.py`)
- Data source and pagination → HubSpot API client: requests data (evidence: `services/data_source.py`)
- HubSpot API client → HubSpot Deals API: fetches records (evidence: `services/api_service.py`)
- Scan orchestration → Job and checkpoint management: tracks scan jobs (evidence: `services/extraction_service.py`)
- Scan orchestration → Scan results and maintenance: queries scan data (evidence: `services/extraction_service.py`)
- Scan orchestration → PostgreSQL via DLT: loads with DLT (evidence: `readme.md`)
- Scan results and maintenance → PostgreSQL via DLT: reads and cleans (evidence: `readme.md`)
- Job and checkpoint management → Database connection manager: opens sessions (evidence: `services/job_service.py`)
- Job and checkpoint management → Job and checkpoint models: uses job models (evidence: `services/job_service.py`)
- Database connection manager → Environment configuration: gets DB settings (evidence: `models/database.py`)
- Database connection manager → Job and checkpoint models: creates tables (evidence: `models/database.py`)
- Job and checkpoint management → Configuration encryption: encrypts config (evidence: `services/job_service.py`)
- Scan and results API → Logging and monitoring: records API events (evidence: `api/routes.py`)
- HubSpot API client → Logging and monitoring: logs API calls (evidence: `services/api_service.py`)
