C4 Architecture
System Context (Level 1) and Container (Level 2) diagrams showing paiOS’s external relationships and internal structure.
This section covers the system architecture, design patterns, and architectural decisions for paiOS.
C4 Architecture
System Context (Level 1) and Container (Level 2) diagrams showing paiOS’s external relationships and internal structure.
Layer Architecture
Android-style layer view from Hardware to Apps, including technology stack and form factor evolution.
paiOS follows Clean Architecture principles, ensuring testability, maintainability, and clear separation of concerns.
The pai-engine follows Clean Architecture with distinct module responsibilities:
rpc/ - Interface Adapter (Ingress): Handles all gRPC/UDS communicationcore/ - Domain Layer: Contains SystemController and business logicorchestrator/ - Application Logic: Contains InferenceOrchestrator for resource schedulinghal/ - Infrastructure Layer: Hardware abstraction (Audio, HID, LED, NPU/GPU/CPU backends)rpc/ → core/ ← orchestrator/ → hal/The domain layer (core/) has no dependencies on other modules, ensuring pure business logic.
To maintain a strict separation between safe and unsafe code, we follow the Sys-Crate Pattern:
*-sys crates located in pai-engine/libs/.bindgen FFI bindings and unsafe code blocks.pai-engine/src/ remains pure Safe Rust, depending on sys-crates only via trait interfaces.pai-engine/├── libs/│ └── rknn-sys/ # Hardware bindings (AGPL-3.0)│ ├── Cargo.toml│ ├── build.rs # bindgen configuration│ └── src/lib.rs # Safe Rust wrapper└── src/ # Pure Safe Rust └── hal/ └── npu.rs # Uses rknn-sys via traitWe use gRPC (via tonic in Rust) over Unix Domain Sockets (UDS) for maximum performance and type safety.
All major architectural decisions are documented in Architecture Decision Records.