# rizwan1602/machine-learning-with-ci-cd architecture

> Architecture diagram of the GitHub repository rizwan1602/machine-learning-with-ci-cd, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rizwan1602/machine-learning-with-ci-cd
- Repository: https://github.com/rizwan1602/machine-learning-with-ci-cd

## Overview

##### Main Components
- Data Input & Artifacts: Represent the raw data sources and artifacts. This includes CSV files (train.csv, test.csv, stud.csv in notebook/data and artifacts) and pre-generated artifacts such as model.pkl and preprocessor.pkl stored in the artifacts folder.
- Data Ingestion: Encapsulated in the src/components/data_ingestion.py module where raw data is loaded.
- Data Transformation: Represented by src/components/data_transformation.py, which preprocesses the incoming data.
- Model Training: Indicated by src/components/model_trainer.py and the pipelines in src/pipeline/train_pipeline.py. Also include the CatBoost logs and supplementary information (e.g., catboost_info directories).
- Prediction Pipeline: Captured by src/pipeline/predict_pipeline.py, which uses the trained model and preprocessor to produce predictions.
- Web Interface/Service: The existence of app.py, application.py, and HTML templates (in the templates folder) suggests a web component that likely serves as an interface for user interaction with the model (for example, collecting input and displaying predictions). This can be shown as a “Frontend” or “API/Web Service” component.
- Notebooks & Experimental Environment: The notebook directory containing Jupyter notebooks for Exploratory Data Analysis (EDA) and training indicates an experimental process separate from the main production code.
- Deployment & Configuration: Include elements like the Dockerfile, .ebextensions (for AWS Elastic Beanstalk), and GitHub workflows, which manage CI/CD and deployment.

##### Relationships and Interactions
- Data flows from raw CSV files (or other sources) are ingested by the Data Ingestion module.
- Ingested data is passed to the Data Transformation component for cleaning and preprocessing.
- The output from transformation is used by the Model Trainer to train the ML model using CatBoost (as evidenced by files in the catboost_info directory) and then stored as model artifacts.
- The Prediction Pipeline consumes incoming new data, applies the same preprocessing steps (using the preprocessor artifact), and utilizes the trained model for predictions.
- The Web Service (app.py/application.py) interfaces with the Prediction Pipeline to provide a user-friendly front-end or API endpoint.
- Notebooks can be depicted as a support layer that was used during development and experimentation; though not part of the production system, they provide context on EDA and model training processes.
- Deployment configurations (Dockerfile, .ebextensions, GitHub workflows) tie into how the entire system is containerized and deployed, ensuring a consistent production environment.

##### Highlighting Architectural Patterns & Design Principles
- Layered Architecture: You have separate layers for data ingestion, transformation, model training, and prediction, which follows a pipeline-based (or ‘separation of concerns’) approach.
- Modular Design: Each module (data_ingestion, data_transformation, model_trainer, predict_pipeline, train_pipeline) is self-contained, lending itself to independent testing and reuse.
- Deployment Agility: Inclusion of Docker and AWS EB configurations signals containerized deployments and possibly a microservice approach for the web service layer.
- Error Handling & Logging: The presence of src/exception.py and src/logger.py indicates the design incorporates dedicated error logging and management practices.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Sources Subgraph
    subgraph "Data Sources & Artifacts"
        Artifacts["Artifacts"]:::sources
        NotebookData["Notebook Data"]:::sources
    end

    %% Main Processing Pipeline
    Artifacts -->|"feeds"| DataIngestion
    NotebookData -->|"feeds"| DataIngestion

    DataIngestion["Data Ingestion (src/components/data_ingestion.py)"]:::ingestion
    DataIngestion -->|"provides data to"| DataTransformation
    DataTransformation["Data Transformation (src/components/data_transformation.py)"]:::transformation

    %% Branch out to Model Training and Prediction Pipeline
    DataTransformation -->|"prepares data for"| ModelTrainingGroup
    DataTransformation -->|"prepares data for"| PredictPipeline["Prediction Pipeline (src/pipeline/predict_pipeline.py)"]:::prediction

    %% Model Training Group Subgraph
    subgraph "Model Training"
        ModelTrainer["Model Trainer (src/components/model_trainer.py)"]:::training
        TrainPipeline["Train Pipeline (src/pipeline/train_pipeline.py)"]:::training
        CatBoostInfo["CatBoost Info"]:::training
        ModelTrainer -->|"triggers"| TrainPipeline
        TrainPipeline -->|"logs info to"| CatBoostInfo
    end

    %% Web Service Subgraph
    PredictPipeline -->|"serves results to"| WebServiceGroup
    subgraph "Web Service"
        App["App (app.py)"]:::web
        Application["Application (application.py)"]:::web
        Templates["Templates (templates)"]:::web
        App --> Application
        Application --> Templates
    end

    %% Infrastructure & Deployment Subgraph
    WebServiceGroup -->|"deployed via"| DeploymentGroup
    subgraph "Deployment & Configuration"
        Docker["Dockerfile"]:::infra
        AWSEB["AWS EB Config (.ebextensions)"]:::infra
        CICD["CI/CD (.github/workflows)"]:::infra
        Docker --> AWSEB
        AWSEB --> CICD
    end

    %% Development / EDA Subgraph
    subgraph "Development / EDA"
        Notebooks["Notebooks (notebook)"]:::dev
    end

    %% Logging & Exception Handling Subgraph
    subgraph "Logging & Exception Handling"
        Logger["Logger (src/logger.py)"]:::logging
        Exception["Exception (src/exception.py)"]:::logging
    end

    %% Dotted support lines from Logging & Exception Handling to core processing components
    Logger -.-> DataIngestion
    Logger -.-> DataTransformation
    Logger -.-> ModelTrainer
    Logger -.-> TrainPipeline
    Logger -.-> PredictPipeline

    Exception -.-> DataIngestion
    Exception -.-> DataTransformation
    Exception -.-> ModelTrainer
    Exception -.-> TrainPipeline
    Exception -.-> PredictPipeline

    %% Click Events for Component Mapping
    click Artifacts "https://github.com/rizwan1602/machine-learning-with-ci-cd/tree/main/artifacts"
    click NotebookData "https://github.com/rizwan1602/machine-learning-with-ci-cd/tree/main/notebook/data"
    click DataIngestion "https://github.com/rizwan1602/machine-learning-with-ci-cd/blob/main/src/components/data_ingestion.py"
    click DataTransformation "https://github.com/rizwan1602/machine-learning-with-ci-cd/blob/main/src/components/data_transformation.py"
    click ModelTrainer "https://github.com/rizwan1602/machine-learning-with-ci-cd/blob/main/src/components/model_trainer.py"
    click TrainPipeline "https://github.com/rizwan1602/machine-learning-with-ci-cd/blob/main/src/pipeline/train_pipeline.py"
    click CatBoostInfo "https://github.com/rizwan1602/machine-learning-with-ci-cd/tree/main/catboost_info"
    click PredictPipeline "https://github.com/rizwan1602/machine-learning-with-ci-cd/blob/main/src/pipeline/predict_pipeline.py"
    click App "https://github.com/rizwan1602/machine-learning-with-ci-cd/blob/main/app.py"
    click Application "https://github.com/rizwan1602/machine-learning-with-ci-cd/blob/main/application.py"
    click Templates "https://github.com/rizwan1602/machine-learning-with-ci-cd/tree/main/templates"
    click Docker "https://github.com/rizwan1602/machine-learning-with-ci-cd/tree/main/Dockerfile"
    click AWSEB "https://github.com/rizwan1602/machine-learning-with-ci-cd/blob/main/.ebextensions"
    click CICD "https://github.com/rizwan1602/machine-learning-with-ci-cd/blob/main/.github/workflows/main.yaml"
    click Notebooks "https://github.com/rizwan1602/machine-learning-with-ci-cd/tree/main/notebook"
    click Logger "https://github.com/rizwan1602/machine-learning-with-ci-cd/blob/main/src/logger.py"
    click Exception "https://github.com/rizwan1602/machine-learning-with-ci-cd/blob/main/src/exception.py"

    %% Styles
    classDef sources fill:#FFEEAD,stroke:#333,stroke-width:2px;
    classDef ingestion fill:#B3E5FC,stroke:#333,stroke-width:2px;
    classDef transformation fill:#C8E6C9,stroke:#333,stroke-width:2px;
    classDef training fill:#FFCDD2,stroke:#333,stroke-width:2px;
    classDef prediction fill:#DCEDC8,stroke:#333,stroke-width:2px;
    classDef web fill:#B2DFDB,stroke:#333,stroke-width:2px;
    classDef infra fill:#FFF9C4,stroke:#333,stroke-width:2px;
    classDef dev fill:#E1BEE7,stroke:#333,stroke-width:2px;
    classDef logging fill:#E0E0E0,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5;
```
