# skypilot-org/skypilot architecture

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

- Interactive diagram: https://gitdiagram.com/skypilot-org/skypilot
- Repository: https://github.com/skypilot-org/skypilot

## Overview

##### Identifying the Main Components and Their Roles
- Client/CLI Layer: This includes components like sky/cli.py and sky/client/sdk.py that parse the YAML (or Python API) job definition and allow users to launch tasks.
- API Server / Job Management:
– The API server logic is primarily found across directories such as sky/jobs/server/ (e.g., server.py in sky/jobs/server) and parts of sky/server/. This layer is responsible for handling incoming requests, managing job states, and providing endpoints for status queries.
- Scheduler and Orchestrator:
– The orchestrator handles the task scheduling and resource allocation logic, which interacts with both the provisioning subsystems and the backends.
- Provisioners:
- Backends – Highlighting CloudVMRayBackend:
– The CloudVMRayBackend (located in sky/backends/cloud_vm_ray_backend.py) is a specialized backend that integrates with the Ray framework. It’s used to manage distributed compute clusters (Ray clusters) and tie into the general job orchestration flow. Illustrate its role as a module that receives job submissions from the API server/scheduler and handles task distribution through Ray.
- Data Management and Synchronization:
– Modules like sky/data, which manage code and data synchronization between local work directories and remote cloud instances, are essential for moving job artifacts.
- Logging, Exception Handling, and Utility Layers:
– These support all core functionalities, ensuring that job provisioning, execution, and recovery are robust.

##### Relationships and Interactions
- For tasks that require distributed computing, the API server/scheduler will choose a backend – most notably, the CloudVMRayBackend. This should be clearly shown as a dedicated component receiving jobs from the scheduler and interfacing with the Ray cluster infrastructure.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client/CLI Layer
    subgraph "Client/CLI Layer"
        CLI["CLI"]:::cli
        SDK["SDK"]:::cli
    end

    %% API Server / Job Management
    subgraph "API Server / Job Management"
        API1["API Server (sky/jobs/server)"]:::api
        API2["API Server (sky/server)"]:::api
    end

    %% Scheduler and Orchestrator
    subgraph "Scheduler and Orchestrator"
        SCHED["Scheduler (sky/jobs/scheduler)"]:::sched
        CTRL["Controller (sky/jobs/controller)"]:::sched
    end

    %% Provisioners
    subgraph "Provisioners"
        PROV["Provisioners (sky/provision)"]:::prov
        AWS["AWS Adapter"]:::prov
        AZURE["Azure Adapter"]:::prov
        GCP["GCP Adapter"]:::prov
        OCI["OCI Adapter"]:::prov
        K8S["Kubernetes Adapter"]:::prov
    end

    %% Backends
    subgraph "Backends"
        CLOUDVM["CloudVMRayBackend"]:::backend
    end

    %% Data Management & Synchronization
    subgraph "Data Management & Synchronization"
        DATA["Data Management (sky/data)"]:::data
    end

    %% Logging & Utilities
    subgraph "Logging & Utilities"
        LOG["Logging & Exceptions"]:::log
        UTILS["Utilities (sky/utils)"]:::utils
    end

    %% Connections
    CLI -->|"submits"| API1
    SDK -->|"submits"| API1

    API1 -->|"manages"| SCHED
    API2 -->|"manages"| SCHED

    API1 -->|"provisions"| PROV
    SCHED -->|"schedules"| PROV
    SCHED -->|"dispatches"| CLOUDVM
    SCHED -->|"controls"| CTRL

    PROV -->|"routes to"| AWS
    PROV -->|"routes to"| AZURE
    PROV -->|"routes to"| GCP
    PROV -->|"routes to"| OCI
    PROV -->|"routes to"| K8S

    API1 -->|"syncs"| DATA

    API1 -->|"logs"| LOG
    SCHED -->|"logs"| LOG
    PROV -->|"logs"| LOG
    CLOUDVM -->|"logs"| LOG

    %% Click Events
    click CLI "https://github.com/skypilot-org/skypilot/blob/master/sky/cli.py"
    click SDK "https://github.com/skypilot-org/skypilot/blob/master/sky/client/sdk.py"
    click API1 "https://github.com/skypilot-org/skypilot/blob/master/sky/jobs/server/server.py"
    click API2 "https://github.com/skypilot-org/skypilot/blob/master/sky/server/server.py"
    click SCHED "https://github.com/skypilot-org/skypilot/blob/master/sky/jobs/scheduler.py"
    click CTRL "https://github.com/skypilot-org/skypilot/blob/master/sky/jobs/controller.py"
    click PROV "https://github.com/skypilot-org/skypilot/tree/master/sky/provision/"
    click CLOUDVM "https://github.com/skypilot-org/skypilot/blob/master/sky/backends/cloud_vm_ray_backend.py"
    click DATA "https://github.com/skypilot-org/skypilot/tree/master/sky/data/"
    click LOG "https://github.com/skypilot-org/skypilot/blob/master/sky/sky_logging.py"
    click UTILS "https://github.com/skypilot-org/skypilot/tree/master/sky/utils/"

    %% Styles
    classDef cli fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef api fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef sched fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef prov fill:#FFA500,stroke:#000,stroke-width:2px;
    classDef backend fill:#FF6347,stroke:#000,stroke-width:2px;
    classDef data fill:#AFEEEE,stroke:#000,stroke-width:2px;
    classDef log fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef utils fill:#F0E68C,stroke:#000,stroke-width:2px;
```
