# pikvm/kvmd architecture

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

- Interactive diagram: https://gitdiagram.com/pikvm/kvmd
- Repository: https://github.com/pikvm/kvmd

## Overview

##### Main Components

a. Core Services Layer:
- KVMD Main Service
- Web Interface
- Authentication System
- Streaming Services (Janus)
- VNC Server
- IPMI Service

b. Hardware Interface Layer:
- HID Controllers (Arduino/Pico)
- Video Capture
- ATX Control
- GPIO Management
- USB OTG Management

c. External Interfaces:
- Web Clients
- VNC Clients
- IPMI Clients
- REST API

**[Client Layer]**
- ↑↓
**[Web/API Gateway (Nginx)]**
- ↑↓
**[Core Services Layer]**
- ↑↓
**[Hardware Interface Layer]**
- ↑↓
**[Physical Hardware]**

##### Key Elements to Highlight

a. Service Communication:
- Use different line styles for control flow vs data flow
- WebSocket connections for real-time features

b. Authentication Flow:
- Auth plugins integration (htpasswd, LDAP, PAM, etc.)

c. Video Streaming Pipeline:
- → Processing → Streaming
- Both MJPEG and WebRTC paths

##### Component Details

- Main responsibilities
- Key configurations
- Plugin points
- Resource requirements

##### Specific Implementation Notes

a. Web Interface:
- Separation between static content and dynamic API
- WebSocket connections for real-time control

b. Hardware Control:
- HID protocol implementation
- ATX power management flow
- USB gadget mode configuration

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph Clients
        WC[Web Clients]:::client
        VC[VNC Clients]:::client
        IC[IPMI Clients]:::client
    end

    %% Gateway Layer
    NG[Nginx Gateway]:::gateway

    %% Core Services Layer
    subgraph CoreServices
        KVMD[KVMD Main Service]:::core
        WI[Web Interface]:::web
        AS[Authentication System]:::security
        SS[Streaming Services]:::stream
        VNC[VNC Server]:::core
        IPMI[IPMI Service]:::core
        API[REST API]:::api
    end

    %% Hardware Interface Layer
    subgraph HardwareInterface
        HID[HID Controllers]:::hardware
        VC_HW[Video Capture]:::hardware
        ATX[ATX Control]:::hardware
        GPIO[GPIO Management]:::hardware
        USB[USB OTG Management]:::hardware
    end

    %% Physical Hardware Layer
    subgraph Hardware
        ARD[Arduino/Pico]:::physical
        CAP[Capture Device]:::physical
        PWR[Power Control]:::physical
        PINS[GPIO Pins]:::physical
        USBP[USB Ports]:::physical
    end

    %% Connections
    WC --> NG
    VC --> NG
    IC --> NG
    NG --> KVMD
    NG --> WI
    NG --> API

    KVMD --> AS
    KVMD --> SS
    KVMD --> VNC
    KVMD --> IPMI
    KVMD --> API

    KVMD --> HID
    KVMD --> VC_HW
    KVMD --> ATX
    KVMD --> GPIO
    KVMD --> USB

    HID --> ARD
    VC_HW --> CAP
    ATX --> PWR
    GPIO --> PINS
    USB --> USBP

    %% Styles
    classDef client fill:#90EE90
    classDef gateway fill:#FFB6C1
    classDef core fill:#87CEEB
    classDef web fill:#DDA0DD
    classDef security fill:#FF6347
    classDef stream fill:#F0E68C
    classDef api fill:#98FB98
    classDef hardware fill:#FFA500
    classDef physical fill:#D3D3D3

    %% Click Events
    click KVMD "https://github.com/pikvm/kvmd/blob/master/kvmd/apps/kvmd/__main__.py"
    click AS "https://github.com/pikvm/kvmd/tree/master/kvmd/plugins/auth/"
    click SS "https://github.com/pikvm/kvmd/tree/master/kvmd/apps/janus/"
    click VNC "https://github.com/pikvm/kvmd/tree/master/kvmd/apps/vnc/"
    click IPMI "https://github.com/pikvm/kvmd/tree/master/kvmd/apps/ipmi/"
    click WI "https://github.com/pikvm/kvmd/tree/master/web/"
    click HID "https://github.com/pikvm/kvmd/tree/master/hid/arduino/"
    click GPIO "https://github.com/pikvm/kvmd/tree/master/kvmd/plugins/ugpio/"
    click USB "https://github.com/pikvm/kvmd/tree/master/kvmd/apps/otg/"
    click ATX "https://github.com/pikvm/kvmd/tree/master/kvmd/plugins/atx/"
    click API "https://github.com/pikvm/kvmd/tree/master/kvmd/apps/kvmd/api/"
```
