# ocamposfaria/bees-data-engineering-case architecture

> Architecture diagram of the GitHub repository ocamposfaria/bees-data-engineering-case, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ocamposfaria/bees-data-engineering-case
- Repository: https://github.com/ocamposfaria/bees-data-engineering-case

## Overview

##### Project type and purpose
- This is a full-stack, containerized data engineering pipeline built with a medallion (bronze/silver/gold) architecture.
- Purpose: extract brewery data from the Open Brewery DB API, store it in an object store, transform it via Spark, and expose it through an AI-powered Streamlit dashboard.

##### File structure
- Top-level folders:
- airflow/ – orchestrates data extraction and ELT tasks
- minio/ – object storage service for Bronze/Silver/Gold layers
- spark/ – PySpark notebooks and runtime for transformations
- streamlit/ – interactive chat-based visualization app
- Configuration & orchestration artifacts: Dockerfiles and docker-compose YAML for each service, a shared Docker network, and a `.env` template.

##### Extract architecture insights from README
- Orchestration: Apache Airflow manages ELT DAGs (`elt_001_breweries.py`).
- Storage: MinIO buckets represent data lake layers:
- Bronze: raw JSON
- Silver: cleaned & partitioned Parquet
- Gold: aggregated Parquet & metadata
- Processing: PySpark notebooks for each layer in the `spark/notebooks` subfolders.
- Visualization: Streamlit app that pulls Gold metadata and integrates with the OpenAI API for chat queries.

##### Main components & relationships
a. External Services
- Open Brewery DB API (data source)
- OpenAI API (AI assistant in Streamlit)
b. Orchestration & Ingestion
- Airflow Scheduler & Webserver (Python container)
- DAG triggers `requests.get` tasks → writes raw JSON to MinIO Bronze bucket
c. Storage
- MinIO object store exposed on port 9001
- Bronze, Silver, Gold buckets
d. Processing
- Spark Master & Worker launched in Docker
- `start-spark.sh` initializes cluster
- Notebooks read Bronze data → write Silver → read Silver → write Gold
e. Visualization
- Streamlit app (port 8501)
- Reads Gold metadata from MinIO or local mount
- Sends user queries to OpenAI, visualizes responses

##### Architectural patterns & principles
- Medallion architecture: clear separation of data quality layers
- Container-per-service: each major component in its own Docker container
- Event-driven ELT: Airflow DAGs trigger periodic ingestion & transformations
- Modular & extensible: each layer’s logic isolated in notebooks and Python classes

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Services
    OBAPI["Open Brewery DB API"]:::external
    OpenAI["OpenAI API"]:::external

    %% Orchestration & Ingestion
    subgraph "Orchestration (Airflow)"
        AF["Airflow (Scheduler & Webserver)"]:::orchestration
        DAG["DAG: elt_001_breweries.py"]:::orchestration
        Tasks["Task Module: tasks_elt_001_breweries.py"]:::orchestration
        ClassBrew["Class: breweries.py"]:::orchestration
        ClassMinio["Class: minio.py"]:::orchestration
        Requirements["requirements.txt"]:::orchestration
    end

    %% Storage Layer
    subgraph "Storage (MinIO)"
        MinIO["MinIO Object Store"]:::storage
        Bronze["Bronze Bucket (raw JSON)"]:::storage
        Silver["Silver Bucket (Parquet)"]:::storage
        Gold["Gold Bucket (Aggregated)"]:::storage
    end

    %% Processing Layer
    subgraph "Processing (Spark Cluster)"
        SparkCluster["Spark Master & Worker"]:::processing
        subgraph "Notebooks"
            BNB["bronze_001_breweries.txt"]:::processing
            SNB["silver_001_breweries.ipynb"]:::processing
            GNBipynb["gold_001_breweries.ipynb"]:::processing
            GNBjson["gold_001_breweries.json"]:::processing
        end
    end

    %% Visualization Layer
    subgraph "Visualization (Streamlit)"
        StreamlitApp["Streamlit Dashboard"]:::viz
    end

    %% Environment Configuration
    subgraph "Configuration"
        EnvConfig["config-example.env"]:::env
        Gitignore[".gitignore"]:::env
        Readme["README.md"]:::env
    end

    %% Data Flow
    OBAPI -->|"HTTP"| AF
    AF -->|"S3 API"| Bronze
    Bronze -->|"read JSON"| SparkCluster
    SparkCluster -->|"write Parquet"| Silver
    Silver -->|"read Parquet"| SparkCluster
    SparkCluster -->|"write Parquet"| Gold
    Gold -->|"S3 API"| StreamlitApp
    StreamlitApp -->|"OpenAI API"| OpenAI

    %% Airflow Component Flow
    AF --> DAG
    DAG --> Tasks
    DAG --> ClassBrew
    DAG --> ClassMinio
    AF --> Requirements

    %% Click Events for Orchestration
    click AF "https://github.com/ocamposfaria/bees-data-engineering-case/tree/master/airflow/Dockerfile"
    click AF "https://github.com/ocamposfaria/bees-data-engineering-case/blob/master/airflow/docker-compose.airflow.yaml"
    click DAG "https://github.com/ocamposfaria/bees-data-engineering-case/blob/master/airflow/dags/elt_001_breweries.py"
    click Tasks "https://github.com/ocamposfaria/bees-data-engineering-case/blob/master/airflow/dags/tasks/tasks_elt_001_breweries.py"
    click ClassBrew "https://github.com/ocamposfaria/bees-data-engineering-case/blob/master/airflow/dags/classes/breweries.py"
    click ClassMinio "https://github.com/ocamposfaria/bees-data-engineering-case/blob/master/airflow/dags/classes/minio.py"
    click Requirements "https://github.com/ocamposfaria/bees-data-engineering-case/blob/master/airflow/requirements.txt"

    %% Click Events for Storage
    click MinIO "https://github.com/ocamposfaria/bees-data-engineering-case/blob/master/minio/docker-compose.minio.yaml"

    %% Click Events for Processing
    click SparkCluster "https://github.com/ocamposfaria/bees-data-engineering-case/tree/master/spark/Dockerfile"
    click SparkCluster "https://github.com/ocamposfaria/bees-data-engineering-case/blob/master/spark/docker-compose.spark.yaml"
    click SparkCluster "https://github.com/ocamposfaria/bees-data-engineering-case/blob/master/spark/start-spark.sh"
    click BNB "https://github.com/ocamposfaria/bees-data-engineering-case/blob/master/spark/notebooks/1_bronze/bronze_001_breweries.txt"
    click SNB "https://github.com/ocamposfaria/bees-data-engineering-case/blob/master/spark/notebooks/2_silver/silver_001_breweries.ipynb"
    click GNBipynb "https://github.com/ocamposfaria/bees-data-engineering-case/blob/master/spark/notebooks/3_gold/gold_001_breweries.ipynb"
    click GNBjson "https://github.com/ocamposfaria/bees-data-engineering-case/blob/master/spark/notebooks/3_gold/gold_001_breweries.json"

    %% Click Events for Visualization
    click StreamlitApp "https://github.com/ocamposfaria/bees-data-engineering-case/tree/master/streamlit/Dockerfile"
    click StreamlitApp "https://github.com/ocamposfaria/bees-data-engineering-case/blob/master/streamlit/docker-compose.streamlit.yaml"
    click StreamlitApp "https://github.com/ocamposfaria/bees-data-engineering-case/blob/master/streamlit/main.py"
    click StreamlitApp "https://github.com/ocamposfaria/bees-data-engineering-case/blob/master/streamlit/requirements.txt"
    click StreamlitApp "https://github.com/ocamposfaria/bees-data-engineering-case/blob/master/streamlit/gold_metadata/gold_001_breweries.json"

    %% Click Events for Configuration
    click EnvConfig "https://github.com/ocamposfaria/bees-data-engineering-case/blob/master/config-example.env"
    click Gitignore "https://github.com/ocamposfaria/bees-data-engineering-case/blob/master/.gitignore"
    click Readme "https://github.com/ocamposfaria/bees-data-engineering-case/blob/master/README.md"

    %% Styles
    classDef orchestration fill:#ddeeff,stroke:#6699cc,stroke-width:2px
    classDef storage fill:#e0f7e9,stroke:#34a853,stroke-width:2px
    classDef processing fill:#ffe8cc,stroke:#f5a623,stroke-width:2px
    classDef viz fill:#f3e5f5,stroke:#9c27b0,stroke-width:2px
    classDef external fill:#f2f2f2,stroke:#999999,stroke-width:2px,stroke-dasharray: 5 5
    classDef env fill:#fff4e5,stroke:#ffaa00,stroke-width:2px,stroke-dasharray: 2 2
```
