# virt-do/cloudlet architecture

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

- Interactive diagram: https://gitdiagram.com/virt-do/cloudlet
- Repository: https://github.com/virt-do/cloudlet

## Overview

##### Project type and purpose
- This is a distributed FaaS (Function-as-a-Service) system written in Rust.
- It comprises a CLI client, an HTTP/gRPC API server, a Virtual Machine Monitor (VMM), and an in-VM agent.
- Supporting crates generate boot artifacts (kernel + initramfs) and share protobuf models.

##### File structure
- Top-level Cargo.toml defines a workspace of multiple Rust crates under `src/`:
- `cli` – command-line client that reads a TOML config and issues HTTP requests.
- `api` – HTTP server exposing a `/run` endpoint; uses gRPC proto in `proto/` to talk to VMM.
- `vmm` – Virtual Machine Monitor: boots VMs, exposes a gRPC server, implements devices, networking, epoll.
- `agent` – runs inside each guest VM; hosts a gRPC server to build and execute user code.
- `fs-gen` – filesystem and initramfs image builder (invoked at first run).
- `shared-models` – common protobuf-generated types.
- `proto/` holds .proto definitions for inter-service gRPC (agent.proto, vmm.proto).
- `tools/` contains shell scripts and kernel config for building a custom Linux binary and root filesystem.
- CI workflows lint Rust code and test on push/pull requests.

##### README for architectural insights
CLI → HTTP → API → gRPC → VMM → gRPC → Agent → (build & run) → stream results back.
- Describes prerequisites, how to start each service, and configuration file schema.

##### Elements
- A third for build artifacts and shared models.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Local Environment
    subgraph "Local Environment"
        CLI["CLI Client"]:::frontend
    end

    %% Build Layer
    subgraph "Build Layer"
        Build["Build Tools (fs-gen + tools)"]:::build
    end

    %% Contract Layer
    subgraph "Contract Layer"
        ProtoAgent["agent.proto"]:::contract
        ProtoVMM["vmm.proto"]:::contract
        Models["Shared Models (shared-models)"]:::contract
    end

    %% Orchestration Plane
    subgraph "Orchestration Plane"
        API["API Server"]:::backend
        VMM["VMM Service"]:::system
    end

    %% Execution Plane
    subgraph "Execution Plane"
        VM["Guest VM + Agent"]:::system
    end

    %% Request Flows
    CLI -->|"HTTP/1.1 JSON POST /run"| API
    API -->|"gRPC/protobuf"| VMM
    VMM -.->|"build-time dependency"| Build
    VMM -->|"Spawn VM"| VM
    VMM -->|"gRPC/protobuf"| VM
    VM ---|"gRPC stream logs/results"| VMM
    VMM ---|"gRPC stream logs/results"| API
    API -->|"HTTP/1.1 JSON response"| CLI

    %% Contract Dependencies
    ProtoAgent -.-> API
    ProtoAgent -.-> VMM
    ProtoAgent -.-> VM
    ProtoVMM -.-> API
    ProtoVMM -.-> VMM
    ProtoVMM -.-> VM
    Models -.-> API
    Models -.-> VMM
    Models -.-> VM

    %% Click Events
    click CLI "https://github.com/virt-do/cloudlet/blob/main/src/cli/Cargo.toml"
    click API "https://github.com/virt-do/cloudlet/blob/main/src/api/Cargo.toml"
    click VMM "https://github.com/virt-do/cloudlet/blob/main/src/vmm/Cargo.toml"
    click VM "https://github.com/virt-do/cloudlet/blob/main/src/agent/Cargo.toml"
    click Build "https://github.com/virt-do/cloudlet/blob/main/src/fs-gen/Cargo.toml"
    click Models "https://github.com/virt-do/cloudlet/blob/main/src/shared-models/Cargo.toml"
    click ProtoAgent "https://github.com/virt-do/cloudlet/blob/main/proto/agent.proto"
    click ProtoVMM "https://github.com/virt-do/cloudlet/blob/main/proto/vmm.proto"

    %% Styles
    classDef frontend fill:#FFD580,stroke:#D4A017,color:#000;
    classDef backend fill:#80CFFF,stroke:#1685A9,color:#000;
    classDef system fill:#C0FFC0,stroke:#28A828,color:#000;
    classDef build fill:#FFC0CB,stroke:#C81446,color:#000;
    classDef contract fill:#E0E0E0,stroke:#888,color:#000;
```
