LocalDNS.wtf
Advanced

Rust Integration

Architecture and plan for integrating Rust modules for high-performance low-level operations.

Rust Integration

LocalDNS uses a hybrid architecture: TypeScript for high-level orchestration, Rust for low-level operations. This provides optimal performance and memory safety for critical paths.

Architecture

┌─────────────────────────────────────┐
│   TypeScript (High-Level API)       │
│   - CLI Commands                    │
│   - Business Logic                  │
│   - Orchestration                   │
└──────────────┬──────────────────────┘
               │ FFI/N-API

┌─────────────────────────────────────┐
│   Rust (Low-Level Operations)       │
│   - File I/O (hosts, registry)      │
│   - Process Management              │
│   - Network Operations              │
│   - System Calls                    │
└─────────────────────────────────────┘

Rust Modules

localdns-hosts (Priority 1)

Hosts file operations with native file I/O, atomic operations, and zero-copy parsing.

Performance target: 5-20x improvement (from 50-200ms to <10ms per operation).

localdns-process (Priority 1)

Process management with native spawning, PID management, and efficient monitoring.

localdns-network (Priority 1)

Port operations with native socket operations and fast port scanning.

Performance target: 10-100x improvement (from 100-1000ms to <10ms per port).

localdns-registry (Priority 2)

Registry file operations with faster JSON via serde, native file locking, and atomic writes.

localdns-watcher (Priority 2)

File system watching with native inotify/kqueue/FSEvents and lower memory footprint.

Technical Stack

  • napi-rs - Node.js FFI bindings
  • tokio - Async runtime
  • serde - JSON serialization
  • notify - File system watching
  • sysinfo - Process/system information

Building

# Build all Rust crates
cargo build --release

# Build FFI bindings
cd packages/rust-ffi
pnpm build

See the Rust Setup Guide for detailed instructions.