# lxc/incus architecture

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

- Interactive diagram: https://gitdiagram.com/lxc/incus
- Repository: https://github.com/lxc/incus

## Overview

##### Main Components Overview

The system should be divided into these major components:

a) Core Services:
- Daemon (incusd) - The main server component
- Client (incus) - Command-line interface
- Agent (incus-agent) - Runs inside instances
- REST API - For external communication

b) Storage Layer:
- Multiple backend drivers (btrfs, ceph, dir, lvm, zfs)
- Volume management
- Storage pools
- Backup systems

c) Network Layer:
- Network management (bridges, macvlan, sriov)
- DNS/DHCP handling
- Firewall management
- OVN integration

d) Instance Layer:
- Container management
- VM management
- Instance operations
- Resource control

##### Relationship Flows

**External Clients -> REST API -> Daemon**
- > Authentication/Authorization
- > Database
- > Storage
- > Network
- > Instances

##### Detailed Component Breakdown

a) Server (incusd):
- API endpoints
- Authentication
- Database management
- Event system
- Clustering support
- Resource management

b) Client Layer:
- CLI interface
- Remote connections
- Certificate management
- Project handling

c) Storage Subsystem:
- Volume management
- Backup operations
- Storage pools
- Different backend drivers

d) Network Subsystem:
- Network creation/management
- DNS/DHCP services
- Firewall rules
- Network ACLs
- Load balancing

##### Specific Implementation Details

Key architectural elements:
- REST API endpoints
- Database schema
- Event system
- Storage driver interfaces
- Network management
- Instance lifecycle management
- Security components

##### API-first design philosophy

Remember to maintain a balance between detail and clarity, focusing on the architectural relationships while avoiding overwhelming technical minutiae.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph External
        CLI["Client CLI"]:::client
        ExtApps["External Applications"]:::external
    end

    subgraph Core
        API["REST API Layer"]:::api
        Daemon["Core Daemon Service"]:::core
        Auth["Authentication"]:::security
        DB["Database Layer"]:::database
        Metrics["Metrics System"]:::monitoring
        Cluster["Clustering"]:::core
    end

    subgraph "Storage System"
        StorageMain["Storage System"]:::storage
        subgraph "Storage Drivers"
            Btrfs["BTRFS"]:::storage
            ZFS["ZFS"]:::storage
            LVM["LVM"]:::storage
            Ceph["Ceph"]:::storage
        end
    end

    subgraph "Network Layer"
        NetMgmt["Network Management"]:::network
        Firewall["Firewall Management"]:::network
        DNSDHCP["DNS/DHCP Services"]:::network
        OVN["Network OVN Integration"]:::network
    end

    subgraph "Instance Layer"
        InstMgmt["Instance Management"]:::instance
        subgraph "Instance Types"
            Containers["Containers"]:::instance
            VMs["Virtual Machines"]:::instance
        end
        Agent["Agent Service"]:::instance
    end

    subgraph "Project Layer"
        Projects["Project Management"]:::project
    end

    %% Relationships
    CLI --> API
    ExtApps --> API
    API --> Auth
    Auth --> Daemon
    Daemon --> DB
    Daemon --> Metrics
    Daemon --> Cluster
    Daemon --> StorageMain
    Daemon --> NetMgmt
    Daemon --> InstMgmt
    Daemon --> Projects

    StorageMain --> Btrfs & ZFS & LVM & Ceph
    NetMgmt --> Firewall & DNSDHCP & OVN
    InstMgmt --> Containers & VMs
    InstMgmt --> Agent

    %% Click Events
    click CLI "https://github.com/lxc/incus/tree/main/cmd/incus/"
    click Daemon "https://github.com/lxc/incus/tree/main/cmd/incusd/"
    click Agent "https://github.com/lxc/incus/tree/main/cmd/incus-agent/"
    click API "https://github.com/lxc/incus/tree/main/internal/server/endpoints/"
    click StorageMain "https://github.com/lxc/incus/tree/main/internal/server/storage/"
    click Btrfs,ZFS,LVM,Ceph "https://github.com/lxc/incus/tree/main/internal/server/storage/drivers/"
    click NetMgmt "https://github.com/lxc/incus/tree/main/internal/server/network/"
    click OVN "https://github.com/lxc/incus/tree/main/internal/server/network/ovn/"
    click InstMgmt "https://github.com/lxc/incus/tree/main/internal/server/instance/"
    click Containers,VMs "https://github.com/lxc/incus/tree/main/internal/server/instance/drivers/"
    click DB "https://github.com/lxc/incus/tree/main/internal/server/db/"
    click Auth "https://github.com/lxc/incus/tree/main/internal/server/auth/"
    click Cluster "https://github.com/lxc/incus/tree/main/internal/server/cluster/"
    click Firewall "https://github.com/lxc/incus/tree/main/internal/server/firewall/"
    click DNSDHCP "https://github.com/lxc/incus/tree/main/internal/server/dnsmasq/"
    click Metrics "https://github.com/lxc/incus/tree/main/internal/server/metrics/"
    click Projects "https://github.com/lxc/incus/tree/main/internal/server/project/"

    %% Styles
    classDef core fill:#2374ab
    classDef client fill:#878787
    classDef external fill:#878787
    classDef api fill:#2374ab
    classDef security fill:#9b4dca
    classDef database fill:#2374ab
    classDef monitoring fill:#2374ab
    classDef storage fill:#ff7f50
    classDef network fill:#4caf50
    classDef instance fill:#ffd700
    classDef project fill:#2374ab
```
