# mlops-talksick/supplychainoptimization architecture

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

- Interactive diagram: https://gitdiagram.com/mlops-talksick/supplychainoptimization
- Repository: https://github.com/mlops-talksick/supplychainoptimization

## Overview

##### Project Identification
- Project Type/Purpose: A supply chain optimization system built to simulate realistic demand data using synthetic data generation, process that data through a robust pipeline (including cleaning, validation, versioning, and feature engineering), and ultimately produce forecast models.
- Use Cases: Demand forecasting, anomaly detection, model monitoring and prediction, and MLOps best practices in data versioning and pipeline orchestration.

##### File Structure for Components
- Data Generation: The “Data_Generation” folder contains scripts (dataGenerator.py, transactionGenerator.py, dataMess.py) that simulate realistic market and transaction conditions.
- Data Pipeline: The “Data_Pipeline” directory holds the core processing code. It includes a Dockerfile, various scripts for validation, preprocessing, logging, DVC versioning, and testing modules – all likely orchestrated by Airflow (with DAGs in the “dags” folder).
- Infrastructure & Deployment: The “infrastructure” and “terraform” directories indicate cloud configuration (e.g., instance groups, load balancers) and deployment automation. This is complemented by various shell scripts in “scripts” for building and deploying Docker images and Airflow servers.
- Cloud Integration: The README and various configuration files (like .env and docker-compose.yaml) stress Google Cloud integration, including storage and GCP-specific DAGs.
- Experiment Tracking: The “mlruns” folder suggests that ML experiment tracking is built into the system.

##### Main Components and Their Interactions
a. Data Generation Layer:
- Components: Synthetic data generators for demand data, transaction logs, and controlled data quality issues.
- Purpose: Generate input data sets simulating commodity trends and store-customer product interactions.
- Flow: Outputs data that gets fed into the data pipeline.

b. Data Pipeline Layer:
- Components: Airflow DAGs (located in the “dags” directory), pre- and post-validation scripts, preprocessing routines, and DVC-based version control.
- Purpose: Ingest raw data (via manual upload or simulated GCP bucket), clean and validate the data, version control with DVC, and then output cleaned and feature-engineered datasets.
- Interaction: Receives data from the Data Generation module and processes it to be consumed by the ML module.

c. ML Models Layer:
- Components: Containerized ML solutions (Dockerfiles, docker-compose, experiments scripts like deepar, lstm, sarima), model prediction and monitoring scripts.
- Purpose: Train forecast models, monitor their performance, and produce predictions.
- Interaction: Consumes processed data from the Data Pipeline. It outputs trained models and predictions, with artifacts tracked in “mlruns.”

d. Infrastructure & Deployment:
- Components: Terraform scripts, additional shell scripts, and container orchestration configurations.
- Purpose: Provision cloud resources (GCP), manage service deployment (e.g., Airflow, ML services), and set up networking with load balancers and instance groups.
- Interaction: Underpins both the Data Pipeline and ML Modules by ensuring the system’s scalable, cloud-ready deployment.

e. Storage & Integration:
- Components: Local file storage, DVC-managed storage, Google Cloud Storage.
- Purpose: Store raw and processed data, version datasets, and hold model artifacts.
- Interaction: Acts as the central hub where data flows between generation, processing, and modeling.

##### Architectural Patterns and Design Principles
- Emphasis on modularity – each main functionality (data generation, pipeline, ML modeling) is maintained in separate directories with its own Docker configurations.
- Use of containerization for consistency (Dockerfiles and docker-compose.yaml for both the ML models and the data pipeline).
- Adoption of MLOps practices: data versioning (via DVC), experiment tracking (mlruns directory), and pipeline orchestration (Airflow DAGs).
- Infrastructure-as-Code with Terraform for reproducible cloud deployments.
- Continuous integration and testing: GitHub workflows, tests in the Data_Pipeline/tests directory, and multiple scripts for validation.

- At the top, designate the “Input Layer” representing data generation and manual or simulated data ingestion (with reference to GCP bucket uploads).
- Next, connect to the “Modeling Layer” which covers ML model training, prediction, and monitoring (including integration with the experiment tracking system).
- Finally, a surrounding “Infrastructure Layer” should encapsulate cloud services, container orchestration (Docker, Kubernetes if applicable), networking, and load balancing as set up by Terraform.
- Don’t neglect to illustrate monitoring & alerting functionalities (email alerts, logs) as part of operational feedback.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Input Layer"
        DG["Synthetic Data Generation (dataGenerator.py, transactionGenerator.py, dataMess.py)"]:::datagen
        CI1["Cloud Config (.env)"]:::cloud
        CI2["Root Compose (docker-compose.yaml)"]:::cloud
    end

    subgraph "Processing Layer"
        DP["Data Pipeline (Airflow, DVC, Preprocessing, Validation)"]:::pipeline
        DAGs["Airflow DAGs"]:::pipeline
    end

    subgraph "Storage & Integration"
        Storage["Data & Model Storage (Local, DVC, GCP Storage)"]:::storage
    end

    subgraph "Modeling Layer"
        ML["ML Models & Experimentation (Training, Prediction, Monitoring)"]:::ml
        EXP["Experiment Tracking (mlruns)"]:::tracking
    end

    subgraph "Infrastructure & Deployment"
        Infra1["Terraform Config (Terraform files)"]:::infra
        Infra2["Deployment Scripts (infrastructure)"]:::infra
    end

    %% Data Flow Connections
    DG -->|"generates"| DP
    CI1 -->|"configures"| DP
    CI2 -->|"configures"| DP
    DP -->|"runsWorkflows"| DAGs
    DP -->|"sendsProcessedData"| ML
    DP -->|"storesData"| Storage
    ML -->|"storesModels"| Storage
    ML -->|"logsExperiments"| EXP

    %% Infrastructure Support
    Infra1 -->|"provisions"| DP
    Infra2 -->|"supports"| DP
    Infra1 -->|"provisions"| ML
    Infra2 -->|"supports"| ML

    %% Click Events
    click DG "https://github.com/mlops-talksick/supplychainoptimization/tree/main/Data_Generation/"
    click DP "https://github.com/mlops-talksick/supplychainoptimization/tree/main/Data_Pipeline/"
    click DAGs "https://github.com/mlops-talksick/supplychainoptimization/tree/main/dags/"
    click CI1 "https://github.com/mlops-talksick/supplychainoptimization/blob/main/.env"
    click CI2 "https://github.com/mlops-talksick/supplychainoptimization/blob/main/docker-compose.yaml"
    click ML "https://github.com/mlops-talksick/supplychainoptimization/tree/main/ML_Models/"
    click Infra1 "https://github.com/mlops-talksick/supplychainoptimization/tree/main/terraform/"
    click Infra2 "https://github.com/mlops-talksick/supplychainoptimization/tree/main/infrastructure/"
    click EXP "https://github.com/mlops-talksick/supplychainoptimization/tree/main/mlruns/"

    %% Styles
    classDef datagen fill:#f9f,stroke:#333,stroke-width:2px;
    classDef pipeline fill:#cff,stroke:#333,stroke-width:2px;
    classDef ml fill:#fcf,stroke:#333,stroke-width:2px;
    classDef infra fill:#ffc,stroke:#333,stroke-width:2px;
    classDef storage fill:#cfc,stroke:#333,stroke-width:2px;
    classDef tracking fill:#ccf,stroke:#333,stroke-width:2px;
    classDef cloud fill:#ff9,stroke:#333,stroke-width:2px;
```
