# hsg15/airflow_etl_pipeline architecture

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

- Interactive diagram: https://gitdiagram.com/hsg15/airflow_etl_pipeline
- Repository: https://github.com/hsg15/airflow_etl_pipeline

## Overview

##### Project Type & Purpose
- This is a data-engineering ETL pipeline built with Apache Airflow.
- It fetches JSON from NASA’s APOD HTTP API, transforms selected fields, and loads the results into a PostgreSQL database.
- The pipeline runs locally in Docker Compose during development and is deployed in the cloud via Astronomer on AWS (using RDS for Postgres).

##### File-Structure Analysis
- Top‐level:
- Dockerfile & packages.txt / requirements.txt → custom Airflow image + Python deps
- docker-compose.yml → local Airflow + Postgres services and networks
- airflow_settings.yaml → Astronomer/Airflow config
- dags/etl.py & exampledag.py → DAG definitions (extract, transform, load tasks)
- No front-end; it’s strictly backend/orchestration.
- Key patterns: DAG orchestration (Airflow), containerization (Docker), external API calls, database interactions.

##### README Insights
- Local workflow: `astro dev init` → Docker Compose brings up Airflow scheduler, webserver, worker, triggerer + Postgres.
- Airflow Connections: HTTP hook to NASA API, Postgres hook to DB.
- Cloud workflow: code in Git → `astro deploy` → Astronomer Cloud runs Airflow → connects to AWS RDS.

a. Main Components
- External Services:
- NASA APOD HTTP API
- Astronomer Cloud (Airflow managed service)
- AWS RDS (Postgres)
- Local Dev Environment (Docker Compose):
- Airflow Scheduler, Webserver, Worker, Triggerer (each a container)
- Postgres container
- VS Code / Astro CLI (developer workstation)
- Production Environment (Astronomer/AWS):
- Astronomer-managed Airflow nodes
- RDS Postgres instance
b. Relationships & Data Flow
1. Airflow Scheduler → triggers DAG according to schedule.
2. “extract_apod” task uses HTTP connection → calls NASA API → retrieves JSON.
3. “transform_apod” task processes JSON → extracts relevant fields.
4. “load_data” task uses Postgres connection → inserts/updates data in `nasa_apod_data`.
5. For local dev: all components communicate over Docker network.
6. For cloud: Git push → Astro CLI deploys code → Astronomer Airflow pulls DAGs from repo → connects to AWS RDS.
c. Architectural Patterns & Principles
- ETL Pipeline as code (DAGs)
- Separation of concerns: extract, transform, load tasks are modular.
- Containerization & immutable infrastructure for consistency.
- IaC / GitOps via Astro CLI for deployment.
d. Key Technologies
- Apache Airflow (Python, DAGs, Operators, Hooks)
- Docker & Docker Compose
- PostgreSQL
- Astronomer (Airflow Cloud orchestration)
- AWS RDS

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% Local Development Environment
  subgraph "Local Dev Environment"
    direction TB
    DC["Docker Compose"]:::service
    DC --> ImageBuild["Image Build"]:::service
    subgraph "Custom Airflow Image & Dependencies"
      direction TB
      DF["Dockerfile"]:::service
      PKG["packages.txt"]:::service
      REQ["requirements.txt"]:::service
    end
    ImageBuild --> DF
    ImageBuild --> PKG
    ImageBuild --> REQ

    DC --> Scheduler["Airflow Scheduler"]:::service
    DC --> Webserver["Airflow Webserver"]:::service
    DC --> Worker["Airflow Worker"]:::service
    DC --> Triggerer["Airflow Triggerer"]:::service

    DC --> PostgresLocal["Postgres"]:::data

    subgraph "DAG Definitions"
      direction TB
      ETL["etl.py"]:::service
      ExampleDag["exampledag.py"]:::service
    end

    Scheduler --> ETL
    ETL -->|"extract_apod()"| NASAAPI["NASA APOD HTTP API"]:::ext
    ETL -->|"transform_apod()"| ETL
    ETL -->|"load_data()"| PostgresLocal

  end

  %% Cloud Production Environment
  subgraph "Cloud Prod Environment"
    direction TB
    Git["Git Repository"]:::service
    CLI["Astro CLI"]:::service
    Git --> CLI
    CLI --> Astronomer["Astronomer Cloud (Airflow)"]:::ext
    Astronomer -->|"connects to"| AWSRDS["AWS RDS (Postgres)"]:::ext
    Astronomer -->|"uses config"| Settings["airflow_settings.yaml"]:::service
  end

  %% Documentation
  Docs["README.md"]:::service

  %% Cross-Environment Connections
  Docs --> DC

  %% Styles
  classDef service fill:#D0E6FF,stroke:#0284C7,stroke-width:1px
  classDef data fill:#FFD8BA,stroke:#FF7F11,stroke-width:1px
  classDef ext fill:#D1FAE5,stroke:#059669,stroke-width:1px

  %% Click Events
  click DF "https://github.com/hsg15/airflow_etl_pipeline/tree/main/Proj_ETL_Pipeline_API_Integration/Dockerfile"
  click PKG "https://github.com/hsg15/airflow_etl_pipeline/blob/main/Proj_ETL_Pipeline_API_Integration/packages.txt"
  click REQ "https://github.com/hsg15/airflow_etl_pipeline/blob/main/Proj_ETL_Pipeline_API_Integration/requirements.txt"
  click DC "https://github.com/hsg15/airflow_etl_pipeline/blob/main/Proj_ETL_Pipeline_API_Integration/docker-compose.yml"
  click Settings "https://github.com/hsg15/airflow_etl_pipeline/blob/main/Proj_ETL_Pipeline_API_Integration/airflow_settings.yaml"
  click ETL "https://github.com/hsg15/airflow_etl_pipeline/blob/main/Proj_ETL_Pipeline_API_Integration/dags/etl.py"
  click ExampleDag "https://github.com/hsg15/airflow_etl_pipeline/blob/main/Proj_ETL_Pipeline_API_Integration/dags/exampledag.py"
  click Docs "https://github.com/hsg15/airflow_etl_pipeline/blob/main/Proj_ETL_Pipeline_API_Integration/README.md"
```
