# psviderski/uncloud architecture

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

- Interactive diagram: https://gitdiagram.com/psviderski/uncloud
- Repository: https://github.com/psviderski/uncloud

## Overview

##### Main Components

a) Client Layer:
- CLI components (`cmd/uncloud` and `cmd/ucind`)
- Main command groups: machine, service, and cluster management

b) Control Plane:
- Daemon component (`cmd/uncloudd`)
- Cluster management system
- Configuration management system

c) Machine Layer:
- Docker host management
- Network management (WireGuard)
- Container orchestration
- Storage management

d) Communication Layer:
- gRPC API services (visible in `internal/machine/api/pb`)
- Network tunneling
- SSH connectivity

##### Key Relationships to Illustrate

**[Client CLI] → [Control Plane Daemon] → [Machine Layer]**
- ↓
- [Network Mesh Layer]

##### Specific Component Details

a) Control Plane Components:
- Subcomponents:
- Cluster State Manager
- IPAM (IP Address Management)
- Service Orchestrator
- Configuration Store

b) Machine Layer Components:
- Docker Engine integration
- Network management (WireGuard)
- Container runtime
- Storage subsystem

c) Network Mesh:
- WireGuard overlay network
- Service discovery
- Load balancing

##### Important Architectural Patterns to Highlight

- Peer-to-peer nature of the network mesh
- Service discovery mechanism
- Demonstrate the control plane's relationship with individual nodes
- How configuration propagates through the system

##### Technical Details

- gRPC API endpoints
- WireGuard overlay network
- Docker API integration
- State management system
- Configuration distribution

**┌─ Client Layer ─────┐    ┌─ Control Plane ──────┐    ┌─ Machine Layer ─────┐**
- uncloud CLI     │    │ - Cluster Management  │    │ - Docker Runtime    │
- ucind CLI       │━━━▶│ - Service Orchestrator│━━━▶│ - Container Mgmt   │
- ┘    │ - Configuration Store  │    │ - Network Overlay   │
- ┬────────────┘    └──────────┬─────────┘

- ▼                             ▼
- ┌─ Network Mesh ──────────────────────────┐
- WireGuard Overlay                     │
- Service Discovery                     │
- Load Balancing                        │
- ┘

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph CL[Client Layer]
        CLI["uncloud CLI"]:::client
        UCIND["ucind CLI"]:::client
        MCH["Machine Management"]:::client
        SVC["Service Management"]:::client
    end

    %% Control Plane
    subgraph CP[Control Plane]
        DC["Daemon Core"]:::control
        CM["Cluster Management"]:::control
        CFG["Configuration Management"]:::control
        SM["State Management"]:::control
        IPAM["IP Address Management"]:::control
        SO["Service Orchestrator"]:::control
    end

    %% Machine Layer
    subgraph ML[Machine Layer]
        DI["Docker Integration"]:::machine
        CNM["Container Management"]:::machine
        NM["Network Management"]:::machine
        WG["WireGuard Implementation"]:::machine
    end

    %% Communication Layer
    subgraph COM[Communication Layer]
        GRPC["gRPC API"]:::comm
        SSH["SSH Connectivity"]:::comm
        NT["Network Tunneling"]:::comm
        AP["API Proxying"]:::comm
    end

    %% Core Services
    subgraph CS[Core Services]
        SO_SVC["Service Orchestration"]:::service
        IPAM_SVC["IPAM Service"]:::service
        TM["Token Management"]:::service
        MS["Machine State"]:::service
    end

    %% Security
    subgraph SEC[Security Layer]
        SM_SEC["Secret Management"]:::security
        TH["Token Handling"]:::security
    end

    %% Relationships
    CLI --> DC
    UCIND --> DC
    MCH --> CM
    SVC --> SO

    DC --> CM
    DC --> CFG
    DC --> SM
    CM --> IPAM
    CM --> SO

    SO --> DI
    SO --> CNM
    CNM --> NM
    NM --> WG

    DC --> GRPC
    GRPC --> SSH
    GRPC --> NT
    NT --> AP

    SO --> SO_SVC
    IPAM --> IPAM_SVC
    DC --> TM
    CM --> MS

    GRPC --> SM_SEC
    TM --> TH

    %% Styles
    classDef client fill:#9370DB
    classDef control fill:#4682B4
    classDef machine fill:#FF8C00
    classDef comm fill:#20B2AA
    classDef service fill:#3CB371
    classDef security fill:#CD5C5C

    %% Click Events
    click CLI "https://github.com/psviderski/uncloud/tree/main/cmd/uncloud/"
    click UCIND "https://github.com/psviderski/uncloud/tree/main/cmd/ucind/"
    click MCH "https://github.com/psviderski/uncloud/tree/main/cmd/uncloud/machine/"
    click SVC "https://github.com/psviderski/uncloud/tree/main/cmd/uncloud/service/"
    click DC "https://github.com/psviderski/uncloud/tree/main/cmd/uncloudd/"
    click CM "https://github.com/psviderski/uncloud/tree/main/internal/machine/cluster/"
    click CFG "https://github.com/psviderski/uncloud/tree/main/internal/cli/config/"
    click SM "https://github.com/psviderski/uncloud/tree/main/internal/machine/store/"
    click DI "https://github.com/psviderski/uncloud/tree/main/internal/machine/docker/"
    click CNM "https://github.com/psviderski/uncloud/blob/main/internal/machine/store/container.go"
    click NM "https://github.com/psviderski/uncloud/tree/main/internal/machine/network/"
    click WG "https://github.com/psviderski/uncloud/blob/main/internal/machine/network/wireguard.go"
    click GRPC "https://github.com/psviderski/uncloud/tree/main/internal/machine/api/pb/"
    click SSH "https://github.com/psviderski/uncloud/tree/main/internal/sshexec/"
    click NT "https://github.com/psviderski/uncloud/tree/main/internal/machine/network/tunnel/"
    click AP "https://github.com/psviderski/uncloud/tree/main/internal/machine/api/proxy/"
    click SO_SVC "https://github.com/psviderski/uncloud/tree/main/internal/machine/corroservice/"
    click IPAM_SVC "https://github.com/psviderski/uncloud/blob/main/internal/machine/cluster/ipam.go"
    click TM "https://github.com/psviderski/uncloud/blob/main/internal/machine/token.go"
    click MS "https://github.com/psviderski/uncloud/blob/main/internal/machine/state.go"
    click SM_SEC "https://github.com/psviderski/uncloud/tree/main/internal/secret/"
    click TH "https://github.com/psviderski/uncloud/blob/main/internal/daemon/token.go"
```
