Skip to content

mandocaesar/workflow-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Workflow Engine

A generic, extensible workflow engine in Go, supporting state machines, pluggable actions (API calls, message broker, functions, callbacks), and a simple API server with dashboard visualization.

Features

  • Register workflows and actions dynamically via HTTP API
  • Group workflows by domain
  • Visualize workflows and transitions in a web dashboard (Mermaid.js)
  • Easily extend with new action types

Getting Started

1. Run the API Server

cd cmd
go run api_server.go

The server will start on http://localhost:8080.

2. Register a Workflow

curl -X POST http://localhost:8080/register-workflow \
  -H "Content-Type: application/json" \
  -d '{"domain":"ticket","name":"ticket_flow","initial_state":"open"}'

3. Register an Action

Register a Predefined Function Action

curl -X POST http://localhost:8080/register-action \
  -H "Content-Type: application/json" \
  -d '{"domain":"ticket","workflow":"ticket_flow","state":"open","event":"start_progress","action_type":"function","function_name":"example"}'

Register a Dynamic JavaScript Script Action

curl -X POST http://localhost:8080/register-action \
  -H "Content-Type: application/json" \
  -d '{"domain":"ticket","workflow":"ticket_flow","state":"open","event":"start_progress","action_type":"script","script":"result = ticket_id + \\" started by \\\" + user;"}'

You can use any parameter passed to the action (e.g., ticket_id, user) in your script. The last evaluated value (e.g., result) will be returned as the action result.

4. Visualize the Workflow

Open your browser and go to:

http://localhost:8080/dashboard

Enter the domain and workflow name, then click Visualize to see the state diagram.


Project Structure

  • cmd/api_server.go — API server entry point
  • internal/api/ — API handlers, dashboard, visualization
  • internal/domain/ — State machine, types, models
  • internal/usecase/ — Workflow orchestration
  • internal/actions/ — Pluggable action implementations

Extending

  • Add new action types in internal/actions/
  • Register new actions via the API
  • To add new Go functions for use in function actions, add them to the FunctionRegistry in internal/actions/function_action.go.

Dynamic Scripting

  • You can register JavaScript code as a workflow action using the script action type. The script will be executed in a sandboxed JS interpreter (otto) with all action parameters available as variables.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors