# faramarzq/resource_allocation_using_machine_learning architecture

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

- Interactive diagram: https://gitdiagram.com/faramarzq/resource_allocation_using_machine_learning
- Repository: https://github.com/faramarzq/resource_allocation_using_machine_learning

## Overview

- Cloud Module: Represents the “brain” of the system.
- Following subcomponents:
- Data Storage – The cloud storage folder (Cloud/storage) where raw data, processed data, and the trained model (model.joblib) reside.
- ML Model Trainer – Represent Cloud/cloud.py which splits the dataset, trains the model (Decision Tree Classifier), validates it, and persists the trained ML model.
- Edge Module: Represents the distributed task handling part.
- Master Node:
- Depicted as the coordinator (Edges/Master.py) that takes in Cloudlet details and the trained model from the Cloud Module.
- It chooses the best Worker for each task using both the ML model and a secondary greedy algorithm for comparison.
- Cloudlets:
- Represented by the Cloudlet class (Edges/Cloudlet.py). They encapsulate task attributes (e.g., position, instructions, size, and priority) that the Master node needs to evaluate.
- Worker Nodes:
- Depicted as individual worker components (in Edges/workers/). Include the abstract Worker (Edges/workers/Worker.py) and the three specific Worker implementations (Worker1.py, Worker2.py, Worker3.py) which differ in processing power and their network characteristics.

##### Out the Relationships and Data Flow
- Cloud Module Processing:
- Ingestion of raw data into Cloud/cloud.py for training.
- Separation of data into training (70%) and testing (30%), highlight decision tree training, and show the final output: the ML model saved in the storage.
- Interconnection Between Cloud and Edge:
- Inside the Edge Module:
- That Cloudlets are initiated, processed, and then dispatched to a worker.
- Network communication/data flow between the Master Node and Worker Nodes (possibly label them with “Resource Allocation Decision” and “Task Dispatch”).

##### Architectural Patterns and Decision Points
- Separation between a centralized Cloud (data processing, ML training, storage) and distributed Edge (task management, execution).
- Incorporate the inherited worker design pattern where Worker1, Worker2, and Worker3 derive from the base Worker class.

##### Incorporate Technical Details
- Use clear labels for each component and subcomponent.
- Where applicable, add technology hints (e.g., Python-based ML using Decision Tree Classifier, joblib for model persistence).

- Use a central block representing the Cloud Module that includes ML training and data management.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Cloud Layer
    subgraph "Cloud Layer"
        DS["Data Seeder\n(seeder.py\nCSV Template, data.csv,\ndata_description.txt)"]:::process
        storage["Data Storage\n(storage/\nmodel.joblib)"]:::storage
        ml["ML Model Trainer\n(cloud.py)"]:::process
    end

    %% Data flow within Cloud
    DS -->|"reads template"| storage
    storage -->|"ingests raw data"| ml
    ml -->|"saves trained model"| storage

    %% Connection between Cloud and Edge
    storage -->|"provides model"| MN

    %% Edge Layer
    subgraph "Edge Layer"
        MN["Master Node\n(Master.py)"]:::process
        cl["Cloudlet\n(Cloudlet.py)"]:::task
        DB["Decision Branch"]:::decision
        
        MN -->|"receives cloudlet\nmetadata"| cl
        MN -->|"for decision"| DB

        %% Decision branch to Worker Nodes
        DB -->|"ML"| w1
        DB -->|"ML"| w2
        DB -->|"ML"| w3
        DB -->|"Greedy"| w1
        DB -->|"Greedy"| w2
        DB -->|"Greedy"| w3

        %% Worker Nodes subgraph
        subgraph "Worker Nodes"
            wbase["Base Worker\n(Worker.py)"]:::worker
            w1["Worker 1\n(Worker1.py)"]:::worker
            w2["Worker 2\n(Worker2.py)"]:::worker
            w3["Worker 3\n(Worker3.py)"]:::worker
            wbase -.->|"inherits"| w1
            wbase -.->|"inherits"| w2
            wbase -.->|"inherits"| w3
        end
    end

    %% Click Events
    click DS "https://github.com/faramarzq/resource_allocation_using_machine_learning/blob/main/Cloud/seeder.py"
    click storage "https://github.com/faramarzq/resource_allocation_using_machine_learning/tree/main/Cloud/storage/"
    click ml "https://github.com/faramarzq/resource_allocation_using_machine_learning/blob/main/Cloud/cloud.py"
    click MN "https://github.com/faramarzq/resource_allocation_using_machine_learning/blob/main/Edges/Master.py"
    click cl "https://github.com/faramarzq/resource_allocation_using_machine_learning/blob/main/Edges/Cloudlet.py"
    click wbase "https://github.com/faramarzq/resource_allocation_using_machine_learning/blob/main/Edges/workers/Worker.py"
    click w1 "https://github.com/faramarzq/resource_allocation_using_machine_learning/blob/main/Edges/workers/Worker1.py"
    click w2 "https://github.com/faramarzq/resource_allocation_using_machine_learning/blob/main/Edges/workers/Worker2.py"
    click w3 "https://github.com/faramarzq/resource_allocation_using_machine_learning/blob/main/Edges/workers/Worker3.py"

    %% Styles
    classDef process fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef storage fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef task fill:#D5F5E3,stroke:#1D8348,stroke-width:2px;
    classDef worker fill:#F5CBA7,stroke:#943126,stroke-width:2px;
    classDef decision fill:#FAD7A0,stroke:#E67E22,stroke-width:2px;
```
