Skip to content

Latest commit

 

History

228 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

F-Mesh Examples

Real-world examples of Flow-Based Programming with F-Mesh

F-Mesh Go Version Go Report Card License: MIT

GitHub stars GitHub issues GitHub last commit GitHub contributors


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

Examples are grouped by what they teach, not by what they compute. Start at the top.

basics/ — everyday meshes

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

patterns/ — how a mesh is wired and driven

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

simulation/ — systems evolving over time

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.

graphics/ — pixels

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

Quick Start

Prerequisites

  • Go 1.27 or later
  • Git

Running Examples

# 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 graph

Project Structure

fmesh-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.


Contributing

We welcome new examples from any domain: simulations, data processing, protocols, algorithms, or real-world systems.

How to Contribute

  1. Fork this repository

  2. Create a new directory under the category that fits what your example teaches (basics, patterns, simulation or graphics — add a new category if none fit):

    mkdir patterns/my_example
    cd patterns/my_example
  3. Write your example in main.go:

    • Follow existing patterns
    • Add comments explaining the scenario and concepts
    • Keep it focused on one concept
  4. Generate visualization (optional):

    FMESH_GRAPH=1 go run .
  5. Test your example:

    go run .
  6. Update README.md:

    • Add your example to its category's table with a brief description
  7. 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.


Built with F-Mesh v1.13.0

Questions? Open an issue or check the wiki

About

Examples of fmesh library usage

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages