# guttof/pyzdc architecture

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

- Interactive diagram: https://gitdiagram.com/guttof/pyzdc
- Repository: https://github.com/guttof/pyzdc

## Overview

#### Purpose and public entry point
PyZDC is a Python 3.11+ library for retrieving and analyzing Brazilian Aedes aegypti epidemiological data, including Dengue, Zika, and Chikungunya. Consumers import the package as `pyzdc`; its exported API is rooted at `pyzdc/__init__.py` and provides processed tables as pandas DataFrames.

#### Pipeline architecture
The repository is organized as an ETL-style data pipeline:
1. extract raw disease/year data,
2. transform database-oriented and column-level representations,
3. infer schemas,
4. load or refresh accessible datasets,
5. expose domain-specific query functions.
The stage boundaries are explicit package directories: `pyzdc/extract/`, `pyzdc/transform/`, `pyzdc/infer_schema/`, and `pyzdc/load/`.

#### Extraction boundary
Raw retrieval is centralized in `pyzdc/extract/get_raw.py`. This is the external-data boundary: disease and year inputs are converted into raw source data before local transformations. Downstream code should avoid coupling directly to source formats and use this module’s output contract.

#### Transformation and validation
DuckDB is the material transformation runtime, used for validation and processing of epidemiological tables. `pyzdc/transform/transform_db.py` handles database-level transformations, while `pyzdc/transform/transform_columns.py` normalizes or maps columns. These stages bridge inconsistent source fields to the package’s consumer-facing tabular schema.

#### Schema contract
Schema inference and model definitions establish the structural contract between transformed data and access functions. `pyzdc/infer_schema/infer_schema.py` derives schemas from data; `pyzdc/schemas/model_schema.py` and `pyzdc/schemas/model_schema_pydantic.py` define model representations, with Pydantic providing runtime validation where used. Changes to extraction or transformations should be reconciled here to preserve API stability.

#### Loading and query-facing access
`pyzdc/load/refresh_data.py` refreshes prepared data, and `pyzdc/load/show_data.py` reads or presents it. `pyzdc/get_info/get_info.py` is the domain-facing access layer for tables such as notifications, personal data, and clinical signs. The primary control flow is: public API → info/query functions → prepared DuckDB-backed data; refresh paths invoke extraction, transformation, and schema work.

#### Reference data and shared infrastructure
Static reference mappings are packaged under `pyzdc/data/json/`, notably `cities.json`, `states.json`, and `columns_translated_english.json`. They support geographic interpretation and column translation rather than requiring an external reference service. Shared database and operational concerns are isolated in `pyzdc/utils/db_utils.py`, `pyzdc/utils/config.py`, and `pyzdc/utils/logger.py`.

#### Delivery and quality boundaries
The package is distributed as a Python library, with dependencies and runtime metadata in `pyproject.toml` and `requirements.txt`. GitHub Actions CI is defined in `.github/workflows/ci.yaml`; documentation is published through MkDocs/Read the Docs configuration (`mkdocs.yml`, `.readthedocs.yaml`).

Main entry points: [`pyzdc/load/refresh_data.py`](https://github.com/guttof/pyzdc/blob/main/pyzdc/load/refresh_data.py) (Dataset refresh), [`pyzdc/infer_schema/infer_schema.py`](https://github.com/guttof/pyzdc/blob/main/pyzdc/infer_schema/infer_schema.py) (Schema inference), [`pyzdc/transform/transform_db.py`](https://github.com/guttof/pyzdc/blob/main/pyzdc/transform/transform_db.py) (Database transforms), [`pyzdc/transform/transform_columns.py`](https://github.com/guttof/pyzdc/blob/main/pyzdc/transform/transform_columns.py) (Column normalization)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_pipeline["Data Pipeline"]
  node_raw_sources[("Disease source data<br/>external data")]
  node_raw_extraction["Raw extraction<br/>extract stage<br/>[get_raw.py]"]
  node_db_transform[("Database transforms<br/>DuckDB transform<br/>[transform_db.py]")]
  node_column_transform["Column normalization<br/>transform stage"]
  node_schema_inference["Schema inference<br/>schema stage<br/>[infer_schema.py]"]
  node_data_refresh["Dataset refresh<br/>load stage<br/>[refresh_data.py]"]
  node_data_reader["Prepared-data reader<br/>load stage<br/>[show_data.py]"]
end

subgraph group_contracts["Contracts &amp; Reference Data"]
  node_model_schema["Model schema<br/>schema model<br/>[model_schema.py]"]
  node_pydantic_schema["Pydantic schema<br/>runtime validation"]
  node_reference_mappings["Reference mappings<br/>packaged JSON"]
end

subgraph group_access["Public Access"]
  node_public_api["pyzdc public API<br/>Python package<br/>[__init__.py]"]
  node_info_queries["Domain queries<br/>query access<br/>[get_info.py]"]
  node_prepared_data[("Prepared datasets<br/>DuckDB-backed data")]
end

subgraph group_operations["Shared Infrastructure"]
  node_db_utils["Database utilities<br/>shared utility<br/>[db_utils.py]"]
  node_config["Runtime configuration<br/>shared utility<br/>[config.py]"]
  node_logger["Logging<br/>shared utility<br/>[logger.py]"]
end

subgraph group_delivery["Delivery"]
  node_package_metadata["Package metadata<br/>distribution config<br/>[pyproject.toml]"]
  node_ci["GitHub Actions CI<br/>CI workflow<br/>[ci.yaml]"]
  node_documentation["MkDocs documentation<br/>[mkdocs.yml]"]
end

node_public_api -->|"exposes"| node_info_queries
node_info_queries -->|"queries"| node_prepared_data
node_data_reader -->|"reads"| node_prepared_data
node_raw_sources -->|"retrieved by"| node_raw_extraction
node_raw_extraction -->|"raw data"| node_db_transform
node_db_transform -->|"processed tables"| node_column_transform
node_column_transform -->|"normalized data"| node_schema_inference
node_schema_inference -->|"schema contract"| node_data_refresh
node_data_refresh -->|"refreshes"| node_prepared_data
node_model_schema -.->|"defines models"| node_schema_inference
node_pydantic_schema -.->|"validates"| node_schema_inference
node_reference_mappings -.->|"translation mappings"| node_column_transform
node_db_utils -.->|"database support"| node_db_transform
node_db_utils -.->|"database support"| node_data_refresh
node_config -.->|"configures"| node_data_refresh
node_logger -.->|"logs"| node_data_refresh
node_package_metadata -.->|"packages"| node_public_api
node_ci -.->|"validates"| node_package_metadata
node_documentation -.->|"documents"| node_public_api

click node_public_api "https://github.com/guttof/pyzdc/blob/main/pyzdc/__init__.py"
click node_info_queries "https://github.com/guttof/pyzdc/blob/main/pyzdc/get_info/get_info.py"
click node_raw_extraction "https://github.com/guttof/pyzdc/blob/main/pyzdc/extract/get_raw.py"
click node_db_transform "https://github.com/guttof/pyzdc/blob/main/pyzdc/transform/transform_db.py"
click node_column_transform "https://github.com/guttof/pyzdc/blob/main/pyzdc/transform/transform_columns.py"
click node_schema_inference "https://github.com/guttof/pyzdc/blob/main/pyzdc/infer_schema/infer_schema.py"
click node_data_refresh "https://github.com/guttof/pyzdc/blob/main/pyzdc/load/refresh_data.py"
click node_data_reader "https://github.com/guttof/pyzdc/blob/main/pyzdc/load/show_data.py"
click node_model_schema "https://github.com/guttof/pyzdc/blob/main/pyzdc/schemas/model_schema.py"
click node_pydantic_schema "https://github.com/guttof/pyzdc/blob/main/pyzdc/schemas/model_schema_pydantic.py"
click node_reference_mappings "https://github.com/guttof/pyzdc/blob/main/pyzdc/data/json/columns_translated_english.json"
click node_db_utils "https://github.com/guttof/pyzdc/blob/main/pyzdc/utils/db_utils.py"
click node_config "https://github.com/guttof/pyzdc/blob/main/pyzdc/utils/config.py"
click node_logger "https://github.com/guttof/pyzdc/blob/main/pyzdc/utils/logger.py"
click node_package_metadata "https://github.com/guttof/pyzdc/blob/main/pyproject.toml"
click node_ci "https://github.com/guttof/pyzdc/blob/main/.github/workflows/ci.yaml"
click node_documentation "https://github.com/guttof/pyzdc/blob/main/mkdocs.yml"

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_raw_sources,node_raw_extraction,node_db_transform,node_column_transform,node_schema_inference,node_data_refresh,node_data_reader toneBlue
class node_model_schema,node_pydantic_schema,node_reference_mappings toneAmber
class node_public_api,node_info_queries,node_prepared_data toneMint
class node_db_utils,node_config,node_logger toneRose
class node_package_metadata,node_ci,node_documentation toneIndigo
```

## Components

### Data Pipeline

ETL stages that prepare epidemiological tables.

- **Disease source data**: external data · Raw Dengue, Zika, and Chikungunya data by year.
- [Raw extraction](https://github.com/guttof/pyzdc/blob/main/pyzdc/extract/get_raw.py): extract stage · Converts disease and year inputs into a raw-data contract. · `pyzdc/extract/get_raw.py`
- [Database transforms](https://github.com/guttof/pyzdc/blob/main/pyzdc/transform/transform_db.py): DuckDB transform · Validates and processes epidemiological tables. · `pyzdc/transform/transform_db.py`
- [Column normalization](https://github.com/guttof/pyzdc/blob/main/pyzdc/transform/transform_columns.py): transform stage · Normalizes and maps inconsistent source columns. · `pyzdc/transform/transform_columns.py`
- [Schema inference](https://github.com/guttof/pyzdc/blob/main/pyzdc/infer_schema/infer_schema.py): schema stage · Derives schemas from transformed data. · `pyzdc/infer_schema/infer_schema.py`
- [Dataset refresh](https://github.com/guttof/pyzdc/blob/main/pyzdc/load/refresh_data.py): load stage · Orchestrates preparation and refresh of accessible data. · `pyzdc/load/refresh_data.py`
- [Prepared-data reader](https://github.com/guttof/pyzdc/blob/main/pyzdc/load/show_data.py): load stage · Reads or presents prepared datasets. · `pyzdc/load/show_data.py`

### Contracts & Reference Data

Schema definitions and packaged mappings.

- [Model schema](https://github.com/guttof/pyzdc/blob/main/pyzdc/schemas/model_schema.py): schema model · Defines structural model representations. · `pyzdc/schemas/model_schema.py`
- [Pydantic schema](https://github.com/guttof/pyzdc/blob/main/pyzdc/schemas/model_schema_pydantic.py): runtime validation · Validates model representations where used. · `pyzdc/schemas/model_schema_pydantic.py`
- [Reference mappings](https://github.com/guttof/pyzdc/blob/main/pyzdc/data/json/columns_translated_english.json): packaged JSON · City, state, and English-column mappings. · `pyzdc/data/json/columns_translated_english.json`

### Public Access

Consumer-facing package and query layer.

- [pyzdc public API](https://github.com/guttof/pyzdc/blob/main/pyzdc/__init__.py): Python package · Exports DataFrame-oriented library functions. · `pyzdc/__init__.py`
- [Domain queries](https://github.com/guttof/pyzdc/blob/main/pyzdc/get_info/get_info.py): query access · Provides notifications, personal-data, and clinical-sign tables. · `pyzdc/get_info/get_info.py`
- **Prepared datasets**: DuckDB-backed data · Accessible epidemiological tables used by queries.

### Shared Infrastructure

Database and operational support.

- [Database utilities](https://github.com/guttof/pyzdc/blob/main/pyzdc/utils/db_utils.py): shared utility · Shared database concerns. · `pyzdc/utils/db_utils.py`
- [Runtime configuration](https://github.com/guttof/pyzdc/blob/main/pyzdc/utils/config.py): shared utility · Operational configuration. · `pyzdc/utils/config.py`
- [Logging](https://github.com/guttof/pyzdc/blob/main/pyzdc/utils/logger.py): shared utility · Shared operational logging. · `pyzdc/utils/logger.py`

### Delivery

Packaging, CI, and documentation.

- [Package metadata](https://github.com/guttof/pyzdc/blob/main/pyproject.toml): distribution config · Python dependencies and runtime metadata. · `pyproject.toml`
- [GitHub Actions CI](https://github.com/guttof/pyzdc/blob/main/.github/workflows/ci.yaml): CI workflow · Automated quality boundary. · `.github/workflows/ci.yaml`
- [MkDocs documentation](https://github.com/guttof/pyzdc/blob/main/mkdocs.yml): documentation · Published documentation configuration. · `mkdocs.yml`

## Connections

- pyzdc public API → Domain queries: exposes
- Domain queries → Prepared datasets: queries
- Prepared-data reader → Prepared datasets: reads
- Disease source data → Raw extraction: retrieved by
- Raw extraction → Database transforms: raw data
- Database transforms → Column normalization: processed tables
- Column normalization → Schema inference: normalized data
- Schema inference → Dataset refresh: schema contract
- Dataset refresh → Prepared datasets: refreshes
- Model schema → Schema inference: defines models
- Pydantic schema → Schema inference: validates
- Reference mappings → Column normalization: translation mappings
- Database utilities → Database transforms: database support
- Database utilities → Dataset refresh: database support
- Runtime configuration → Dataset refresh: configures
- Logging → Dataset refresh: logs
- Package metadata → pyzdc public API: packages
- GitHub Actions CI → Package metadata: validates
- MkDocs documentation → pyzdc public API: documents
