┌─────────────────────────────────────────────────────────────────────────┐
│ RR-UI v2.0 ARCHITECTURE │
└─────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────────┐
│ FRONTEND (Dioxus 0.7.2 + Wasm) │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Dashboard │ │ Inbounds │ │ Settings │ │
│ │ Page │ │ Page │ │ Page │ │
│ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │
│ │ │ │ │
│ └──────────────────┴──────────────────┘ │
│ │ │
│ ┌────────▼────────┐ │
│ │ Dioxus Signals │ │
│ ├─────────────────┤ │
│ │ • GlobalState │ ← Real-time reactivity │
│ │ • ToastStore │ ← Zero-DOM-thrash updates │
│ │ • ThemeState │ ← Dark/Light mode │
│ └────────┬────────┘ │
│ │ │
│ ┌────────▼────────┐ │
│ │ Server Fns │ │
│ │ (RPC Layer) │ │
│ └────────┬────────┘ │
└────────────────────────────┼────────────────────────────────────────────┘
│
│ HTTP/CBOR (server_fn)
│
┌────────────────────────────▼────────────────────────────────────────────┐
│ BACKEND (Rust + Actix-Web) │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ API Endpoints (prefixed with /panel/api) │ │
│ ├─────────────────────────────────────────────────────────────────┤ │
│ │ /login → auth::login() │ │
│ │ /sub → sub::get_subscription() │ │
│ │ │ │
│ │ /server/status → system::get_status() │ │
│ │ /server/mode → system::get_mode() │ │
│ │ /server/xray/* → xray_control::{status, restart, ...} │ │
│ │ │ │
│ │ /setting → setting::{get,update}_all_settings() │ │
│ │ /client/traffic → client::{get,reset}_traffic() │ │
│ │ │ │
│ │ /inbounds/* → inbound::{list, add, update, del} │ │
│ │ /warp/* → warp::{status, register} │ │
│ │ /cert/issue → cert::issue_cert() │ │
│ │ /backup/* → backup::{export, import}_db() │ │
│ │ /routing/* → routing::{list, add, del}_rule() │ │
│ │ /tgbot/* → tgbot::{get, update, test}_config() │ │
│ └─────────────────────────┬───────────────────────────────────────┘ │
│ │ │
│ ┌─────────────────────────▼───────────────────────────────────────┐ │
│ │ Application State │ │
│ ├─────────────────────────────────────────────────────────────────┤ │
│ │ • DbClient (SurrealDB) │ │
│ │ • XrayClient (gRPC) │ │
│ │ • SystemState (sysinfo) │ │
│ │ • SharedXrayProcess │ │
│ │ • AtomicConfigWriter (APL) ← NEW: Crash-safe writes │ │
│ └─────────┬───────────────────────┬───────────────────────────────┘ │
│ │ │ │
│ ┌─────────▼─────────┐ ┌────────▼────────┐ │
│ │ Services │ │ Background │ │
│ ├───────────────────┤ │ Jobs │ │
│ │ • auth.rs │ ├─────────────────┤ │
│ │ - hash_password │ │ • traffic.rs │ │
│ │ - verify_jwt │ │ - 30s interval│ │
│ │ - create_jwt │ │ - Batch update│ │
│ │ • audit.rs │ │ • log_watcher.rs│ │
│ └───────────────────┘ └─────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────┘
│ │
│ │
┌────────────────────┴────────┐ ┌────────▼────────┐
│ │ │ │
┌───────▼────────┐ ┌─────────▼──▼──────┐ ┌─────▼──────┐
│ SurrealDB │ │ Xray/RustRay │ │ System │
│ (RocksDB) │ │ Core Process │ │ (sysinfo) │
├────────────────┤ ├───────────────────┤ ├────────────┤
│ • Settings │ │ • gRPC API │ │ • CPU │
│ • Inbounds │ │ (port 10085) │ │ • Memory │
│ • Traffic │ │ • Config.json │ │ • Disk │
│ • Users │ │ (Atomic Write) │ │ • Uptime │
└────────────────┘ └───────────────────┘ └────────────┘
┌─────────────────────────────────────────────────────────────────────────┐
│ DATA FLOW EXAMPLE │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ User Opens Dashboard │
│ │ │
│ ▼ │
│ Dioxus Component Mounts │
│ │ │
│ ▼ │
│ use_resource(get_server_status) ← Server Function │
│ │ │
│ ▼ │
│ POST /panel/api/get_server_status (CBOR) │
│ │ │
│ ▼ │
│ get_status(SystemState) │
│ │ │
│ ├─► sys.refresh_all() │
│ ├─► sys.global_cpu_info() │
│ ├─► sys.total_memory() │
│ ├─► sys.disks() │
│ └─► sys.uptime() │
│ │ │
│ ▼ │
│ CBOR Response │
│ { │
│ cpu: 12.5, │
│ mem: { current: 512000000, total: 1073741824 }, │
│ disk: { current: 10737418240, total: 107374182400 }, │
│ uptime: 123456, │
│ loads: [0.5, 0.3, 0.1] │
│ } │
│ │ │
│ ▼ │
│ Dioxus Signal Update (Zero re-renders) │
│ │ │
│ ▼ │
│ Dashboard UI Updates │
│ • Progress rings animate │
│ • Numbers transition smoothly │
│ • Status badges update │
│ • Glassmorphism cards shimmer │
│ │
└─────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────────┐
│ ATOMIC PERSISTENCE LAYER (APL) │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ Config Update Request │
│ │ │
│ ▼ │
│ XrayConfigBuilder::build(db) │
│ │ │
│ ▼ │
│ AtomicConfigWriter::write_json(path, config) │
│ │ │
│ ├─► 1. Create temp file (.config.json.tmp.12345) │
│ ├─► 2. Write JSON content │
│ ├─► 3. fsync() to disk │
│ ├─► 4. Create backup (.config.json.bak) │
│ ├─► 5. Atomic rename (temp → config.json) │
│ └─► 6. Log transaction │
│ │ │
│ ▼ │
│ Config safely persisted (survives power loss) │
│ │
└─────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────────┐
│ TESTING ARCHITECTURE │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ Unit Tests (tests/auth_tests.rs) │
│ ├─ test_password_hashing() │
│ ├─ test_password_verification_success() │
│ ├─ test_password_verification_failure() │
│ ├─ test_jwt_generation_and_verification() │
│ ├─ test_jwt_verification_with_invalid_token() │
│ ├─ test_jwt_expiration() │
│ └─ test_multiple_password_hashes_are_different() │
│ │
│ Integration Tests (tests/system_api_tests.rs) │
│ ├─ test_system_status_endpoint() │
│ ├─ test_system_mode_endpoint() │
│ ├─ test_system_state_creation() │
│ └─ test_system_cpu_usage_range() │
│ │
│ Benchmarks (benches/) │
│ ├─ apl_benchmark.rs ← NEW: Atomic write performance │
│ ├─ grpc_benchmark.rs │
│ ├─ serialization_bench.rs │
│ ├─ ws_throughput.rs │
│ ├─ allocation_bench.rs │
│ ├─ orchestrator_latency.rs │
│ ├─ routing_engine_latency.rs │
│ ├─ binary_footprint.rs │
│ └─ ui_state_sync.rs │
│ │
└─────────────────────────────────────────────────────────────────────────┘
- Framework: Dioxus 0.7.2 (Rust → Wasm)
- State Management: Dioxus Signals (reactive, zero-copy)
- Styling: Tailwind CSS + Custom CSS (Obsidian/Slate palette)
- Effects: Glassmorphism, backdrop-filter, micro-animations
- RPC: server_fn (CBOR serialization)
- Web Server: Actix-Web 4.9 (Rust async runtime)
- Database: SurrealDB 2.0 (Embedded RocksDB)
- Persistence: Atomic writes with fsync() (APL)
- Process Management: Tokio async + SharedXrayProcess
- gRPC Client: Tonic 0.12 (Xray/RustRay communication)
- Authentication: Argon2 + JWT + TOTP (2FA)
- Binary Size: <8MB (optimized with LTO, strip, panic=abort)
- Deployment: Single binary with embedded Wasm
- Service: systemd integration with graceful shutdown
- Logging: tracing + syslog
# Development
cargo run --features server # Start backend + serve Wasm
dx serve --features web --hot-reload # Dioxus dev server (hot reload)
# Testing
cargo test --features server # Run all tests
cargo bench --features server # Run benchmarks
# Production Build
cargo build --release --features server # Optimized binary (<8MB)
strip target/release/rr-ui-cli # Further reduce size
# Deployment
sudo ./install.sh # Install + systemd service
sudo systemctl status rr-ui # Check statusrr-ui/
├── src/
│ ├── adapters/ # Infrastructure adapters
│ │ ├── atomic_config.rs # APL: Crash-safe writes
│ │ ├── cert_manager.rs # ACME certificate management
│ │ └── uds_manager.rs # Unix domain sockets
│ ├── api/ # HTTP endpoints
│ ├── domain/ # Shared domain models
│ │ └── models.rs # Protocol-specific types
│ ├── services/ # Business logic
│ ├── jobs/ # Background tasks
│ ├── repositories/ # Data access layer
│ ├── ui/ # Dioxus frontend
│ │ ├── app.rs # Router + layout
│ │ ├── components/ # Reusable UI components
│ │ ├── pages/ # Page components
│ │ ├── server_fns.rs # RPC functions
│ │ ├── state.rs # Global state
│ │ └── assets/
│ │ └── layout.css # Dark theme + glassmorphism
│ ├── db.rs # SurrealDB client
│ ├── xray_client.rs # gRPC client
│ ├── xray_config.rs # Config generation
│ ├── xray_process.rs # Process lifecycle
│ └── lib.rs # Module exports
├── benches/ # Performance benchmarks
├── tests/ # Integration tests
├── proto/ # gRPC protobuf definitions
└── Cargo.toml # Dependencies + features
- No JS runtime: Pure Rust compiled to Wasm
- Type safety: Compile-time guarantees
- Performance: Zero-cost abstractions, no virtual DOM overhead
- Bundle size: ~200KB Wasm vs 1MB+ React
- Crash safety: fsync() ensures data on disk before rename
- Rollback: Transaction log for multi-file operations
- Backup: Automatic .bak files
- Performance: ~5-10ms overhead acceptable for reliability
- Eye strain reduction: Deep slate backgrounds (#0F172A)
- Premium aesthetic: Glassmorphism + micro-animations
- Accessibility: High contrast text (95% opacity)
- Brand identity: Cyan accents (#06B6D4) for modern feel
- Type safety: Discriminated unions prevent invalid configs
- Validation: Compile-time + runtime checks
- Extensibility: Easy to add new protocols
| Feature | rr-ui v2.0 | Remnawave | 3x-ui | Hiddify |
|---|---|---|---|---|
| Runtime | Pure Rust/Wasm | React (JS) | Go templates | Python/JS |
| Config Safety | Atomic writes + fsync | Standard writes | Standard writes | Standard writes |
| Type Safety | Discriminated unions | TypeScript (partial) | Go structs | Python dicts |
| UI Framework | Dioxus Signals | React hooks | jQuery | Vue |
| Binary Size | <8MB | N/A (web only) | ~15MB | ~50MB |
| Dark Mode | Glassmorphism | Basic | Basic | Basic |
| Network Mgmt | Native netlink (planned) | Shell scripts | Shell scripts | Shell scripts |
- Cold start: <100ms
- Hot reload: <50ms (Dioxus dev mode)
- Config write: 5-10ms (atomic) vs 1-2ms (standard)
- UI reactivity: <16ms (60 FPS)
- Memory usage: ~50MB (idle)
- Binary size: 6.5MB (release build)
- Authentication: Argon2 password hashing
- Authorization: JWT with expiration
- 2FA: TOTP support
- TLS: Automatic ACME certificates
- Secrets: SecretString for sensitive data
- Audit: Transaction logging
See task.md for detailed Phase 2-9 plans.