# graviraja/mlops-basics architecture

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

- Interactive diagram: https://gitdiagram.com/graviraja/mlops-basics
- Repository: https://github.com/graviraja/mlops-basics

## Overview

##### Main Components
- Data and Preprocessing Module: Capture code related to data ingestion (data.py files), experimentation (notebooks) and any initial preprocessing.
- Model Training & Inference: Represent the core training (train.py) and inference (inference.py, inference_onnx.py) components. Note that model definitions (model.py) evolve throughout different weeks.
- Experiment Tracking & Logging: Include a dedicated module for Weights & Biases integration as introduced in Week 1.
- Configuration Management: Emphasize the role of Hydra in managing configurations (the configs directories in Week 2 onward).
- Data & Model Versioning: Clearly denote the use of DVC (shown through DVC files and directories) to version both data and models.
- Model Packaging: Create separate nodes for ONNX (Week 4) and Docker (Week 5 and later). For Docker, indicate how container images (via Dockerfile, docker-compose.yml) encapsulate the application.
- CI/CD Pipeline: Highlight the use of GitHub Actions (Week 6) to integrate building, testing, and deployment.
- Container Registry & Cloud Deployments: Mark components for pushing container images (AWS ECR in Week 7) and triggering serverless deployments (AWS Lambda with API Gateway in Week 8).
- Monitoring & Logging: Include the end-stage where logging and monitoring are performed (Week 9 with Kibana, CloudWatch, and Elasticsearch).

##### Relationships and Data Flow
- That configurations are centrally managed (via Hydra) and feed into the training, inference, and packaging modules.
- That after training, versioned models (via DVC) travel to packaging components (ONNX conversion, Dockerization) before being pushed to container registries.
- That CI/CD (triggered by GitHub Actions) automates building container images and deployment to AWS services.
- Finally, connect the deployed services to the Monitoring setup, showing data/feedback loops that help detect issues.

##### Architectural Patterns & Design Principles
- Modularity: Each “week” can be viewed as an evolutionary layer or module that builds upon the previous stage.
- Separation of Concerns: Differentiated components for training, configuration, packaging, deployment, and monitoring.
- Automation & Reproducibility: Emphasize CI/CD pipelines and version control (DVC) that ensure consistency across environments.
- Cloud-Native & Containerization: Underline the move from a local environment to containerized, serverless deployments.

##### Of Key Technologies and Frameworks
- Huggingface Datasets/Transformers, PyTorch Lightning for model building.
- Weights & Biases (W&B) and TorchMetrics for experiment tracking.
- Hydra for managing configurations.
- DVC for data versioning.
- ONNX and ONNXRuntime for model packaging.
- Docker and Docker Compose for containerization.
- GitHub Actions for CI/CD.
- AWS services including ECR, Lambda, API Gateway (for serverless) and S3 (for remote storage in DVC setups).
- Kibana (backed by Elasticsearch and CloudWatch) for monitoring.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data & Preprocessing Layer
    subgraph "Data & Preprocessing Layer"
        A["Data Ingestion"]:::data
    end

    %% Training & Experimentation Layer
    subgraph "Training & Experimentation Layer"
        D["Hydra Config Management"]:::config
        B["Model Training & Inference"]:::compute
        C["W&B Experiment Tracking"]:::tracking
    end

    %% Versioning & Packaging Layer
    subgraph "Versioning & Packaging Layer"
        E["DVC Versioning"]:::version
        F["ONNX Packaging"]:::packaging
        G["Docker Packaging"]:::packaging
    end

    %% CI/CD & Deployment Layer
    subgraph "CI/CD & Deployment Layer"
        H["GitHub Actions CI/CD"]:::ci
        I["AWS Deployment"]:::cloud
    end

    %% Monitoring Layer
    subgraph "Monitoring Layer"
        J["Monitoring & Logging"]:::monitoring
    end

    %% Connections
    A -->|"to_train"| B
    D -->|"config_feeds"| B
    B -->|"logs_to"| C
    B -->|"saves_model_to"| E
    E -->|"converts_to"| F
    E -->|"packages_for"| G
    D -->|"config_feeds"| F
    D -->|"config_feeds"| G
    F -->|"triggers_build"| H
    G -->|"triggers_build"| H
    H -->|"deploys_to"| I
    I -->|"monitored_by"| J
    J -->|"feedback_to"| B

    %% Click Events for Data & Preprocessing Module
    click A "https://github.com/graviraja/mlops-basics/blob/main/week_0_project_setup/data.py"
    click A "https://github.com/graviraja/mlops-basics/blob/main/week_0_project_setup/experimental_notebooks/data_exploration.ipynb"

    %% Click Events for Model Training & Inference
    click B "https://github.com/graviraja/mlops-basics/blob/main/week_0_project_setup/train.py"
    click B "https://github.com/graviraja/mlops-basics/blob/main/week_0_project_setup/inference.py"
    click B "https://github.com/graviraja/mlops-basics/blob/main/week_4_onnx/inference.py"
    click B "https://github.com/graviraja/mlops-basics/blob/main/week_5_docker/train.py"

    %% Click Event for Experiment Tracking & Logging
    click C "https://github.com/graviraja/mlops-basics/blob/main/week_1_wandb_logging/README.md"

    %% Click Event for Configuration Management (Hydra)
    click D "https://github.com/graviraja/mlops-basics/blob/main/week_2_hydra_config/configs/config.yaml"

    %% Click Events for Data & Model Versioning (DVC)
    click E "https://github.com/graviraja/mlops-basics/blob/main/.dvc"
    click E "https://github.com/graviraja/mlops-basics/blob/main/week_3_dvc/dvcfiles/trained_model.dvc"

    %% Click Events for Model Packaging – ONNX
    click F "https://github.com/graviraja/mlops-basics/blob/main/week_4_onnx/convert_model_to_onnx.py"
    click F "https://github.com/graviraja/mlops-basics/blob/main/week_4_onnx/inference_onnx.py"

    %% Click Events for Model Packaging – Docker
    click G "https://github.com/graviraja/mlops-basics/tree/main/week_5_docker/Dockerfile"
    click G "https://github.com/graviraja/mlops-basics/blob/main/week_5_docker/docker-compose.yml"

    %% Click Events for CI/CD Pipeline (GitHub Actions)
    click H "https://github.com/graviraja/mlops-basics/blob/main/.github/workflows/basic.yaml"
    click H "https://github.com/graviraja/mlops-basics/blob/main/.github/workflows/build_docker_image.yaml"

    %% Click Events for Container Registry & Cloud Deployments
    click I "https://github.com/graviraja/mlops-basics/tree/main/week_7_ecr/Dockerfile"
    click I "https://github.com/graviraja/mlops-basics/blob/main/week_7_ecr/app.py"
    click I "https://github.com/graviraja/mlops-basics/blob/main/week_8_serverless/lambda_handler.py"
    click I "https://github.com/graviraja/mlops-basics/blob/main/week_9_monitoring/lambda_handler.py"

    %% Click Events for Monitoring & Logging
    click J "https://github.com/graviraja/mlops-basics/blob/main/week_9_monitoring/app.py"
    click J "https://github.com/graviraja/mlops-basics/tree/main/week_9_monitoring/Dockerfile"
    click J "https://github.com/graviraja/mlops-basics/tree/main/week_9_monitoring/"

    %% Styles
    classDef data fill:#aee1f9,stroke:#333,stroke-width:2px;
    classDef compute fill:#b2d8b2,stroke:#333,stroke-width:2px;
    classDef tracking fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef config fill:#FFECB3,stroke:#333,stroke-width:2px;
    classDef version fill:#FFA07A,stroke:#333,stroke-width:2px;
    classDef packaging fill:#F5B7B1,stroke:#333,stroke-width:2px;
    classDef ci fill:#D2B4DE,stroke:#333,stroke-width:2px;
    classDef cloud fill:#D6DBDF,stroke:#333,stroke-width:2px;
    classDef monitoring fill:#F1948A,stroke:#333,stroke-width:2px;
```
