# harshitraiii2005/vehichle-insurance-prediction architecture

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

- Interactive diagram: https://gitdiagram.com/harshitraiii2005/vehichle-insurance-prediction
- Repository: https://github.com/harshitraiii2005/vehichle-insurance-prediction

## Overview

##### Project Type and Purpose
- This is an MLOps pipeline for building, evaluating, and serving a vehicle‐insurance prediction model.
- It combines data engineering (MongoDB ingestion, validation, transformation), model training/evaluation, cloud storage (AWS S3), a FastAPI prediction service (app.py + templates/static), and CI/CD (Docker + GitHub Actions + AWS EC2/ECR).

##### File Structure
- Top-level: Dockerfile, GitHub Actions workflow (.github/workflows/aws.yaml), config/schema.yaml, app.py (FastAPI service), demo.py (quick smoke test), notebooks for EDA.
- src/cloud_storage: AWS S3 logic
- src/components: pipeline steps (data_ingestion → validation → transformation → trainer → evaluator → pusher)
- src/configuration: connection objects (MongoDB, AWS)
- src/data_access: raw data fetch (vehicle_data.py)
- src/entity: configuration and artifact definitions
- src/pipline: orchestrates training and prediction pipelines
- src/utils, src/logger, src/exception: cross-cutting utilities
- templates/ + static/: UI assets for the prediction web interface

##### README Insights
- 18‐step workflow: from environment setup → MongoDB data push → ETL steps → model training/evaluation → S3 model push → FastAPI app → Dockerize → CI/CD to EC2/ECR.
- Emphasis on modular “components” for each ML stage and on cloud integration.

##### Main Components & Interactions
a. Data Sources
- CSV files (notebooks/data.csv, data.csv)
- Jupyter notebooks (for EDA)
b. Data Storage
- MongoDB Atlas cluster
c. ETL Pipeline
- Data Ingestion (src/components/data_ingestion.py) reads from MongoDB via src/data_access/vehicle_data.py
- Data Validation (src/components/data_validation.py; schema in config/schema.yaml)
- Data Transformation (src/components/data_transformation.py; uses entity/estimator.py)
d. Model Pipeline
- Model Trainer (src/components/model_trainer.py)
- Model Evaluation (src/components/model_evaluation.py)
- Model Pusher (src/components/model_pusher.py) → AWS S3 (src/cloud_storage/aws_storage.py)
e. Serving Layer
- FastAPI app (app.py + templates.py) loads best model from S3 and serves predictions via templates/vehicledata.html + static/css/style.css
f. CI/CD & Infrastructure
- Dockerfile builds container image
- GitHub Actions (aws.yaml) runs tests, builds image, pushes to ECR
- EC2 instance (self-hosted runner) pulls image and runs container on port 5080

##### Architectural Patterns & Design Principles
- Modular ETL & model‐ops “components” connected by clear interfaces (entity definitions, configuration objects)
- Layered separation: ingestion → processing → training → deployment
- Infrastructure as code (Docker + GitHub Actions + AWS resources)
- Single responsibility modules for logging, exception handling, configuration

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Data Layer
    subgraph "Data Layer"
        direction TB
        CSV["data.csv"]:::datalayer
        Notebooks["Jupyter Notebooks"]:::datalayer
        MongoDBAtlas(("MongoDB Atlas")):::external
    end

    %% ETL Layer
    subgraph "ETL Layer"
        direction TB
        Ingestion["src/components/data_ingestion.py"]:::etl
        Validation["src/components/data_validation.py"]:::etl
        Transformation["src/components/data_transformation.py"]:::etl
    end

    %% Model Layer
    subgraph "Model Layer"
        direction TB
        Trainer["src/components/model_trainer.py"]:::model
        Evaluator["src/components/model_evaluation.py"]:::model
        Pusher["src/components/model_pusher.py"]:::model
        S3Storage(("AWS S3")):::external
    end

    %% Serving Layer
    subgraph "Serving Layer"
        direction TB
        FastAPIApp["app.py (FastAPI Service)"]:::serving
        Templates["templates/vehicledata.html"]:::serving
        StaticCSS["static/css/style.css"]:::serving
        DemoTest["demo.py"]:::serving
    end

    %% CI/CD & Infrastructure
    subgraph "CI/CD & Infra"
        direction TB
        GitHubActions[".github/workflows/aws.yaml"]:::infra
        DockerfileNode["Dockerfile"]:::infra
        ECR["AWS ECR"]:::external
        EC2["AWS EC2 (Self-Hosted Runner)"]:::external
    end

    %% Configuration & Utilities
    subgraph "Configuration"
        direction TB
        MongoConfig["src/configuration/mongo_db_connection.py"]:::infra
        AWSConfig["src/configuration/aws_connection.py"]:::infra
        SchemaDef["config/schema.yaml"]:::infra
    end

    subgraph "Utilities"
        direction TB
        MainUtils["src/utils/main_utils.py"]:::infra
        Logger["src/logger/__init__.py"]:::infra
        ExceptionHandler["src/exception/__init__.py"]:::infra
    end

    %% Pipeline Orchestrators & Entities
    subgraph "Orchestrators & Entities"
        direction TB
        TrainingPipeline["src/pipline/training_pipeline.py"]:::etl
        PredictionPipeline["src/pipline/prediction_pipeline.py"]:::serving
        VehicleData["src/data_access/vehicle_data.py"]:::etl
        ArtifactEntity["src/entity/artifact_entity.py"]:::etl
        ConfigEntity["src/entity/config_entity.py"]:::etl
        EstimatorEntity["src/entity/estimator.py"]:::etl
        S3EstimatorEntity["src/entity/s3_estimator.py"]:::model
    end

    %% Data Flow
    CSV --> MongoDBAtlas
    Notebooks --> MongoDBAtlas
    MongoDBAtlas --> VehicleData
    VehicleData --> Ingestion
    Ingestion --> Validation
    Validation --> Transformation
    Transformation --> Trainer
    Trainer --> Evaluator
    Evaluator --> Pusher
    Pusher --> S3Storage
    S3Storage --> FastAPIApp
    FastAPIApp --> Templates
    FastAPIApp --> StaticCSS
    PredictionPipeline --> FastAPIApp

    %% Control & Config
    MongoConfig -.-> Ingestion
    AWSConfig -.-> Pusher
    SchemaDef -.-> Validation
    MainUtils -.-> Ingestion
    Logger -.-> Ingestion
    ExceptionHandler -.-> Ingestion

    TrainingPipeline --> Ingestion
    TrainingPipeline --> Trainer
    PredictionPipeline --> VehicleData
    PredictionPipeline --> FastAPIApp

    %% CI/CD Flow
    GitHubActions --> DockerfileNode
    DockerfileNode --> ECR
    ECR --> EC2
    EC2 --> FastAPIApp
    GitHubActions -.-> AWSConfig
    GitHubActions -.-> MongoConfig

    %% Click Events
    click Ingestion "https://github.com/harshitraiii2005/vehichle-insurance-prediction/blob/main/src/components/data_ingestion.py"
    click Validation "https://github.com/harshitraiii2005/vehichle-insurance-prediction/blob/main/src/components/data_validation.py"
    click Transformation "https://github.com/harshitraiii2005/vehichle-insurance-prediction/blob/main/src/components/data_transformation.py"
    click Trainer "https://github.com/harshitraiii2005/vehichle-insurance-prediction/blob/main/src/components/model_trainer.py"
    click Evaluator "https://github.com/harshitraiii2005/vehichle-insurance-prediction/blob/main/src/components/model_evaluation.py"
    click Pusher "https://github.com/harshitraiii2005/vehichle-insurance-prediction/blob/main/src/components/model_pusher.py"
    click S3Storage "https://github.com/harshitraiii2005/vehichle-insurance-prediction/blob/main/src/cloud_storage/aws_storage.py"
    click MongoConfig "https://github.com/harshitraiii2005/vehichle-insurance-prediction/blob/main/src/configuration/mongo_db_connection.py"
    click AWSConfig "https://github.com/harshitraiii2005/vehichle-insurance-prediction/blob/main/src/configuration/aws_connection.py"
    click VehicleData "https://github.com/harshitraiii2005/vehichle-insurance-prediction/blob/main/src/data_access/vehicle_data.py"
    click ArtifactEntity "https://github.com/harshitraiii2005/vehichle-insurance-prediction/blob/main/src/entity/artifact_entity.py"
    click ConfigEntity "https://github.com/harshitraiii2005/vehichle-insurance-prediction/blob/main/src/entity/config_entity.py"
    click EstimatorEntity "https://github.com/harshitraiii2005/vehichle-insurance-prediction/blob/main/src/entity/estimator.py"
    click S3EstimatorEntity "https://github.com/harshitraiii2005/vehichle-insurance-prediction/blob/main/src/entity/s3_estimator.py"
    click TrainingPipeline "https://github.com/harshitraiii2005/vehichle-insurance-prediction/blob/main/src/pipline/training_pipeline.py"
    click PredictionPipeline "https://github.com/harshitraiii2005/vehichle-insurance-prediction/blob/main/src/pipline/prediction_pipeline.py"
    click MainUtils "https://github.com/harshitraiii2005/vehichle-insurance-prediction/blob/main/src/utils/main_utils.py"
    click Logger "https://github.com/harshitraiii2005/vehichle-insurance-prediction/blob/main/src/logger/__init__.py"
    click ExceptionHandler "https://github.com/harshitraiii2005/vehichle-insurance-prediction/blob/main/src/exception/__init__.py"
    click SchemaDef "https://github.com/harshitraiii2005/vehichle-insurance-prediction/blob/main/config/schema.yaml"
    click FastAPIApp "https://github.com/harshitraiii2005/vehichle-insurance-prediction/blob/main/app.py"
    click Templates "https://github.com/harshitraiii2005/vehichle-insurance-prediction/blob/main/templates/vehicledata.html"
    click StaticCSS "https://github.com/harshitraiii2005/vehichle-insurance-prediction/blob/main/static/css/style.css"
    click DemoTest "https://github.com/harshitraiii2005/vehichle-insurance-prediction/blob/main/demo.py"
    click GitHubActions "https://github.com/harshitraiii2005/vehichle-insurance-prediction/blob/main/.github/workflows/aws.yaml"
    click DockerfileNode "https://github.com/harshitraiii2005/vehichle-insurance-prediction/tree/main/Dockerfile"

    %% Styles
    classDef datalayer fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef etl fill:#FFA500,stroke:#333,stroke-width:1px
    classDef model fill:#90EE90,stroke:#333,stroke-width:1px
    classDef serving fill:#D8BFD8,stroke:#333,stroke-width:1px
    classDef infra fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef external fill:#f0f0f0,stroke:#333,stroke-width:1px
```
