Skip to main content

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:
Key Responsibilities:
  • 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:
Key Features:
  • 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:
Flow:

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

  1. Startup: Mac app spawns Bun process with embedded server
  2. Health Check: Polls /health endpoint until ready
  3. Operation: Handles sessions, forwards logs to Mac app
  4. 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