# longhorn/longhorn-spdk-engine architecture

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

- Interactive diagram: https://gitdiagram.com/longhorn/longhorn-spdk-engine
- Repository: https://github.com/longhorn/longhorn-spdk-engine

## Overview

##### Main Components Identification

a. Core Engine Layer
- Server component (pkg/spdk/server.go) as the interface layer

b. Storage Drivers Layer
- NVMe Driver
- AIO Driver
- Virtio-BLK Driver
- Virtio-SCSI Driver

c. Data Management Layer
Following components:
- Backing Image Manager
- Replica Manager
- Backup Manager
- Restore Manager

##### Component Relationships

**API Layer (pkg/api) → Server → Engine Core → Disk Drivers**
- ↓
- Data Management Components

##### Detailed Component Breakdown

a. Core Engine:
**┌─────────────────────┐**
- SPDK Engine     │
- ┤
- Engine Core       │
- Server Component  │
- Utility Functions │
- ┘

b. Storage Drivers:
**┌─────────────────────┐**
- Storage Drivers   │
- ┤
- NVMe             │
- AIO              │
- Virtio-BLK       │
- Virtio-SCSI      │
- ┘

c. Data Management:
**┌─────────────────────┐**
- Data Management    │
- ┤
- Backing Image     │
- Replica          │
- Backup           │
- Restore          │
- ┘

##### Technical Details

- Async operations with appropriate symbols
- Connection points to physical storage devices
- Where poll-mode drivers interact with hardware
- High-performance paths with distinct line styles

##### Additional Notes

- Keep the focus on the SPDK integration aspects
- Clear boundaries between user-space and kernel-space components
- Where performance critical paths exist
- Points of interaction with the broader Longhorn ecosystem

## Diagram (Mermaid)

```mermaid
graph TB
    %% Core Components
    Engine["SPDK Engine"]:::core
    Server["Server Component"]:::core
    
    %% API Layer
    subgraph API["API Layer"]
        APITypes["API Types"]:::api
        Client["Client Interface"]:::api
    end
    
    %% Storage Drivers
    subgraph Drivers["Storage Drivers"]
        direction TB
        DriverInterface["Base Driver Interface"]:::driver
        NVMe["NVMe Driver"]:::driver
        AIO["AIO Driver"]:::driver
        VirtioBLK["Virtio-BLK Driver"]:::driver
        VirtioSCSI["Virtio-SCSI Driver"]:::driver
        
        DriverInterface --> NVMe
        DriverInterface --> AIO
        DriverInterface --> VirtioBLK
        DriverInterface --> VirtioSCSI
    end
    
    %% Data Management
    subgraph DataMgmt["Data Management"]
        direction TB
        BackingImage["Backing Image Manager"]:::datamgmt
        Replica["Replica Manager"]:::datamgmt
        Backup["Backup Manager"]:::datamgmt
        Restore["Restore Manager"]:::datamgmt
    end
    
    %% Utility Components
    subgraph Utils["Utilities"]
        direction TB
        CoreUtils["Core Utilities"]:::util
        Logging["Logging"]:::util
        Types["Type Definitions"]:::util
    end
    
    %% Relationships
    APITypes --> Server
    Client --> Server
    Server --> Engine
    Engine --> DriverInterface
    Engine --> DataMgmt
    Engine --> Utils
    
    %% Click Events
    click Engine "https://github.com/longhorn/longhorn-spdk-engine/blob/main/pkg/spdk/engine.go"
    click Server "https://github.com/longhorn/longhorn-spdk-engine/blob/main/pkg/spdk/server.go"
    click APITypes "https://github.com/longhorn/longhorn-spdk-engine/blob/main/pkg/api/types.go"
    click Client "https://github.com/longhorn/longhorn-spdk-engine/blob/main/pkg/client/client.go"
    click DriverInterface "https://github.com/longhorn/longhorn-spdk-engine/blob/main/pkg/spdk/disk/driver.go"
    click NVMe "https://github.com/longhorn/longhorn-spdk-engine/blob/main/pkg/spdk/disk/nvme/nvme.go"
    click AIO "https://github.com/longhorn/longhorn-spdk-engine/blob/main/pkg/spdk/disk/aio/aio.go"
    click VirtioBLK "https://github.com/longhorn/longhorn-spdk-engine/blob/main/pkg/spdk/disk/virtio-blk/virtio-blk.go"
    click VirtioSCSI "https://github.com/longhorn/longhorn-spdk-engine/blob/main/pkg/spdk/disk/virtio-scsi/virtio-scsi.go"
    click BackingImage "https://github.com/longhorn/longhorn-spdk-engine/blob/main/pkg/spdk/backing_image.go"
    click Replica "https://github.com/longhorn/longhorn-spdk-engine/blob/main/pkg/spdk/replica.go"
    click Backup "https://github.com/longhorn/longhorn-spdk-engine/blob/main/pkg/spdk/backup.go"
    click Restore "https://github.com/longhorn/longhorn-spdk-engine/blob/main/pkg/spdk/restore.go"
    click CoreUtils "https://github.com/longhorn/longhorn-spdk-engine/blob/main/pkg/spdk/util.go"
    click Logging "https://github.com/longhorn/longhorn-spdk-engine/blob/main/pkg/spdk/log.go"
    click Types "https://github.com/longhorn/longhorn-spdk-engine/blob/main/pkg/spdk/types.go"
    
    %% Styles
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef api fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef driver fill:#4CAF50,stroke:#388E3C,color:white
    classDef datamgmt fill:#FFC107,stroke:#FFA000,color:black
    classDef util fill:#607D8B,stroke:#455A64,color:white
    
    %% Legend
    subgraph Legend
        CoreL["Core Components"]:::core
        APIL["API Components"]:::api
        DriverL["Storage Drivers"]:::driver
        DataL["Data Management"]:::datamgmt
        UtilL["Utilities"]:::util
    end
```
