Skip to content

Backend Module

ION Flow Backend - Full-featured backend with WebSocket support, authentication, and multi-tenancy.


The Backend module (backend/) extends the Core engine with enterprise features:

  • Real-time Execution - WebSocket-based flow monitoring and control
  • Authentication - JWT and OAuth2 support
  • Multi-tenancy - Isolated data per company/tenant
  • Scheduled Execution - Cron-based flow scheduling
  • Version Control - Git-based flow versioning

backend/
├── backend.go # Entry point
├── ion/
│ ├── board/ # WebSocket execution engine
│ ├── controllers/ # REST API controllers
│ ├── services/ # Business logic
│ ├── models/ # Backend-specific models
│ ├── nodes/ # Platform-specific nodes
│ ├── params/ # DTOs for controllers
│ ├── helpers/ # Backend utilities
│ ├── middleware/ # HTTP middleware
│ ├── database/ # Database connections
│ ├── scheduler/ # Cron scheduling
│ └── workspace/ # Flow workspace management
└── routes/
├── api.go # REST API routes
└── channels.go # WebSocket routes

Real-time flow execution with WebSocket communication:

engine := board.NewExecutionEngine(sessionID, executor, context, messageSender)
engine.Start() // Begin execution
engine.Pause() // Pause execution
engine.Resume() // Resume execution
engine.Stop() // Stop execution

Learn more about Board

Two main route groups:

PrefixAuthDescription
/api/2.0/webcomponentWebComponent AuthPublic app endpoints
/api/1.0/tenants/{tenantId}JWT + Tenant AuthTenant-specific endpoints

Learn more about Routes

Two connection patterns:

// Global (Account level)
database.GetConnection().Model(&model).First(&result)
// Tenant (Company level)
company.CompanySchema(models.TableName()).First(&result)

Learn more about Database


func Up() {
// 1. Load environment
godotenv.Load()
// 2. Connect database
database.Connect()
// 3. Set SQLite path for flows
db.DB_PATH = "./storage/dbs"
// 4. Initialize scheduler
scheduleManager := scheduler.NewScheduleManager()
scheduler.StartTaskScheduler(cr, scheduleManager)
// 5. Setup routes
routes.ApiRouters(r)
routes.ChannelsRouters(r)
// 6. Setup WebSocket
board.SetupWebSocket()
board.SetupHub()
// 7. Load auth keys
middleware.LoadPublicKey("./storage/oauth-public.key")
// 8. Start server
http.ListenAndServe(port, handler)
}

Real-time debugging with WebSocket feedback:

  • Step-by-step execution
  • Progress messages for each node
  • Pause/Resume/Stop controls
  • Input waiting capabilities

Background execution without WebSocket:

  • Creates execution records
  • Handles app nodes
  • Persists execution state
  • No real-time feedback

Organized by route group:

GroupControllersPurpose
WebComponentConnection, Flow, IntegrationPublic app endpoints
TenantFlow, Connection, App, WebhookCompany endpoints
AccountFlow, Intent, WebhookAccount endpoints

Learn more about Controllers


Business logic services:

ServiceFilePurpose
CompanyFlowServicecompany_flow_service.goCompany flow CRUD
AccountFlowServiceaccount_flow_service.goAccount flow CRUD
CompanyWebhookServicecompany_webhook_service.goWebhook management
ScheduleServiceschedule_service.goCron scheduling
AttemptServiceattempt_service.goConnection attempts

Learn more about Services


LibraryPurpose
github.com/gorilla/muxHTTP routing
github.com/gorilla/websocketWebSocket support
github.com/golang-jwt/jwt/v5JWT authentication
github.com/robfig/cron/v3Cron scheduling
github.com/go-git/go-git/v6Git operations
gorm.io/gormDatabase ORM
gorm.io/driver/postgresPostgreSQL driver

VariableDescription
PORTServer port
DATABASE_URLPostgreSQL connection string
ENVIRONMENT”production” or “development”
JWT_PUBLIC_KEYPath to JWT public key