VibeTunnel Architecture Deep Dive
🏗️ High-Level Architecture
VibeTunnel is a sophisticated terminal multiplexer ecosystem with native macOS/iOS apps and a powerful web interface. Here’s the complete architectural breakdown:🎯 Core Components Breakdown
1. macOS Application (Swift/SwiftUI)
The native macOS app serves as the system orchestrator:- Process Management: Spawns and monitors the Bun/Node.js server
- Log Aggregation: Captures all logs from server and frontend
- System Integration: Menu bar UI, notifications, keychain
- Remote Access: Tailscale/Ngrok tunnel management
2. Web Server (Node.js/Bun)
The TypeScript server handles all terminal operations:- Session Management: Full PTY lifecycle (create/resize/kill)
- Binary Buffer Protocol: Optimized terminal streaming
- Authentication: JWT + SSH keys + PAM
- Distributed Mode: HQ server for multi-machine setups
3. iOS Application (Swift/SwiftUI)
Mobile terminal client with full feature parity:4. Web Frontend (TypeScript/LitElement)
Browser-based terminal interface:📡 Communication Protocols
1. Binary Buffer Protocol (0xBF Magic Byte)
Optimized terminal streaming protocol:2. REST API Endpoints
3. Unix Socket IPC
Mac app ↔ Server communication:🔄 Key Data Flows
Session Creation Flow
Log Aggregation Pipeline
🔐 Security Architecture
Authentication Layers
🚀 Advanced Features
1. Distributed Mode (HQ)
2. Remote Access (Tailscale/Ngrok)
3. Activity Monitoring
📁 File System Structure
🎨 Technology Stack
- macOS/iOS: Swift 6, SwiftUI, Combine, os.log
- Server: Node.js/Bun, TypeScript, Express, node-pty
- Frontend: TypeScript, LitElement, xterm.js, Web Components
- Protocols: WebSocket, Unix Sockets, REST, Binary Buffer
- Security: JWT, Ed25519 SSH keys, PAM, Keychain
- Build: Xcode, Swift Package Manager, pnpm, esbuild
🔧 Key Implementation Details
Server Lifecycle
- Startup: Mac app spawns Bun process with embedded server
- Health Check: Polls /health endpoint until ready
- Operation: Handles sessions, forwards logs to Mac app
- Shutdown: Graceful termination on SIGTERM
Session Persistence
- Sessions survive server restarts via control directory
- Reconnection supported through session ID
- Automatic cleanup of orphaned sessions
Performance Optimizations
- Binary Protocol: 10x smaller than JSON for terminal data
- Buffer Aggregation: Batches updates to reduce WebSocket messages
- Delta Updates: Only sends changes, not full buffer
- Lazy Loading: Sessions load on-demand
Development vs Production
- Development: Hot reload, verbose logging, dev server mode
- Production: Embedded server, optimized builds, minimal logging
- No Backwards Compatibility: Everything ships together as one unit