How sipeed/nanokvm works
Project Type and Purpose
• The project is a full-stack solution for an IP-KVM (Keyboard, Video, and Mouse) device based on a RISC-V platform (LicheeRV Nano). It includes embedded firmware/applications (in kvmapp), a backend server (written in Go), and a front-end web interface (built with modern web frameworks and tooling).
• The device provides remote control capabilities (including virtual HID, video streaming using MJPEG/H264, and other management functions) and interacts with physical hardware via system-level scripts, kernel modules, and several support subsystems.
Analyzing the File Structure
• Top-level directories:
• kvmapp: Contains the firmware update packages, system applications, and system scripts (with subdirectories like “jpg_stream”, “kvm_new_app”, “kvm_system”, and “system” with init scripts and kernel modules). This part is focused on device-level operations and hardware interfacing.
• server: Implements the back-end services in Go. The structure here shows common utilities, configuration files, middleware (e.g., for JWT and TLS), API definitions (proto files), routing, and several service modules (for applications, authentication, network, video streaming, VM management, virtual devices, etc.).
• web: Provides the front-end interface, built with TypeScript, React (or a similar framework, as evidenced by .tsx files), and uses modern tooling like Vite, Tailwind CSS, and ESLint. It contains API integrations that mirror backend services.
• support: Contains auxiliary modules and support files (including additional driver components, system updates, image subsystem, and other functionalities for variants like NanoKVM-Lite/Full/PCIe). Also includes more classical C/C++ projects using CMake and Kconfig for kernel or hardware-specific functions.
Key Components and Their Interactions
• Hardware/Firmware Layer (kvmapp and support):
• kvmapp hosts the system-level applications and scripts (init scripts, kernel modules, and update routines) used to control and update the device.
• The support directory includes supplementary functions (e.g., image processing, kernel modules for vision, peripheral management) that support the device’s operational needs.
• Backend Server:
• The server layer written in Go encapsulates business logic, configuration management, data processing (such as video streaming protocols, virtual device control, authentication, and extension modules like Tailscale), and exposes various APIs (gRPC or REST) to the front-end.
• Front-End Web Interface:
• The web directory houses the modern interactive interface, which provides users control over authentication, device management, video and keyboard/mouse control settings, and other configuration options.
• Communication and Data Flow:
• The web UI communicates with the server via HTTP/WS (with clear API endpoints defined in the “api” subdirectory).
• The server interacts with the underlying hardware/firmware layer (through system scripts, direct calls to services, and possibly via hardware abstraction libraries) and may also interface with auxiliary support functions.
Architectural Patterns and Technologies
• The system follows a layered architecture:
• Frontend (UI/UX concerns) separate from Business Logic (backend server) and System/Hardware control (embedded firmware and support functions).
• The Go backend is organized with clear modular separation (configuration, routing, middleware, and service logic) which may follow aspects of MVC or microservices within a monolithic structure.
• The front-end uses modern web tooling with React/TypeScript, state management (as indicated by “jotai”), and REST/WS API interactions.
• The firmware component uses Linux init scripts, kernel modules, and native C/C++ modules (in the support directory) for low-level hardware control.