# slimplanet/slimfaas architecture

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

- Interactive diagram: https://gitdiagram.com/slimplanet/slimfaas
- Repository: https://github.com/slimplanet/slimfaas

## Overview

##### Project Type and Purpose
- SlimFaas is a “Function as a Service” (FaaS) platform that acts as an HTTP proxy for handling both synchronous and asynchronous function calls. It encapsulates auto‑scaling, scheduling, event publishing, and health-check mechanisms.
- The README describes scaling behaviors (scaling down to 0, scaling up on HTTP triggers), various HTTP endpoints (synchronous, asynchronous, wake, publish event), and integration with Kubernetes. There’s also a front-end component demo (FibonacciReact and SlimFaasPlanetSaver) that provides a user interface for monitoring and triggering functions.
- The project is built with .NET for the backend purposes, and there is a JavaScript/React front-end along with Kubernetes/Docker deployment configurations.

##### Analyzing the File Structure
- Top-Level Directories and Files: You have directories like “src”, “demo”, “documentation”, and “tests”, alongside CI/CD workflows, Dockerfiles, and configuration files (e.g., docker-compose.yml, SlimFaas.sln).
- In the “src” directory you see multiple projects:
- Backend service projects: “SlimFaas” deals with the proxy and function management, “SlimData” implements an in‑memory distributed datastore based on Raft, and “Fibonacci” / “FibonacciBatch” serve as sample functions.
- Frontend projects: “FibonacciReact” and “SlimFaasPlanetSaver” show client applications to interact with the functions.
- Benchmarking and ancillary tools: “SlimFaasBenchmark”.
- You also see detailed Kubernetes deployment YAML files in the “demo” directory (for functions, MySQL, ingress, nodeport) that provide insight into how the system integrates with a Kubernetes cluster.
- The presence of multiple Dockerfiles in both the backend and frontend projects indicates containerized deployment in production.

##### Architectural Insights from the README
- The README explains that SlimFaas works by exposing HTTP endpoints used by clients to invoke functions:
- Synchronous calls: Endpoint “/function/<functionName>/...”
- Asynchronous calls: Endpoint “/async-function/<functionName>/...”
- Special endpoints to wake up functions and publish events.
- It details internal workers (SlimWorker, HistorySynchronousWorker, ReplicasScaleWorker, etc.) responsible for routing requests, scaling pods, and synchronizing function replicas.
- The README also describes the integrated “SlimData” component that leverages the Raft consensus algorithm to keep state and history.
- Deployment instructions emphasize Kubernetes annotations on pods, illustrating that auto‑scaling is achieved by simply deploying standard pods with specific annotations.

##### Specific Elements
- Each component should have clear labels:
- “API Gateway (SlimFaas)”
- “Function Containers (e.g., Fibonacci, FibonacciBatch)”
- “Internal Worker Modules (SlimWorker, ScaleWorker, etc.)”
- “Distributed Data Store (SlimData – Raft cluster)”
- “Client Applications (FibonacciReact, SlimFaasPlanetSaver)”
- “Kubernetes Infrastructure” (illustrate Pods, Deployments, Services, Ingress/NodePort boundaries)
- Data flow from client to gateway.
- Request routing from gateway to function pods.
- Internal synchronization between gateway and data store.
- Scaling decisions fed back to Kubernetes.

##### Final Advice
- Layer (client, API, function execution, data management, infrastructure) is clearly delineated, and annotate each with the key technologies or design principles in use.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        CR["FibonacciReact (Client)"]:::client
        CP["SlimFaasPlanetSaver (Client)"]:::client
    end

    %% API Layer
    subgraph "API Layer"
        API["API Gateway (SlimFaas)"]:::apiLayer
        %% Internal Workers within API layer
        subgraph "Internal Workers"
            SW["SlimWorker"]:::worker
            HS["HistorySynchronizationWorker"]:::worker
            RS["ReplicasScaleWorker"]:::worker
            RSync["ReplicasSynchronizationWorker"]:::worker
        end
    end

    %% Function Containers
    subgraph "Function Containers"
        Fibo["Fibonacci (Function)"]:::function
        FiboBatch["FibonacciBatch (Function)"]:::function
    end

    %% Data Store
    subgraph "Data Store"
        Data["Distributed Data Store (SlimData - Raft)"]:::datastore
    end

    %% Kubernetes Infrastructure
    subgraph "Kubernetes Infrastructure"
        K8s["K8s Services, Deployments & Ingress"]:::infra
        K8sDeploy["Deployment Configurations"]:::infra
    end

    %% Connections from Clients to API Gateway
    CR -- "HTTP_requests" --> API
    CP -- "HTTP_requests" --> API

    %% API Gateway to Function Containers
    API -- "sync/async_calls" --> Fibo
    API -- "sync/async_calls" --> FiboBatch

    %% API Gateway internal routing to Workers
    API -- "routes_async" --> SW
    API -- "logs_requests" --> HS
    API -- "scale_triggers" --> RS
    API -- "replica_sync" --> RSync

    %% Workers interactions with Data Store and Kubernetes
    HS -- "update_history" --> Data
    RSync -- "sync_state" --> Data
    SW -- "scale_signal" --> K8s
    RS -- "scale_signal" --> K8s

    %% API Gateway state synchronization with Data Store
    API -- "state_sync" --> Data

    %% Kubernetes configuration flow
    K8sDeploy -- "configures" --> K8s

    %% Feedback loop: API may also trigger Kubernetes actions
    API -- "deployment_trigger" --> K8s

    %% Class definitions for styling
    classDef client fill:#bfd8d2,stroke:#036,stroke-width:2px;
    classDef apiLayer fill:#e3d4b9,stroke:#b34,stroke-width:2px;
    classDef worker fill:#ffd6a5,stroke:#cc3300,stroke-width:2px;
    classDef function fill:#ffadad,stroke:#f03,stroke-width:2px;
    classDef datastore fill:#caffbf,stroke:#006400,stroke-width:2px;
    classDef infra fill:#9bf6ff,stroke:#008b8b,stroke-width:2px;

    %% Click Events
    click API "https://github.com/slimplanet/slimfaas/tree/main/src/SlimFaas"
    click Fibo "https://github.com/slimplanet/slimfaas/tree/main/src/Fibonacci"
    click FiboBatch "https://github.com/slimplanet/slimfaas/tree/main/src/FibonacciBatch"
    click CR "https://github.com/slimplanet/slimfaas/tree/main/src/FibonacciReact"
    click CP "https://github.com/slimplanet/slimfaas/tree/main/src/SlimFaasPlanetSaver"
    click HS "https://github.com/slimplanet/slimfaas/blob/main/src/SlimFaas/HistorySynchronizationWorker.cs"
    click RS "https://github.com/slimplanet/slimfaas/blob/main/src/SlimFaas/ReplicasScaleWorker.cs"
    click RSync "https://github.com/slimplanet/slimfaas/blob/main/src/SlimFaas/ReplicasSynchronizationWorker.cs"
    click Data "https://github.com/slimplanet/slimfaas/tree/main/src/SlimData"
    click K8s "https://github.com/slimplanet/slimfaas/tree/main/src/SlimFaas/Kubernetes"
    click K8sDeploy "https://github.com/slimplanet/slimfaas/tree/main/demo"
```
