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.
| Example | Description |
|---|---|
| Async Input | Handling asynchronous data sources |
| Electric Circuit | Simulating electrical components |
| Fibonacci | Recursive computation with cyclic pipes |
| Filter | Data filtering and routing |
| Graphviz | Visualizing mesh topology |
| Load Balancer | Distributing work across components |
| Nesting | Composing meshes within meshes |
| Pipeline | Sequential data processing |
| String Processing | Text transformation pipeline |
| Basic CAN Bus | Simple automotive network simulation |
| Advanced CAN Bus | Full CAN protocol with ISO-TP |
- Go 1.24 or later
- Git
# Clone and setup
git clone https://github.com/hovsep/fmesh-examples.git
cd fmesh-examples
go mod tidy
# Run any example
go run ./fibonacci
go run ./electric_circuit
# Build all examples
make build
# Generate visualization graphs
make graphfmesh-examples/
├── fibonacci/
│ ├── main.go # Example code
│ ├── graph.dot # Graphviz source (generated)
│ └── graph.svg # Visual diagram (generated)
├── electric_circuit/
│ └── main.go
└── can_bus/
├── basic/main.go
└── advanced/
├── main.go
└── can/ # Reusable CAN components
Each example is a standalone Go program. Visualization files (graph.dot and graph.svg) are generated using make graph.
We welcome new examples from any domain: simulations, data processing, protocols, algorithms, or real-world systems.
-
Fork this repository
-
Create a new directory for your example:
mkdir my_example cd 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):
cd my_example go run . --graph
-
Test your example:
go run . -
Update README.md:
- Add your example to the Examples 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.