Engine ↔ Website Communication — P2P Bridge & REST API

📘 General javascript v1

How the Flowork Engine (Go, Port 5000) and Website (Vue SPA in Electron) communicate. Covers REST API calls, WebSocket bridge (Port 5001), preload.js bridge, systemBridge.js, and the nativeBridge utility.

How Engine and Website Talk

Flowork OS has a unique architecture where the website (Vue SPA) runs inside Electron and communicates with a local Go engine. This creates three distinct communication channels.

Channel 1: REST API (Port 5000)

The primary communication channel. The Vue SPA makes HTTP requests to http://localhost:5000/api/* for all backend operations:

  • File I/O: Read, write, search, rename files in apps/ and nodes/
  • Terminal: Execute commands, start background processes
  • App Management: List installed apps, upload .flow packages
  • Workflows: Create, execute, and manage visual workflows
  • Knowledge Bank: Store and retrieve AI memory

Channel 2: WebSocket (Port 5001)

Used exclusively by the AI assistant for real-time browser automation:

  • open_ai_tab — Create a new browser window with a URL
  • capture_browser — Take a screenshot of any tab
  • execute_browser_script — Inject and run JavaScript
  • get_console_logs — Read console output
  • scrape_page — Extract page content

Channel 3: Preload Bridge

Electron's preload.js exposes the window.floworkDesktop API to the Vue SPA. This provides:

  • Native OS access (file dialogs, shell commands)
  • App tab management (open, close, switch tabs)
  • Browser automation from the UI
  • System tray and log viewer control

Detection Pattern

// Always check before using native features
if (window.floworkDesktop) {
    // Running inside Electron — full native access
    await window.floworkDesktop.openAppTab(id, name, url);
} else {
    // Running in standard browser — limited to web APIs
    window.open(url, "_blank");
}