# sidag26/dre-scale architecture

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

- Interactive diagram: https://gitdiagram.com/sidag26/dre-scale
- Repository: https://github.com/sidag26/dre-scale

## Overview

##### Project Type and Purpose
- DRe‑SCale is a full‑stack research platform for intelligent autoscaling of serverless functions on Kubernetes using Deep Recurrent Reinforcement Learning.
- It integrates an experimental cluster (MicroK8s + OpenFaaS + Prometheus), a suite of RL “scaling agents,” stateless serverless functions, and a workload generator.

##### File Structure
- Top‑level directories:
- openfaas‑functions – contains the matmul function, its handler and YAML manifest (the actual FaaS workload).
- scaling‑agents – multiple RL implementations (DRQN, PPO, LSTM‑PPO, SAC(+LSTM)) each with agent.py, env.py, tests and requirements.
- workload‑generator – Python script + JSON config to generate HTTP invocations.
- experimental‑results & images – notebooks and output used to analyze and illustrate system behavior.
- Infra/config files: MicroK8s isn’t in repo but implied; OpenFaaS manifests in openfaas‑functions; Prometheus configured externally.

##### Extract Architectural Insights from the README
- Core components:
- Kubernetes cluster (5 nodes)
- OpenFaaS gateway & function pods
- Prometheus for metrics
- RL controller (actor+critic) that polls Prometheus, computes scale‑out/in actions, and calls the OpenFaaS API.
- Workload generator that simulates client traffic.
- systemArchitectureDiagram.png (overall platform)
- agentArchitecture.png (neural network internals)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Infrastructure Layer
    subgraph "Experimental Cluster" 
        direction TB
        K8s["Kubernetes Cluster<br/>(MicroK8s)"]:::infrastructure
        OFG["OpenFaaS Gateway"]:::infrastructure
        PROM["Prometheus Server"]:::infrastructure
        FUNC["matmul Function Pod"]:::dataPlane
    end

    %% Control Loop Layer
    subgraph "Control Loop" 
        direction TB
        MON["Monitoring Agent"]:::controlPlane
        RL["RL Controller"]:::controlPlane
        subgraph "RL Variants" 
            direction TB
            DRQN["DRQN Agent"]:::controlPlane
            PPO["PPO Agent"]:::controlPlane
            LSTMPPO["LSTM‑PPO Agent"]:::controlPlane
            SACLSTM["SAC(+LSTM) Agent"]:::controlPlane
        end
    end

    %% Data Plane Layer
    WG["Workload Generator"]:::dataPlane

    %% Experimental/Test Harness Layer
    subgraph "Experimental Analysis" 
        direction TB
        NB["analysisUtility.ipynb"]:::experimental
        IMG["Images Directory"]:::experimental
    end

    %% Connections
    WG -->|"HTTP Invoke"| OFG
    OFG -->|"Dispatch Request"| FUNC
    FUNC -->|"Metrics"| PROM
    PROM -->|"Query Metrics"| MON
    MON -->|"Observations"| RL
    RL -->|"Scale API Call"| OFG
    FUNC -->|"Logs & Metrics"| NB
    NB -->|"Generates"| IMG

    %% Click Events
    click FUNC "https://github.com/sidag26/dre-scale/blob/main/openfaas-functions/matmul/handler.py"
    click FUNC "https://github.com/sidag26/dre-scale/blob/main/openfaas-functions/matmul.yml"
    click DRQN "https://github.com/sidag26/dre-scale/blob/main/scaling-agents/DRQN/agent.py"
    click DRQN "https://github.com/sidag26/dre-scale/blob/main/scaling-agents/DRQN/env.py"
    click PPO "https://github.com/sidag26/dre-scale/blob/main/scaling-agents/PPO/agent.py"
    click PPO "https://github.com/sidag26/dre-scale/blob/main/scaling-agents/PPO/env.py"
    click LSTMPPO "https://github.com/sidag26/dre-scale/blob/main/scaling-agents/LSTM-PPO/agent.py"
    click LSTMPPO "https://github.com/sidag26/dre-scale/blob/main/scaling-agents/LSTM-PPO/env.py"
    click SACLSTM "https://github.com/sidag26/dre-scale/blob/main/scaling-agents/SAC(+LSTM)/sac_agent.py"
    click SACLSTM "https://github.com/sidag26/dre-scale/blob/main/scaling-agents/SAC(+LSTM)/sac_lstm_agent.py"
    click SACLSTM "https://github.com/sidag26/dre-scale/blob/main/scaling-agents/SAC(+LSTM)/env.py"
    click WG "https://github.com/sidag26/dre-scale/blob/main/workload-generator/request_generator.py"
    click WG "https://github.com/sidag26/dre-scale/blob/main/workload-generator/invokation_data.json"
    click WG "https://github.com/sidag26/dre-scale/blob/main/workload-generator/requirements.txt"
    click NB "https://github.com/sidag26/dre-scale/blob/main/experimental-results/analysisUtility.ipynb"
    click IMG "https://github.com/sidag26/dre-scale/tree/main/experimental-results/images/"

    %% Styles
    classDef infrastructure fill:#AED6F1,stroke:#21618C,color:#1B4F72,stroke-width:1px
    classDef dataPlane fill:#D5F5E3,stroke:#27AE60,color:#145A32,stroke-width:1px
    classDef controlPlane fill:#FAD7A0,stroke:#D35400,color:#873600,stroke-width:1px
    classDef experimental fill:#E8DAEF,stroke:#7D3C98,color:#512E5F,stroke-width:1px
```
