# amitzore71/airflow-feature-engineering architecture

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

- Interactive diagram: https://gitdiagram.com/amitzore71/airflow-feature-engineering
- Repository: https://github.com/amitzore71/airflow-feature-engineering

## Overview

#### Purpose and Entry Points
This is an Airflow-orchestrated feature-engineering platform for recommendation systems. It transforms raw/synthetic events into contract-governed offline features, validates them, selectively publishes serving features to Redis, monitors their quality, and signals MLflow retraining. Operational entry points are the DAGs in `airflow/dags/`, especially `airflow/dags/dag_feature_build.py`; local stack startup is defined by `docker-compose.yml` and `Dockerfile.airflow`.

#### Contract and Configuration Boundary
The feature contract is the central compatibility boundary between generation, validation, publishing, and monitoring. It specifies feature schema, constraints, freshness, leakage rules, and publish policy in `contracts/recommendation_features.yaml`. Contract parsing and typed representation live in `src/contracts/loader.py` and `src/contracts/models.py`; shared runtime settings are centralized in `src/config.py`.

#### Build and Offline Feature Store
The build stage generates/consumes raw events and materializes offline feature snapshots. `airflow/dags/dag_feature_build.py` orchestrates the workflow, delegating transformation/materialization to `src/build/feature_builder.py` and shared DuckDB transformation SQL in `sql/feature_build.sql`. Raw inputs, offline Parquet outputs, and local online-state files are separated under `data/raw/`, `data/offline/`, and `data/online/`. DuckDB is the offline compute/store runtime; Parquet is the durable interchange format.

#### Validation and Promotion Gate
Validation is an explicit gate before online promotion. `airflow/dags/dag_feature_validate.py` runs contract quality and leakage checks from `src/validation/checks.py`, including SQL leakage validation in `sql/validation_leakage.sql`. Validation results/checkpoints are persisted under `artifacts/validation/`; a failed contract blocks downstream publishing rather than allowing an unsafe partial promotion.

#### Online Publish and Serving Parity
The publish path moves approved offline features into Redis with canary and rollback decisioning. `airflow/dags/dag_feature_publish.py` coordinates `src/publish/decision.py` and `src/publish/online_store.py`; `src/parity/checker.py` verifies offline/online feature equivalence. Publish artifacts reside in `artifacts/publish/`. Redis is the online retrieval service boundary; recommendation serving is downstream and not implemented in this repository.

#### Monitoring and Retraining Control Loop
Post-publish monitoring evaluates freshness and distribution drift. `airflow/dags/dag_feature_monitor.py` invokes `src/monitor/freshness.py` and `src/drift/metrics.py`, writing signals to `artifacts/monitoring/`. `airflow/dags/dag_retrain_trigger.py` uses `src/triggers/retrain.py` to turn sustained threshold breaches into MLflow retraining signals, with trigger state in `artifacts/triggers/`. MLflow is an external training-system integration, not the feature pipeline’s execution engine.

#### Historical Recovery and Orchestration
Airflow owns scheduling, dependencies, retries, and stage isolation across build, validation, publish, monitoring, retraining, and historical rebuilds. `airflow/dags/dag_backfill_features.py` drives deterministic reconstruction using `src/backfill/deterministic.py`, producing historical artifacts under `artifacts/backfill/`. `src/tasks.py` is the likely shared task-level integration layer across DAGs. Metadata artifacts and contracts decouple stages so a stage can be audited or rerun without changing the core feature specification.

Main entry points: [`src/build/feature_builder.py`](https://github.com/amitzore71/airflow-feature-engineering/blob/main/src/build/feature_builder.py) (Feature builder), [`src/validation/checks.py`](https://github.com/amitzore71/airflow-feature-engineering/blob/main/src/validation/checks.py) (Quality & leakage checks), [`src/contracts/loader.py`](https://github.com/amitzore71/airflow-feature-engineering/blob/main/src/contracts/loader.py) (Contract loader & models), [`src/monitor/freshness.py`](https://github.com/amitzore71/airflow-feature-engineering/blob/main/src/monitor/freshness.py) (Freshness & drift analysis)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_orchestration["Airflow orchestration"]
  node_airflow{{"Airflow DAG runtime<br/>orchestrator"}}
  node_shared_tasks["Shared task layer<br/>task integration<br/>[tasks.py]"]
end

subgraph group_contract["Contract boundary"]
  node_feature_contract["Recommendation feature contract<br/>YAML contract"]
  node_contract_loader["Contract loader &amp; models<br/>typed contract API<br/>[loader.py]"]
  node_runtime_config["Runtime settings<br/>configuration<br/>[config.py]"]
end

subgraph group_offline["Offline build"]
  node_build_dag["Feature build DAG<br/>Airflow DAG"]
  node_feature_builder["Feature builder<br/>build service<br/>[feature_builder.py]"]
  node_build_sql["Feature transformation SQL<br/>DuckDB SQL<br/>[feature_build.sql]"]
  node_raw_events[("Raw events<br/>input data")]
  node_offline_features[("Offline feature snapshots<br/>Parquet feature store")]
end

subgraph group_promotion["Validation &amp; serving"]
  node_validation_dag["Feature validation DAG<br/>Airflow DAG"]
  node_validation_checks["Quality &amp; leakage checks<br/>validation service<br/>[checks.py]"]
  node_leakage_sql["Leakage validation SQL<br/>DuckDB SQL"]
  node_validation_artifacts[("Validation checkpoints<br/>audit artifacts")]
  node_publish_dag["Feature publish DAG<br/>Airflow DAG"]
  node_publish_decision["Canary &amp; rollback decisions<br/>promotion policy<br/>[decision.py]"]
  node_online_store["Redis publisher<br/>online store adapter<br/>[online_store.py]"]
  node_parity_checker["Offline/online parity checker<br/>verification service<br/>[checker.py]"]
  node_redis[("Redis serving features<br/>external online store")]
end

subgraph group_control["Monitoring &amp; recovery"]
  node_monitor_dag["Feature monitor DAG<br/>Airflow DAG"]
  node_monitoring["Freshness &amp; drift analysis<br/>monitoring service<br/>[freshness.py]"]
  node_retrain_trigger["MLflow retrain trigger<br/>external integration<br/>[retrain.py]"]
  node_backfill_dag["Historical backfill DAG<br/>Airflow DAG"]
  node_deterministic_backfill["Deterministic reconstruction<br/>backfill service<br/>[deterministic.py]"]
end

node_airflow -->|"runs shared tasks"| node_shared_tasks
node_build_dag -->|"orchestrates"| node_feature_builder
node_feature_builder -->|"reads"| node_raw_events
node_feature_builder -->|"executes"| node_build_sql
node_feature_builder -->|"materializes Parquet"| node_offline_features
node_feature_contract -->|"parsed as typed policy"| node_contract_loader
node_contract_loader -.->|"governs schema"| node_feature_builder
node_validation_dag -->|"orchestrates"| node_validation_checks
node_offline_features -->|"validates"| node_validation_checks
node_contract_loader -->|"supplies rules"| node_validation_checks
node_leakage_sql -->|"used for leakage checks"| node_validation_checks
node_validation_checks -->|"writes results"| node_validation_artifacts
node_validation_artifacts -->|"approval gate"| node_publish_dag
node_publish_dag -->|"orchestrates"| node_publish_decision
node_offline_features -->|"comparison source"| node_parity_checker
node_publish_decision -->|"approved canary/promotion"| node_online_store
node_online_store -->|"publishes features"| node_redis
node_redis -->|"comparison target"| node_parity_checker
node_monitor_dag -->|"orchestrates"| node_monitoring
node_redis -->|"observes serving state"| node_monitoring
node_monitoring -->|"threshold breaches"| node_retrain_trigger
node_backfill_dag -->|"orchestrates"| node_deterministic_backfill
node_deterministic_backfill -->|"rebuilds history"| node_offline_features
node_runtime_config -.->|"configures runtime"| node_airflow

click node_shared_tasks "https://github.com/amitzore71/airflow-feature-engineering/blob/main/src/tasks.py"
click node_feature_contract "https://github.com/amitzore71/airflow-feature-engineering/blob/main/contracts/recommendation_features.yaml"
click node_contract_loader "https://github.com/amitzore71/airflow-feature-engineering/blob/main/src/contracts/loader.py"
click node_runtime_config "https://github.com/amitzore71/airflow-feature-engineering/blob/main/src/config.py"
click node_build_dag "https://github.com/amitzore71/airflow-feature-engineering/blob/main/airflow/dags/dag_feature_build.py"
click node_feature_builder "https://github.com/amitzore71/airflow-feature-engineering/blob/main/src/build/feature_builder.py"
click node_build_sql "https://github.com/amitzore71/airflow-feature-engineering/blob/main/sql/feature_build.sql"
click node_validation_dag "https://github.com/amitzore71/airflow-feature-engineering/blob/main/airflow/dags/dag_feature_validate.py"
click node_validation_checks "https://github.com/amitzore71/airflow-feature-engineering/blob/main/src/validation/checks.py"
click node_leakage_sql "https://github.com/amitzore71/airflow-feature-engineering/blob/main/sql/validation_leakage.sql"
click node_publish_dag "https://github.com/amitzore71/airflow-feature-engineering/blob/main/airflow/dags/dag_feature_publish.py"
click node_publish_decision "https://github.com/amitzore71/airflow-feature-engineering/blob/main/src/publish/decision.py"
click node_online_store "https://github.com/amitzore71/airflow-feature-engineering/blob/main/src/publish/online_store.py"
click node_parity_checker "https://github.com/amitzore71/airflow-feature-engineering/blob/main/src/parity/checker.py"
click node_monitor_dag "https://github.com/amitzore71/airflow-feature-engineering/blob/main/airflow/dags/dag_feature_monitor.py"
click node_monitoring "https://github.com/amitzore71/airflow-feature-engineering/blob/main/src/monitor/freshness.py"
click node_retrain_trigger "https://github.com/amitzore71/airflow-feature-engineering/blob/main/src/triggers/retrain.py"
click node_backfill_dag "https://github.com/amitzore71/airflow-feature-engineering/blob/main/airflow/dags/dag_backfill_features.py"
click node_deterministic_backfill "https://github.com/amitzore71/airflow-feature-engineering/blob/main/src/backfill/deterministic.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_airflow,node_shared_tasks toneBlue
class node_feature_contract,node_contract_loader,node_runtime_config toneAmber
class node_build_dag,node_feature_builder,node_build_sql,node_raw_events,node_offline_features toneMint
class node_validation_dag,node_validation_checks,node_leakage_sql,node_validation_artifacts,node_publish_dag,node_publish_decision,node_online_store,node_parity_checker,node_redis toneRose
class node_monitor_dag,node_monitoring,node_retrain_trigger,node_backfill_dag,node_deterministic_backfill toneIndigo
```

## Components

### Airflow orchestration

- **Airflow DAG runtime**: orchestrator · Schedules, isolates, and retries pipeline stages.
- [Shared task layer](https://github.com/amitzore71/airflow-feature-engineering/blob/main/src/tasks.py): task integration · `src/tasks.py`

### Contract boundary

- [Recommendation feature contract](https://github.com/amitzore71/airflow-feature-engineering/blob/main/contracts/recommendation_features.yaml): YAML contract · Defines schema, constraints, freshness, leakage, and publish policy. · `contracts/recommendation_features.yaml`
- [Contract loader & models](https://github.com/amitzore71/airflow-feature-engineering/blob/main/src/contracts/loader.py): typed contract API · `src/contracts/loader.py`
- [Runtime settings](https://github.com/amitzore71/airflow-feature-engineering/blob/main/src/config.py): configuration · `src/config.py`

### Offline build

- [Feature build DAG](https://github.com/amitzore71/airflow-feature-engineering/blob/main/airflow/dags/dag_feature_build.py): Airflow DAG · `airflow/dags/dag_feature_build.py`
- [Feature builder](https://github.com/amitzore71/airflow-feature-engineering/blob/main/src/build/feature_builder.py): build service · `src/build/feature_builder.py`
- [Feature transformation SQL](https://github.com/amitzore71/airflow-feature-engineering/blob/main/sql/feature_build.sql): DuckDB SQL · `sql/feature_build.sql`
- **Raw events**: input data
- **Offline feature snapshots**: Parquet feature store · Durable offline interchange snapshots.

### Validation & serving

- [Feature validation DAG](https://github.com/amitzore71/airflow-feature-engineering/blob/main/airflow/dags/dag_feature_validate.py): Airflow DAG · `airflow/dags/dag_feature_validate.py`
- [Quality & leakage checks](https://github.com/amitzore71/airflow-feature-engineering/blob/main/src/validation/checks.py): validation service · `src/validation/checks.py`
- [Leakage validation SQL](https://github.com/amitzore71/airflow-feature-engineering/blob/main/sql/validation_leakage.sql): DuckDB SQL · `sql/validation_leakage.sql`
- **Validation checkpoints**: audit artifacts · Failed results block online promotion.
- [Feature publish DAG](https://github.com/amitzore71/airflow-feature-engineering/blob/main/airflow/dags/dag_feature_publish.py): Airflow DAG · `airflow/dags/dag_feature_publish.py`
- [Canary & rollback decisions](https://github.com/amitzore71/airflow-feature-engineering/blob/main/src/publish/decision.py): promotion policy · `src/publish/decision.py`
- [Redis publisher](https://github.com/amitzore71/airflow-feature-engineering/blob/main/src/publish/online_store.py): online store adapter · `src/publish/online_store.py`
- [Offline/online parity checker](https://github.com/amitzore71/airflow-feature-engineering/blob/main/src/parity/checker.py): verification service · `src/parity/checker.py`
- **Redis serving features**: external online store · Serving consumers are outside this repository.

### Monitoring & recovery

- [Feature monitor DAG](https://github.com/amitzore71/airflow-feature-engineering/blob/main/airflow/dags/dag_feature_monitor.py): Airflow DAG · `airflow/dags/dag_feature_monitor.py`
- [Freshness & drift analysis](https://github.com/amitzore71/airflow-feature-engineering/blob/main/src/monitor/freshness.py): monitoring service · `src/monitor/freshness.py`
- [MLflow retrain trigger](https://github.com/amitzore71/airflow-feature-engineering/blob/main/src/triggers/retrain.py): external integration · Signals retraining after sustained breaches. · `src/triggers/retrain.py`
- [Historical backfill DAG](https://github.com/amitzore71/airflow-feature-engineering/blob/main/airflow/dags/dag_backfill_features.py): Airflow DAG · `airflow/dags/dag_backfill_features.py`
- [Deterministic reconstruction](https://github.com/amitzore71/airflow-feature-engineering/blob/main/src/backfill/deterministic.py): backfill service · `src/backfill/deterministic.py`

## Connections

- Airflow DAG runtime → Shared task layer: runs shared tasks
- Feature build DAG → Feature builder: orchestrates
- Feature builder → Raw events: reads
- Feature builder → Feature transformation SQL: executes
- Feature builder → Offline feature snapshots: materializes Parquet
- Recommendation feature contract → Contract loader & models: parsed as typed policy
- Contract loader & models → Feature builder: governs schema
- Feature validation DAG → Quality & leakage checks: orchestrates
- Offline feature snapshots → Quality & leakage checks: validates
- Contract loader & models → Quality & leakage checks: supplies rules
- Leakage validation SQL → Quality & leakage checks: used for leakage checks
- Quality & leakage checks → Validation checkpoints: writes results
- Validation checkpoints → Feature publish DAG: approval gate
- Feature publish DAG → Canary & rollback decisions: orchestrates
- Offline feature snapshots → Offline/online parity checker: comparison source
- Canary & rollback decisions → Redis publisher: approved canary/promotion
- Redis publisher → Redis serving features: publishes features
- Redis serving features → Offline/online parity checker: comparison target
- Feature monitor DAG → Freshness & drift analysis: orchestrates
- Redis serving features → Freshness & drift analysis: observes serving state
- Freshness & drift analysis → MLflow retrain trigger: threshold breaches
- Historical backfill DAG → Deterministic reconstruction: orchestrates
- Deterministic reconstruction → Offline feature snapshots: rebuilds history
- Runtime settings → Airflow DAG runtime: configures runtime
