This repository contains practical examples demonstrating F-Mesh - a Flow-Based Programming framework for Go. Each example shows how to model real-world systems as computational graphs with interconnected components.
What is F-Mesh?
F-Mesh is an FBP-inspired framework that lets you express your program as a mesh of components connected by pipes. Instead of writing imperative code, you describe how data flows through your system, making complex interactions more natural and maintainable. Learn more in the wiki.
Examples are grouped by what they teach, not by what they compute. Start at the top.
| Example | Description |
|---|---|
| String Processing | Two components and one pipe: the smallest useful mesh |
| Filter | Routing signals to different outputs by label |
| Pipeline | A multi-stage chain that reads stdin and files |
| Example | Description |
|---|---|
| Fibonacci | Cycles: a component's outputs piped back into its own inputs |
| Nesting | Composition: a component whose activation runs a whole inner mesh |
| Load Balancer | Indexed ports and component state: round-robin across N workers |
| Async Input | Driving a mesh from outside: signals injected on a ticker, results drained into a channel |
| State Machine | An FSM out of nothing but fmesh: states are components, transitions are pipes, the current state is a mesh label — the mesh graph is the state diagram |
| Example | Description |
|---|---|
| Electric Circuit | A supply/demand feedback loop with degrading state |
| Basic CAN Bus | One bus fanning every frame out to all connected ECUs |
| Advanced CAN Bus | Full CAN protocol with ISO-TP, arbitration and diagnostics |
| Life | A step simulation of human physiology inside a habitat |
These share simulation/sim — a small library for building simulations on an f-mesh (engines, simulated time, commands, scheduling, telemetry). It is a library, not an example.
| Example | Description |
|---|---|
| Graphviz | Exporting mesh topology to DOT/SVG, with activated components highlighted |
| Ray Tracer | Wavefront 3D ray tracer: parallel tile bands and a reflection cycle |
- Go 1.27 or later
- Git
# Clone and setup
git clone https://github.com/hovsep/fmesh-examples.git
cd fmesh-examples
go mod tidy
# Run any example, from the repo root...
go run ./patterns/fibonacci
go run ./simulation/electric_circuit
go run ./graphics/ray_tracer
# ...or from the example's own directory
cd patterns/fibonacci && go run .
# Build all examples
make build
# Generate visualization graphs
make graphfmesh-examples/
├── basics/ # everyday meshes
├── patterns/ # how a mesh is wired and driven
│ └── fibonacci/
│ ├── main.go # example code
│ ├── *-graph.dot # graphviz source (generated)
│ └── *-graph.svg # visual diagram (generated)
├── simulation/ # systems evolving over time
│ ├── sim/ # shared simulation library — not an example
│ ├── electric_circuit/
│ ├── can_bus/
│ │ ├── basic/main.go
│ │ └── advanced/
│ │ ├── main.go
│ │ └── can/ # reusable CAN components
│ └── life/
├── graphics/ # pixels
└── internal/ # FMESH_GRAPH helper, shared by every example
Each example is a standalone Go program, runnable either from the repo root (go run ./patterns/fibonacci) or from its own directory (cd patterns/fibonacci && go run .). Visualization files (*-graph.dot and *-graph.svg) are generated using make graph, and land in the example's own directory.
We welcome new examples from any domain: simulations, data processing, protocols, algorithms, or real-world systems.
-
Fork this repository
-
Create a new directory under the category that fits what your example teaches (
basics,patterns,simulationorgraphics— add a new category if none fit):mkdir patterns/my_example cd patterns/my_example -
Write your example in
main.go:- Follow existing patterns
- Add comments explaining the scenario and concepts
- Keep it focused on one concept
-
Generate visualization (optional):
FMESH_GRAPH=1 go run . -
Test your example:
go run . -
Update README.md:
- Add your example to its category's table with a brief description
-
Submit a pull request
package main
import (
"fmt"
"github.com/hovsep/fmesh"
"github.com/hovsep/fmesh/component"
"github.com/hovsep/fmesh/signal"
)
// Description of what this example demonstrates.
// Run: go run .
func main() {
fm := fmesh.New("example").
AddComponents(
component.New("processor").
AddInputs("in").
AddOutputs("out").
WithActivationFunc(func(c *component.Component) error {
// Your logic here
return nil
}),
)
// Connect, initialize, run, and display results
}- One concept per example
- Well-commented code explaining the "why"
- Real-world scenarios preferred
- Self-contained and tested
- F-Mesh Repository - Main framework
- F-Mesh Wiki - Complete documentation
- F-Mesh Graphviz - Visualization tool
- Flow-Based Programming - Learn about FBP (by J. Paul Morrison)
MIT License - see LICENSE file for details.