About
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
Quick Start
Prerequisites
Running Examples
# 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 graph
Project Structure
fmesh-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.
Contributing
We welcome new examples from any domain: simulations, data processing, protocols, algorithms, or real-world systems.
How to Contribute
-
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
Example Template
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
}
Guidelines
- One concept per example
- Well-commented code explaining the "why"
- Real-world scenarios preferred
- Self-contained and tested
Resources
License
MIT License - see LICENSE file for details.