Flow-Based Programming for Go

Build programs as graphs of small components. FMesh runs them concurrently, with no goroutines, channels or locks to manage.

$ go get github.com/hovsep/fmesh

Quick start

Define components. Connect ports. Run.

main.go
// Error handling omitted for brevity
concat, _ := component.New("concat",
  component.WithInputs("i1", "i2"),
  component.WithOutputs("res"),
  component.WithActivationFunc(func(_ context.Context, this *component.Component) error {
    word1 := this.InputByName("i1").Signals().FirstPayloadOrDefault("")
    word2 := this.InputByName("i2").Signals().FirstPayloadOrDefault("")
    return this.OutputByName("res").PutSignals(signal.New(word1 + word2))
  }))

uppercase, _ := component.New("uppercase",
  component.WithInputs("i1"),
  component.WithOutputs("res"),
  component.WithActivationFunc(func(_ context.Context, this *component.Component) error {
    str := this.InputByName("i1").Signals().FirstPayloadOrDefault("")
    return this.OutputByName("res").PutSignals(signal.New(strings.ToUpper(str)))
  }))

// The mesh holds the components, a pipe connects them
fm, _ := fmesh.New("hello world")
fm.AddComponents(concat, uppercase)
concat.OutputByName("res").PipeTo(uppercase.InputByName("i1"))

// Seed the inputs, then run
concat.InputByName("i1").PutSignals(signal.New("hello "))
concat.InputByName("i2").PutSignals(signal.New("world!"))
fm.Run(context.Background())
mesh: hello world
"hello " "world!" i1 i2 concat res i1 uppercase res HELLO WORLD!

$ go run .
Result: HELLO WORLD!

Why FMesh

Model the flow. FMesh runs it.

Small components

Independent blocks with named ports. Easy to test on their own.

Concurrency for free

Every component that is ready runs at the same time.

Deterministic runs

Same input, same output. Runs you can reproduce and test.

Start building with FMesh