Skip to main content

Domain Models & Events

Domain Models

Flow (engine/domain/flow.go)

The core workflow execution structure:

type Flow struct {
Name string // Workflow name
ConfigName string // Configuration reference
States []*FlowState // Available states
Transitions []*FlowTransition // State transitions
CurrentState *FlowState // Active state
CurrentTransition *FlowTransition // Active transition
Resolvers []string // Module resolvers
Options map[string]interface{} // Flow-level options
Parent *Flow // Parent flow (nested workflows)
Properties *FlowOptions // Computed properties
Trace []interfaces.TraceInterface // Execution trace
LastTrace interfaces.TraceInterface // Last trace entry
}

FlowState

type FlowState struct {
State string // State name/action path
ContinueOnFail bool // Continue on failure flag
Type string // "initial", "normal", "final"
Parent *FlowState // Parent state reference
Params []string // Parameter names
Response string // Response variable name
Node *wsl.Node // WSL node reference
Options map[string]interface{} // State options
}

FlowTransition

type FlowTransition struct {
If *string // Condition expression
Else *string // Else target
SkipTo *bool // Skip execution flag
From []string // Source states
To string // Target state
Error string // Error state
True string // Success target
False string // Failure target
Type string // Transition type
ContinueOnFail bool // Continue on failure
Parent *FlowTransition // Parent transition
Params map[string]interface{} // Parameters
Response string // Response variable
Node *wsl.Node // WSL node reference
Options map[string]interface{} // Transition options
}

FlowStepResult

The standard return type for transition methods:

type FlowStepResult struct {
Success bool // Execution success
Next string // Override next state
Error error // Error if any
Response interface{} // Response data
StatusCode int // HTTP status code
}

Configuration (engine/domain/config.go)

type Config struct {
FilePath string // Config file location
Application ApplicationConfig // App settings
WorkflowConfig []WorkflowConfigItem // Workflow definitions
Items IniConfig // Additional items
}

type WorkflowConfigItem struct {
Name string // Workflow name
Path string // Workflow file path
Amount int // Concurrency level
Retry int // Retry count
RetryDelay int // Delay between retries
RestartPolicy string // Restart policy
Options map[string]interface{} // Additional options
}

Event System

The event bus enables loose coupling between components.

Publishing Events

event.Bus.Publish("topic:event", data)

Subscribing to Events

event.Bus.Subscribe("topic:event", func(data interface{}) {
// Handle event
})

Event System Deep Dive

The event system (event/bus.go) provides workflow lifecycle events.

Event Bus

var Bus EventBus.Bus

func init() {
Bus = EventBus.New()
}

Lifecycle Events

EventTriggerPayload
on:workflow:before:runBefore workflow starts(wfConfig, contexts)
on:workflow:run:batchBefore batch execution(wfConfig, contexts)
on:workflow:completeAfter workflow completes(wfConfig, contexts)
on:workflow:exitWhen workflow exits(wfConfig)

Subscribing to Events

event.Bus.Subscribe("on:workflow:complete", func(wfConfig domain.WorkflowConfigItem, contexts []map[string]interface{}) {
log.Printf("Workflow %s completed", wfConfig.Name)
})

Publishing Custom Events

event.Bus.Publish("custom:event", data1, data2)

Configuration Management

Configuration Files

runtime/
└── etc/
├── development/
│ └── engine.ini
└── production/
└── engine.ini

Configuration Structure

type Config struct {
FilePath string
Application ApplicationConfig
WorkflowConfig []WorkflowConfigItem
Items IniConfig
}

type ApplicationConfig struct {
Name string
Env string
Debug bool
Timezone string
Locale string
Version string
BuildTime string
LogFile string
ModulesPath string
WorkflowsPath string
Items IniConfig
}

Environment Variables

Configuration is loaded from .env file:

  • NAME: Application name
  • APP_ENV: Environment (development/production)
  • CONFIG_PATH: Path to configuration directory