# bhavesh2205/mlops-vehicle-insurance-claim-prediction architecture

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

- Interactive diagram: https://gitdiagram.com/bhavesh2205/mlops-vehicle-insurance-claim-prediction
- Repository: https://github.com/bhavesh2205/mlops-vehicle-insurance-claim-prediction

## Overview

##### Project type and purpose
- This is an enterprise‑grade MLOps solution for vehicle insurance claim prediction.
- It implements a full ML lifecycle: data ingestion from MongoDB Atlas, validation, transformation, model training/evaluation, and automated deployment.
- It exposes a FastAPI‑based UI for predictions and training triggers, backed by AWS services (S3, ECR, EC2) and CI/CD via GitHub Actions.

##### File structure
- Top‑level:
- app.py – FastAPI web server handling UI routes and prediction/training endpoints
- run_pipeline.py / push_data.py – scripts to execute ML pipelines or push data
- Dockerfile / .github/workflows/ci-cd.yaml – containerization and CI/CD config
- analysis/ – exploratory data analysis notebooks and scripts
- schema/ – data schema definition for validation
- src/
- cloud_storage/aws_storage.py – S3 interactions (model registry)
- configuration/ – AWS and MongoDB connection setup
- data_access/fetch_data.py – reading raw data from MongoDB Atlas
- components/ – modular pipeline steps (ingestion, validation, transformation, training, evaluation, pusher)
- pipeline/ – orchestrators for training and prediction pipelines
- entity/exception/logging/utils/constants – support classes, custom errors, logger, constants
- static/, templates/ – front‑end assets (CSS, HTML) for the FastAPI UI
- tests/ – unit tests

##### README for additional insights
- Architecture uses AWS S3 as model registry, ECR for Docker images, EC2 for hosting.
- CI/CD workflow: build Docker image → push to ECR → deploy on EC2.
- Data pipeline components: ingestion → validation → transformation.
- Model pipeline components: training → evaluation → pusher.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Layer
    subgraph "User Layer"
        direction TB
        Browser["Browser"]:::frontend
        Templates["HTML Templates"]:::frontend
        Static["Static Assets"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        direction TB
        FastAPI["FastAPI Server (app.py)"]:::frontend
    end

    %% Pipeline Layer
    subgraph "Pipeline Layer"
        direction TB
        subgraph "Orchestrators"
            direction TB
            TrainPipe["Training Pipeline"]:::pipeline
            PredictPipe["Prediction Pipeline"]:::pipeline
        end
        subgraph "Data Pipeline Components"
            direction TB
            Ingest["Data Ingestion"]:::pipeline
            Validation["Data Validation"]:::pipeline
            Transformation["Data Transformation"]:::pipeline
        end
        subgraph "Model Pipeline Components"
            direction TB
            ModelTrainer["Model Trainer"]:::pipeline
            ModelEval["Model Evaluation"]:::pipeline
            ModelPusher["Model Pusher"]:::pipeline
        end
    end

    %% Data & Storage
    subgraph "Data & Storage"
        direction TB
        MongoDB["MongoDB Atlas"]:::db
        S3["AWS S3 Model Registry"]:::cloud
        ECR["AWS ECR"]:::cloud
        EC2["AWS EC2 (Hosting)"]:::cloud
    end

    %% CI/CD
    subgraph "CI/CD"
        direction TB
        GitHubActions["GitHub Actions"]:::cicd
        DockerBuild["Dockerfile"]:::cicd
        DeployECR["Push to ECR"]:::cicd
        DeployEC2["Deploy to EC2"]:::cicd
    end

    %% Utilities & Config
    subgraph "Utilities & Config"
        direction TB
        FetchData["Data Access\n(fetch_data.py)"]:::util
        MongoConfig["MongoDB Config"]:::util
        AWSConfig["AWS Config"]:::util
        AWSStorage["AWS S3 Storage"]:::util
        SchemaDef["Schema Definition"]:::util
        Logger["Logging Utility"]:::util
        ExceptionMod["Exception Module"]:::util
        Utils["Main Utilities"]:::util
        Constants["Constants"]:::util
    end

    %% Connections: User to API
    Browser -->|Requests UI| FastAPI
    Templates -->|Served by| FastAPI
    Static -->|Served by| FastAPI

    %% API to Pipelines
    FastAPI -->|Trigger Training| TrainPipe
    FastAPI -->|Trigger Prediction| PredictPipe

    %% Prediction Flow
    PredictPipe -->|Load Model| S3
    S3 -->|Model Data| PredictPipe
    PredictPipe -->|Return Prediction| FastAPI

    %% Training Flow
    TrainPipe --> FetchData
    FetchData -->|Raw Data| Ingest
    Ingest --> Validation
    Validation --> Transformation
    Transformation --> ModelTrainer
    ModelTrainer --> ModelEval
    ModelEval -->|If Approved| ModelPusher
    ModelPusher -->|Upload Model| S3

    %% Config & Utilities usage
    FetchData --> MongoConfig
    FetchData --> AWSConfig
    Ingest --> SchemaDef
    ModelPusher --> AWSStorage
    TrainPipe --> Utils
    TrainPipe --> Logger
    TrainPipe --> ExceptionMod
    TrainPipe --> Constants

    %% Data Source
    FetchData --> MongoDB

    %% CI/CD Flow
    GitHubActions -->|Build Image| DockerBuild
    DockerBuild -->|Push Image| DeployECR
    DeployECR -->|New Image| ECR
    DeployECR -->|Trigger Deploy| DeployEC2
    DeployEC2 --> EC2
    EC2 --> FastAPI

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1B4F72,color:#1B2631;
    classDef pipeline fill:#A9DFBF,stroke:#196F3D,color:#145A32;
    classDef cloud fill:#F5B7B1,stroke:#6E2C00,color:#4E342E;
    classDef cicd fill:#D5D8DC,stroke:#424949,color:#212F3D;
    classDef db fill:#D7BDE2,stroke:#512E5F,color:#4A235A;
    classDef util fill:#F2F3F4,stroke:#909497,color:#424949;

    %% Click Events
    click FastAPI "https://github.com/bhavesh2205/mlops-vehicle-insurance-claim-prediction/blob/main/app.py"
    click Templates "https://github.com/bhavesh2205/mlops-vehicle-insurance-claim-prediction/blob/main/templates/vehicledata.html"
    click Static "https://github.com/bhavesh2205/mlops-vehicle-insurance-claim-prediction/blob/main/static/style.css"
    click Ingest "https://github.com/bhavesh2205/mlops-vehicle-insurance-claim-prediction/blob/main/src/components/data_ingestion.py"
    click Validation "https://github.com/bhavesh2205/mlops-vehicle-insurance-claim-prediction/blob/main/src/components/data_validation.py"
    click Transformation "https://github.com/bhavesh2205/mlops-vehicle-insurance-claim-prediction/blob/main/src/components/data_transformation.py"
    click ModelTrainer "https://github.com/bhavesh2205/mlops-vehicle-insurance-claim-prediction/blob/main/src/components/model_trainer.py"
    click ModelEval "https://github.com/bhavesh2205/mlops-vehicle-insurance-claim-prediction/blob/main/src/components/model_evaluation.py"
    click ModelPusher "https://github.com/bhavesh2205/mlops-vehicle-insurance-claim-prediction/blob/main/src/components/model_pusher.py"
    click TrainPipe "https://github.com/bhavesh2205/mlops-vehicle-insurance-claim-prediction/blob/main/src/pipeline/training_pipeline.py"
    click PredictPipe "https://github.com/bhavesh2205/mlops-vehicle-insurance-claim-prediction/blob/main/src/pipeline/prediction_pipeline.py"
    click FetchData "https://github.com/bhavesh2205/mlops-vehicle-insurance-claim-prediction/blob/main/src/data_access/fetch_data.py"
    click MongoConfig "https://github.com/bhavesh2205/mlops-vehicle-insurance-claim-prediction/blob/main/src/configuration/mongodb_connection.py"
    click AWSConfig "https://github.com/bhavesh2205/mlops-vehicle-insurance-claim-prediction/blob/main/src/configuration/aws_connection.py"
    click AWSStorage "https://github.com/bhavesh2205/mlops-vehicle-insurance-claim-prediction/blob/main/src/cloud_storage/aws_storage.py"
    click SchemaDef "https://github.com/bhavesh2205/mlops-vehicle-insurance-claim-prediction/blob/main/schema/schema.yaml"
    click Logger "https://github.com/bhavesh2205/mlops-vehicle-insurance-claim-prediction/blob/main/src/logging/logger.py"
    click ExceptionMod "https://github.com/bhavesh2205/mlops-vehicle-insurance-claim-prediction/blob/main/src/exception/exception.py"
    click Utils "https://github.com/bhavesh2205/mlops-vehicle-insurance-claim-prediction/blob/main/src/utils/main_utils.py"
    click Constants "https://github.com/bhavesh2205/mlops-vehicle-insurance-claim-prediction/tree/main/src/constants/constant"
    click DockerBuild "https://github.com/bhavesh2205/mlops-vehicle-insurance-claim-prediction/tree/main/Dockerfile"
    click GitHubActions "https://github.com/bhavesh2205/mlops-vehicle-insurance-claim-prediction/blob/main/.github/workflows/ci-cd.yaml"
```
