# viral3899/food_delivery_time_prediction architecture

> Architecture diagram of the GitHub repository viral3899/food_delivery_time_prediction, 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/viral3899/food_delivery_time_prediction
- Repository: https://github.com/viral3899/food_delivery_time_prediction

## Overview

##### Main Components
- User Interface & Web Service:
- Components: “app.py”, “templates” (form.html, result.html, retrain.html), and “static” (CSS, images)
- Purpose: Provides the front-end for user interactions such as input forms, showing results, and triggering retraining.
- ML Pipeline:
- Located under the “food_delivery” directory:
▸ Pipeline orchestration: “food_delivery/pipeline/pipeline.py”
▸ Individual pipeline steps:
- Data ingestion (“data_ingestion.py”)
- Data transformation (“data_transformation.py”)
- Data validation (“data_validation.py”)
- Model training (“model_trainer.py”)
- Model evaluation (“model_evaluation.py”)
- Model deployment/pusher (“model_pusher.py”)
- Also includes “entity” modules for artifacts, configurations, and predictions (e.g., delivery_time_predictor, artifact_entity).
- Configuration & Constants:
- Centralized in “config” (with YAML files such as “config.yaml”, “model.yaml”, “schema.yaml”) and “food_delivery/config/configuration.py”.
- “food_delivery/constant” provides global constants.
- Logging & Exception Handling:
- “food_delivery/logger” and “food_delivery/exception” support robust logging and error management.
- Deployment & DevOps Infrastructure:
- Dockerization: “Dockerfile”, “docker-compose.yml”, “.dockerignore”
- CI/CD and workflows: Under “.github/workflows/main.yaml”
- AWS Deployment: README instructions mention creating IAM users, ECR repo, and deploying on EC2. Also, guidelines for self-hosted GitHub runners and GitHub secrets are provided.
- Supporting Files:
- “demo.py” for demonstration purposes.
- “notebook” containing an exploratory data analysis (EDA) notebook.
- “saved_models” directory for storing trained models.
- “setup.py”, “requirements.txt” for dependency management.

##### Relationships & Data Flow
- User Interaction Flow:
- Users interact via the web UI (served by app.py using templates & static files).
- Inputs from the UI trigger endpoints that invoke the ML pipeline (either for scoring/prediction or retraining).
- Pipeline Execution Flow:
- The ML pipeline orchestrator (“pipeline.py”) sequentially calls each modular component (ingestion → transformation → validation → training → evaluation → pusher).
- Data flows from one component to the next, with each step processing and passing artifacts (structured using entity classes).
- The “food_delivery/entity/delivery_time_predictor.py” indicates that predictions are computed here.
- Configuration & Logging:
- Before execution, configuration data is loaded from YAML files (or via “configuration.py”), ensuring that parameters for each stage are consistent.
- Throughout, logging and exception modules capture activity and errors.
- Model Management:
- Trained and validated models are saved in the “saved_models” directory.
- Containerization and Deployment:
- The Dockerfile and docker-compose definitions encapsulate the application.
- CI/CD via GitHub Actions builds the docker image, pushes it to an AWS ECR repository, and subsequently deploys to EC2.
- Deployment instructions include setting up the EC2 environment (installing Docker, self-hosted runners, etc.).

##### Architectural Patterns & Design Principles
- Separation of Concerns:
- Different layers for UI, ML processing, configuration, and deployment.
- Distinct directories for pipeline stages, making the system modular.
- Pipeline Design:
- The structure follows a sequential pipeline pattern (ETL → model training → evaluation).
- Containerization & Cloud Deployment:
- The design leverages Docker for consistency and AWS services for scalable deployment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Nodes
    User["User"]:::ui

    %% UI/Frontend Subgraph
    subgraph "UI/Frontend"
        UI1["Flask App (app.py)"]:::ui
        UI2["Templates (form.html, result.html, retrain.html)"]:::ui
        UI3["Static Files (images, style.css)"]:::ui
    end

    %% ML Pipeline Subgraph
    subgraph "ML Pipeline"
        MP1["Pipeline Orchestration (pipeline.py)"]:::ml
        MP2["Data Ingestion (data_ingestion.py)"]:::ml
        MP3["Data Transformation (data_transformation.py)"]:::ml
        MP4["Data Validation (data_validation.py)"]:::ml
        MP5["Model Training (model_trainer.py)"]:::ml
        MP6["Model Evaluation (model_evaluation.py)"]:::ml
        MP7["Model Deployment (model_pusher.py)"]:::ml
        subgraph "Entity Modules"
            EN1["artifact_entity.py"]:::ml
            EN2["config_entity.py"]:::ml
            EN3["delivery_time_predictor.py"]:::ml
            EN4["model_factory.py"]:::ml
        end
    end

    %% Configuration & Utilities Subgraph
    subgraph "Configuration & Utilities"
        CONF1["Configuration Files (config.yaml, model.yaml, schema.yaml, configuration.py)"]:::config
        UTIL1["Constants (food_delivery/constant)"]:::config
        UTIL2["Logging (food_delivery/logger)"]:::config
        UTIL3["Exception Handling (food_delivery/exception)"]:::config
    end

    %% Deployment & CI/CD Subgraph
    subgraph "Deployment & CI/CD"
        DEP1["Docker Setup (Dockerfile, docker-compose.yml, .dockerignore)"]:::deploy
        DEP2["CI/CD (GitHub Actions main.yaml)"]:::deploy
        DEP3["AWS Deployment (ECR, EC2, Runner)"]:::deploy
    end

    %% Supporting Files Subgraph
    subgraph "Supporting Files"
        SUP1["Demo (demo.py)"]:::supporting
        SUP2["Notebook (EDA.ipynb)"]:::supporting
        SUP3["Saved Models (saved_models)"]:::supporting
        SUP4["Dependency Files (requirements.txt, setup.py)"]:::supporting
    end

    %% Connections
    User -->|"Request"| UI1
    UI1 -->|"Trigger_Pipeline"| MP1

    %% Sequential ML Pipeline Flow
    MP1 --> MP2
    MP2 --> MP3
    MP3 --> MP4
    MP4 --> MP5
    MP5 --> MP6
    MP6 --> MP7

    %% Pipeline uses Entity Modules
    MP1 -.->|Creates| EN1
    MP1 -.->|Uses| EN3

    %% Configuration & Utilities connected to UI and ML Pipeline
    CONF1 -.-> UI1
    UTIL2 -.-> UI1
    UTIL3 -.-> UI1
    CONF1 -.-> MP1
    UTIL1 -.-> MP1
    UTIL2 -.-> MP1
    UTIL3 -.-> MP1

    %% Deployment Flow
    UI1 -->|"Containerize"| DEP1
    MP1 -->|"Containerize"| DEP1
    DEP1 -->|"Build&Push"| DEP2
    DEP2 -->|"Deploy"| DEP3

    %% Supporting Files Connection
    MP7 -->|"Save_Model"| SUP3

    %% Styling
    classDef ui fill:#bbdefb,stroke:#0d47a1,color:#0d47a1;
    classDef ml fill:#c8e6c9,stroke:#1b5e20,color:#1b5e20;
    classDef config fill:#ffe0b2,stroke:#e65100,color:#e65100;
    classDef deploy fill:#e0e0e0,stroke:#616161,color:#424242;
    classDef supporting fill:#f3e5f5,stroke:#6a1b9a,color:#6a1b9a;

    %% Click Events
    click UI1 "https://github.com/viral3899/food_delivery_time_prediction/blob/main/app.py"
    click UI2 "https://github.com/viral3899/food_delivery_time_prediction/blob/main/templates/form.html"
    click UI3 "https://github.com/viral3899/food_delivery_time_prediction/blob/main/static/style.css"
    click MP1 "https://github.com/viral3899/food_delivery_time_prediction/blob/main/food_delivery/pipeline/pipeline.py"
    click MP2 "https://github.com/viral3899/food_delivery_time_prediction/blob/main/food_delivery/components/data_ingestion.py"
    click MP3 "https://github.com/viral3899/food_delivery_time_prediction/blob/main/food_delivery/components/data_transformation.py"
    click MP4 "https://github.com/viral3899/food_delivery_time_prediction/blob/main/food_delivery/components/data_validation.py"
    click MP5 "https://github.com/viral3899/food_delivery_time_prediction/blob/main/food_delivery/components/model_trainer.py"
    click MP6 "https://github.com/viral3899/food_delivery_time_prediction/blob/main/food_delivery/components/model_evaluation.py"
    click MP7 "https://github.com/viral3899/food_delivery_time_prediction/blob/main/food_delivery/components/model_pusher.py"
    click EN1 "https://github.com/viral3899/food_delivery_time_prediction/blob/main/food_delivery/entity/artifact_entity.py"
    click EN2 "https://github.com/viral3899/food_delivery_time_prediction/blob/main/food_delivery/entity/config_entity.py"
    click EN3 "https://github.com/viral3899/food_delivery_time_prediction/blob/main/food_delivery/entity/delivery_time_predictor.py"
    click EN4 "https://github.com/viral3899/food_delivery_time_prediction/blob/main/food_delivery/entity/model_factory.py"
    click CONF1 "https://github.com/viral3899/food_delivery_time_prediction/blob/main/config/config.yaml"
    click UTIL1 "https://github.com/viral3899/food_delivery_time_prediction/tree/main/food_delivery/constant"
    click UTIL2 "https://github.com/viral3899/food_delivery_time_prediction/tree/main/food_delivery/logger"
    click UTIL3 "https://github.com/viral3899/food_delivery_time_prediction/tree/main/food_delivery/exception"
    click DEP1 "https://github.com/viral3899/food_delivery_time_prediction/tree/main/Dockerfile"
    click DEP2 "https://github.com/viral3899/food_delivery_time_prediction/blob/main/.github/workflows/main.yaml"
    click SUP1 "https://github.com/viral3899/food_delivery_time_prediction/blob/main/demo.py"
    click SUP2 "https://github.com/viral3899/food_delivery_time_prediction/blob/main/notebook/EDA.ipynb"
    click SUP3 "https://github.com/viral3899/food_delivery_time_prediction/tree/main/saved_models"
    click SUP4 "https://github.com/viral3899/food_delivery_time_prediction/blob/main/requirements.txt"
```
