# mp321/sf-data-warehouse architecture

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

- Interactive diagram: https://gitdiagram.com/mp321/sf-data-warehouse
- Repository: https://github.com/mp321/sf-data-warehouse

## Overview

sf-data-warehouse ingests seven public San Francisco datasets into an append-only Parquet raw zone, precomputes spatial attributes into a derived zone, loads both into a rebuildable warehouse, and produces published exports and an LLM context pack. The README documents the main pipeline and dbt layers; source-index references support the shown internal delegations. Several implementation details are unsampled, so their relationships are omitted unless documented.

Main entry points: [`ingestion/raw_zone.py`](https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/raw_zone.py) (Raw Parquet zone), [`tools/context_pack/generate.py`](https://github.com/mp321/sf-data-warehouse/blob/main/tools/context_pack/generate.py) (Context pack generator), [`ingestion/spatial.py`](https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/spatial.py) (Spatial precompute), [`ingestion/derived_zone.py`](https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/derived_zone.py) (Derived Parquet zone)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Ingestion and storage"]
  node_registry["Dataset registry"]
  node_ingest_run["Dataset ingestion<br/>[ingest.py]"]
  node_raw[("Raw Parquet zone<br/>[raw_zone.py]")]
  node_remote["Object storage access<br/>[remote.py]"]
end

subgraph group_spatial["Spatial processing"]
  node_spatial_run["Spatial precompute<br/>[spatial.py]"]
  node_point_h3["Point H3 cells<br/>[h3_points.py]"]
  node_boundaries["Boundary membership<br/>[boundaries.py]"]
  node_geometry["Geometry operations<br/>[geometry.py]"]
  node_population["Population processing<br/>[population.py]"]
  node_derived_state["Derived state planning<br/>[derived_state.py]"]
  node_derived[("Derived Parquet zone<br/>[derived_zone.py]")]
end

subgraph group_warehouse["Warehouse modeling"]
  node_load["Warehouse loader<br/>[load.py]"]
  node_staging["Staging models"]
  node_intermediate["Activity intermediate"]
  node_marts["Analytics marts"]
end

subgraph group_assurance["Pipeline assurance"]
  node_check_derived["Derived-zone check<br/>[check_derived.py]"]
  node_check_snapshots["Snapshot check<br/>[check_snapshots.py]"]
  node_check_runs["Run reconciliation<br/>[check_runs.py]"]
  node_prune["Raw-zone retention<br/>[prune_raw.py]"]
end

subgraph group_outputs["Consumer outputs"]
  node_export["Parquet publisher<br/>[export.py]"]
  node_pack_generate["Context pack generator<br/>[generate.py]"]
  node_pack_inputs["Pack data inputs<br/>[pack_inputs.py]"]
  node_pack_profile["Pack profiling<br/>[pack_profile.py]"]
  node_pack_prose["Pack prose<br/>[pack_prose.py]"]
  node_pack_render["Pack rendering<br/>[pack_render.py]"]
  node_pack_target["Pack targets<br/>[pack_target.py]"]
end

node_datasf(("DataSF and Census"))

node_datasf -->|"provides datasets"| node_ingest_run
node_registry -->|"configures fetch"| node_ingest_run
node_ingest_run -->|"writes records"| node_raw
node_raw -->|"uses storage access"| node_remote
node_raw -->|"supplies raw data"| node_spatial_run
node_spatial_run -->|"builds point cells"| node_point_h3
node_spatial_run -->|"builds memberships"| node_boundaries
node_spatial_run -->|"computes population"| node_population
node_spatial_run -->|"plans recomputation"| node_derived_state
node_spatial_run -->|"writes spatial tables"| node_derived
node_point_h3 -->|"reads points"| node_raw
node_boundaries -->|"uses geometry"| node_geometry
node_derived -->|"uses storage access"| node_remote
node_raw -->|"provides raw tables"| node_load
node_derived -->|"provides spatial tables"| node_load
node_registry -->|"configures datasets"| node_load
node_load -->|"materializes inputs"| node_staging
node_staging -->|"feeds activity model"| node_intermediate
node_intermediate -->|"feeds analytics"| node_marts
node_raw -->|"checks input freshness"| node_check_derived
node_derived -->|"checks derived state"| node_check_derived
node_raw -->|"checks partitions"| node_check_snapshots
node_raw -->|"reconciles manifests"| node_check_runs
node_raw -->|"prunes eligible data"| node_prune
node_check_snapshots -->|"proves snapshot state"| node_prune
node_marts -->|"exports Parquet"| node_export
node_marts -->|"describes warehouse"| node_pack_generate
node_export -->|"supplies published metadata"| node_pack_generate
node_pack_generate -->|"derives source facts"| node_pack_inputs
node_pack_generate -->|"uses profiling"| node_pack_profile
node_pack_generate -->|"uses prose helpers"| node_pack_prose
node_pack_generate -->|"renders content"| node_pack_render
node_pack_generate -->|"selects targets"| node_pack_target
node_registry -->|"supplies registry data"| node_pack_inputs

click node_registry "https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/dataset_registry.py"
click node_ingest_run "https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/ingest.py"
click node_raw "https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/raw_zone.py"
click node_remote "https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/remote.py"
click node_spatial_run "https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/spatial.py"
click node_point_h3 "https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/h3_points.py"
click node_boundaries "https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/boundaries.py"
click node_geometry "https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/geometry.py"
click node_population "https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/population.py"
click node_derived_state "https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/derived_state.py"
click node_derived "https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/derived_zone.py"
click node_load "https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/load.py"
click node_staging "https://github.com/mp321/sf-data-warehouse/tree/main/dbt/models/staging"
click node_intermediate "https://github.com/mp321/sf-data-warehouse/blob/main/dbt/models/intermediate/int_point_activity.sql"
click node_marts "https://github.com/mp321/sf-data-warehouse/tree/main/dbt/models/marts"
click node_check_derived "https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/check_derived.py"
click node_check_snapshots "https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/check_snapshots.py"
click node_check_runs "https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/check_runs.py"
click node_prune "https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/prune_raw.py"
click node_export "https://github.com/mp321/sf-data-warehouse/blob/main/publish/export.py"
click node_pack_generate "https://github.com/mp321/sf-data-warehouse/blob/main/tools/context_pack/generate.py"
click node_pack_inputs "https://github.com/mp321/sf-data-warehouse/blob/main/tools/context_pack/pack_inputs.py"
click node_pack_profile "https://github.com/mp321/sf-data-warehouse/blob/main/tools/context_pack/pack_profile.py"
click node_pack_prose "https://github.com/mp321/sf-data-warehouse/blob/main/tools/context_pack/pack_prose.py"
click node_pack_render "https://github.com/mp321/sf-data-warehouse/blob/main/tools/context_pack/pack_render.py"
click node_pack_target "https://github.com/mp321/sf-data-warehouse/blob/main/tools/context_pack/pack_target.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_registry,node_ingest_run,node_raw,node_remote toneBlue
class node_spatial_run,node_point_h3,node_boundaries,node_geometry,node_population,node_derived_state,node_derived toneAmber
class node_load,node_staging,node_intermediate,node_marts toneMint
class node_check_derived,node_check_snapshots,node_check_runs,node_prune toneRose
class node_export,node_pack_generate,node_pack_inputs,node_pack_profile,node_pack_prose,node_pack_render,node_pack_target,node_datasf toneIndigo
```

## Components

### Ingestion and storage

- [Dataset registry](https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/dataset_registry.py): `ingestion/dataset_registry.py`
- [Dataset ingestion](https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/ingest.py): `ingestion/ingest.py`
- [Raw Parquet zone](https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/raw_zone.py): `ingestion/raw_zone.py`
- [Object storage access](https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/remote.py): `ingestion/remote.py`

### Spatial processing

- [Spatial precompute](https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/spatial.py): `ingestion/spatial.py`
- [Point H3 cells](https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/h3_points.py): `ingestion/h3_points.py`
- [Boundary membership](https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/boundaries.py): `ingestion/boundaries.py`
- [Geometry operations](https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/geometry.py): `ingestion/geometry.py`
- [Population processing](https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/population.py): `ingestion/population.py`
- [Derived state planning](https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/derived_state.py): `ingestion/derived_state.py`
- [Derived Parquet zone](https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/derived_zone.py): `ingestion/derived_zone.py`

### Warehouse modeling

- [Warehouse loader](https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/load.py): `ingestion/load.py`
- [Staging models](https://github.com/mp321/sf-data-warehouse/tree/main/dbt/models/staging): `dbt/models/staging`
- [Activity intermediate](https://github.com/mp321/sf-data-warehouse/blob/main/dbt/models/intermediate/int_point_activity.sql): `dbt/models/intermediate/int_point_activity.sql`
- [Analytics marts](https://github.com/mp321/sf-data-warehouse/tree/main/dbt/models/marts): `dbt/models/marts`

### Pipeline assurance

- [Derived-zone check](https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/check_derived.py): `ingestion/check_derived.py`
- [Snapshot check](https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/check_snapshots.py): `ingestion/check_snapshots.py`
- [Run reconciliation](https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/check_runs.py): `ingestion/check_runs.py`
- [Raw-zone retention](https://github.com/mp321/sf-data-warehouse/blob/main/ingestion/prune_raw.py): `ingestion/prune_raw.py`

### Consumer outputs

- [Parquet publisher](https://github.com/mp321/sf-data-warehouse/blob/main/publish/export.py): `publish/export.py`
- [Context pack generator](https://github.com/mp321/sf-data-warehouse/blob/main/tools/context_pack/generate.py): `tools/context_pack/generate.py`
- [Pack data inputs](https://github.com/mp321/sf-data-warehouse/blob/main/tools/context_pack/pack_inputs.py): `tools/context_pack/pack_inputs.py`
- [Pack profiling](https://github.com/mp321/sf-data-warehouse/blob/main/tools/context_pack/pack_profile.py): `tools/context_pack/pack_profile.py`
- [Pack prose](https://github.com/mp321/sf-data-warehouse/blob/main/tools/context_pack/pack_prose.py): `tools/context_pack/pack_prose.py`
- [Pack rendering](https://github.com/mp321/sf-data-warehouse/blob/main/tools/context_pack/pack_render.py): `tools/context_pack/pack_render.py`
- [Pack targets](https://github.com/mp321/sf-data-warehouse/blob/main/tools/context_pack/pack_target.py): `tools/context_pack/pack_target.py`

### Other components

- **DataSF and Census**

## Connections

- DataSF and Census → Dataset ingestion: provides datasets (evidence: `README.md`)
- Dataset registry → Dataset ingestion: configures fetch (evidence: `ingestion/ingest.py`)
- Dataset ingestion → Raw Parquet zone: writes records (evidence: `README.md`)
- Raw Parquet zone → Object storage access: uses storage access (evidence: `ingestion/raw_zone.py`)
- Raw Parquet zone → Spatial precompute: supplies raw data (evidence: `README.md`)
- Spatial precompute → Point H3 cells: builds point cells (evidence: `ingestion/spatial.py`)
- Spatial precompute → Boundary membership: builds memberships (evidence: `ingestion/spatial.py`)
- Spatial precompute → Population processing: computes population (evidence: `ingestion/spatial.py`)
- Spatial precompute → Derived state planning: plans recomputation (evidence: `ingestion/spatial.py`)
- Spatial precompute → Derived Parquet zone: writes spatial tables (evidence: `README.md`)
- Point H3 cells → Raw Parquet zone: reads points (evidence: `ingestion/h3_points.py`)
- Boundary membership → Geometry operations: uses geometry (evidence: `ingestion/boundaries.py`)
- Derived Parquet zone → Object storage access: uses storage access (evidence: `ingestion/derived_zone.py`)
- Raw Parquet zone → Warehouse loader: provides raw tables (evidence: `README.md`)
- Derived Parquet zone → Warehouse loader: provides spatial tables (evidence: `README.md`)
- Dataset registry → Warehouse loader: configures datasets (evidence: `ingestion/load.py`)
- Warehouse loader → Staging models: materializes inputs (evidence: `README.md`)
- Staging models → Activity intermediate: feeds activity model (evidence: `README.md`)
- Activity intermediate → Analytics marts: feeds analytics (evidence: `README.md`)
- Raw Parquet zone → Derived-zone check: checks input freshness (evidence: `ingestion/check_derived.py`)
- Derived Parquet zone → Derived-zone check: checks derived state (evidence: `ingestion/check_derived.py`)
- Raw Parquet zone → Snapshot check: checks partitions (evidence: `ingestion/check_snapshots.py`)
- Raw Parquet zone → Run reconciliation: reconciles manifests (evidence: `ingestion/check_runs.py`)
- Raw Parquet zone → Raw-zone retention: prunes eligible data (evidence: `ingestion/prune_raw.py`)
- Snapshot check → Raw-zone retention: proves snapshot state (evidence: `ingestion/prune_raw.py`)
- Analytics marts → Parquet publisher: exports Parquet (evidence: `README.md`)
- Analytics marts → Context pack generator: describes warehouse (evidence: `README.md`)
- Parquet publisher → Context pack generator: supplies published metadata (evidence: `tools/context_pack/generate.py`)
- Context pack generator → Pack data inputs: derives source facts (evidence: `tools/context_pack/generate.py`)
- Context pack generator → Pack profiling: uses profiling (evidence: `tools/context_pack/generate.py`)
- Context pack generator → Pack prose: uses prose helpers (evidence: `tools/context_pack/generate.py`)
- Context pack generator → Pack rendering: renders content (evidence: `tools/context_pack/generate.py`)
- Context pack generator → Pack targets: selects targets (evidence: `tools/context_pack/generate.py`)
- Dataset registry → Pack data inputs: supplies registry data (evidence: `tools/context_pack/pack_inputs.py`)
