Go Engine (main.go) — Bootstrap Sequence & Lifecycle

📘 General go v2 Updated

Deep dive into main.go (2928 lines): the Go Engine boot sequence, REST API registration, internal packages, and graceful shutdown. Covers initEngineDir, license check, port management, and all 40+ API endpoints.

The Go Engine

The Go Engine is the backbone of Flowork OS. It is a single compiled binary (flowork-engine.exe) that provides all backend services through a REST API on Port 5000.

Boot Sequence

When the engine starts, it executes the following steps in order:

1. initEngineDir() — Determines the absolute path of the engine binary and locks all file operations to that directory 2. initLicense() — Reads FloworkData/license.json and verifies the subscription token against floworkos.com/api/v1/license 3. lockWorkingDirectory() — Calls os.Chdir() to set CWD to the exe location 4. killPreviousInstances() — Scans running processes and kills any duplicate engine, gui.exe, or flowork-named processes 5. forceKillPort5000() — Ensures Port 5000 is free by killing any process listening on it 6. checkUpdate() — Fetches floworkos.com/update-engine.txt and compares version. Forces update if outdated 7. fiber.New() — Creates the GoFiber HTTP server with 500MB body limit 8. Register Routes — Registers 40+ REST endpoints for file operations, AI builder, workflows, etc. 9. app.Listen(":5000") — Starts serving

Key API Categories

  • File Operations: /api/ai-write, /api/ai-read/:type/:id, /api/ai-search, /api/ai-rename
  • Terminal: /api/ai-exec, /api/terminal/start, /api/terminal/status/:id
  • Apps & Nodes: /api/local-apps, /api/local-nodes, /api/upload, /api/compile
  • Workflows: /api/workflow/save, /api/workflow/execute/:id, /api/workflow/list
  • Knowledge Bank: /api/knowledge (POST/GET/DELETE)
  • Git: /api/git (init/status/diff/add/commit/revert)
  • Diagnostics: /api/engine-logs, /api/crash-history, /api/progress-log

Version History

Version Date Changes
v2 2026-04-01 Initial KB generation — comprehensive Flowork documentation