petri-pilot

module
v0.22.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2026 License: MIT

README

Petri Pilot

Compile Petri net models into running applications.

A Petri net model defines places (states), transitions (actions), and arcs (connections). Petri-pilot compiles that model into a complete, deployable application. The generation is deterministic — the same model always produces the same code.

Model ──> Context ──> Templates ──> Running Application

The model is the source of truth. Code is a derived artifact.

Live demos: pilot.pflow.xyz | Book: book.pflow.xyz

What It Generates

From a single model file, petri-pilot produces:

  • Go backend — event-sourced aggregate, REST API, SQLite storage
  • ES modules frontend — admin dashboard, simulation, event history
  • GraphQL API — unified query layer with built-in playground
  • pflow viewer — interactive Petri net visualization

No LLM-generated code. The LLM designs models. Templates compile apps.

Install

# From source
go install github.com/pflow-xyz/petri-pilot/cmd/petri-pilot@latest

# Or via Docker
docker run ghcr.io/pflow-xyz/petri-pilot version

# Or download a binary from GitHub Releases
# https://github.com/pflow-xyz/petri-pilot/releases

Quick Start

# Run the demo server
petri-pilot serve tic-tac-toe coffeeshop knapsack

# Or start the MCP server
petri-pilot mcp

MCP Server

Petri-pilot runs as an MCP server. An LLM can design, validate, simulate, and generate without leaving the conversation.

Connect to the hosted server (no install)

The server is hosted at https://pilot.pflow.xyz/mcp over Streamable HTTP. In Claude Code:

claude mcp add --transport http petri-pilot https://pilot.pflow.xyz/mcp
Run locally
petri-pilot mcp
Tool Purpose
petri_validate Structural correctness, conservation laws
petri_analyze Reachability, deadlocks, liveness, P/T-invariants
petri_verify Check stated properties — proved/refuted/unknown + counterexample
petri_conformance Replay a real event log against the model (fitness/precision)
petri_simulate Fire transitions, trace state
petri_code_to_flow Convert source code into a Petri net model
petri_codegen Generate Go backend
petri_frontend Generate ES modules frontend
petri_application Full-stack from high-level spec
petri_extend Modify existing models
service_start/stop/logs Manage running services
Claude Desktop / Cursor

For clients that take JSON config, point at the hosted HTTP server:

{
  "mcpServers": {
    "petri-pilot": {
      "type": "http",
      "url": "https://pilot.pflow.xyz/mcp"
    }
  }
}

Or run the server locally:

{
  "mcpServers": {
    "petri-pilot": {
      "command": "petri-pilot",
      "args": ["mcp"]
    }
  }
}

Or with Docker:

{
  "mcpServers": {
    "petri-pilot": {
      "command": "docker",
      "args": ["run", "-i", "--rm", "ghcr.io/pflow-xyz/petri-pilot", "mcp"]
    }
  }
}

Model Format

{
  "name": "order",
  "places": [
    {"id": "pending", "initial": 1},
    {"id": "shipped"}
  ],
  "transitions": [
    {"id": "ship", "event": "order_shipped"}
  ],
  "arcs": [
    {"from": "pending", "to": "ship"},
    {"from": "ship", "to": "shipped"}
  ]
}

Models can include roles, access rules, typed events, views, and navigation. See services/ for examples.

Ecosystem

Petri-pilot is part of the pflow toolchain. All three tools share the same JSON-LD model format.

Tool Role
pflow.xyz Visual editor — design and simulate nets in the browser
go-pflow Core library — ODE simulation, reachability analysis, P-invariants
petri-pilot Code generator — compiles models into running applications

A net designed in the editor can be analyzed by the library and compiled by petri-pilot without format conversion.

Project Structure

cmd/petri-pilot/     CLI and MCP server entry point
pkg/mcp/             MCP server and tools
pkg/codegen/         Go and ES modules templates
pkg/serve/           Multi-model HTTP server
pkg/validator/       Model analysis
services/            Example models (tic-tac-toe, coffeeshop, knapsack, texas-holdem)
frontends/           Custom frontends for demos
examples/           Output from codegen (derived, not source)

License

MIT

Directories

Path Synopsis
cmd
petri-pilot command
Command petri-pilot provides LLM-augmented Petri net model design and validation.
Command petri-pilot provides LLM-augmented Petri net model design and validation.
zk-field-parity command
Command zk-field-parity emits a deterministic digest of BN254 field arithmetic and gnark circuit artifacts.
Command zk-field-parity emits a deterministic digest of BN254 field arithmetic and gnark circuit artifacts.
zk-tictactoe command
zk-verifier-provenance command
Command zk-verifier-provenance binds each deployed Groth16 verifier to the circuit it was generated from, and surfaces when the circuit source has drifted away from what's actually on-chain (F4 Tier 3).
Command zk-verifier-provenance binds each deployed Groth16 verifier to the circuit it was generated from, and surfaces when the circuit source has drifted away from what's actually on-chain (F4 Tier 3).
Package examples provides auto-registration for the example services.
Package examples provides auto-registration for the example services.
coffeeshop
Code generated by petri-pilot.
Code generated by petri-pilot.
diningphilosophers
Code generated by petri-pilot.
Code generated by petri-pilot.
enzymekinetics
Code generated by petri-pilot.
Code generated by petri-pilot.
galtonboard
Code generated by petri-pilot.
Code generated by petri-pilot.
hiringpipeline
Code generated by petri-pilot.
Code generated by petri-pilot.
knapsack
Code generated by petri-pilot.
Code generated by petri-pilot.
loanapproval
Code generated by petri-pilot.
Code generated by petri-pilot.
predatorprey
Code generated by petri-pilot.
Code generated by petri-pilot.
producerconsumer
Code generated by petri-pilot.
Code generated by petri-pilot.
shop
Package shop is the composition root of the shop application: every data object is its own Petri net (see the entity subpackages), joined by the links recorded in the flattened model this package embeds.
Package shop is the composition root of the shop application: every data object is its own Petri net (see the entity subpackages), joined by the links recorded in the flattened model this package embeds.
shop/inventory
Code generated by petri-pilot.
Code generated by petri-pilot.
shop/order
Code generated by petri-pilot.
Code generated by petri-pilot.
stoplight
Code generated by petri-pilot.
Code generated by petri-pilot.
tcphandshake
Code generated by petri-pilot.
Code generated by petri-pilot.
texasholdem
Code generated by petri-pilot.
Code generated by petri-pilot.
thermostat
Code generated by petri-pilot.
Code generated by petri-pilot.
tictactoe
Code generated by petri-pilot.
Code generated by petri-pilot.
vetclinic
Code generated by petri-pilot.
Code generated by petri-pilot.
Package generated registers the apps produced by the current generator.
Package generated registers the apps produced by the current generator.
beancounter
Code generated by petri-pilot.
Code generated by petri-pilot.
cafe
Package cafe is the composition root of the cafe application: every data object is its own Petri net (see the entity subpackages), joined by the links recorded in the flattened model this package embeds.
Package cafe is the composition root of the cafe application: every data object is its own Petri net (see the entity subpackages), joined by the links recorded in the flattened model this package embeds.
cafe/counter
Code generated by petri-pilot.
Code generated by petri-pilot.
cafe/pantry
Code generated by petri-pilot.
Code generated by petri-pilot.
cafe/staff
Code generated by petri-pilot.
Code generated by petri-pilot.
fulfillment
Package fulfillment is the composition root of the fulfillment application: every data object is its own Petri net (see the entity subpackages), joined by the links recorded in the flattened model this package embeds.
Package fulfillment is the composition root of the fulfillment application: every data object is its own Petri net (see the entity subpackages), joined by the links recorded in the flattened model this package embeds.
fulfillment/credit
Code generated by petri-pilot.
Code generated by petri-pilot.
fulfillment/inventory
Code generated by petri-pilot.
Code generated by petri-pilot.
fulfillment/order
Code generated by petri-pilot.
Code generated by petri-pilot.
warehouse
Package warehouse is the composition root of the warehouse application: every data object is its own Petri net (see the entity subpackages), joined by the links recorded in the flattened model this package embeds.
Package warehouse is the composition root of the warehouse application: every data object is its own Petri net (see the entity subpackages), joined by the links recorded in the flattened model this package embeds.
warehouse/inventory
Code generated by petri-pilot.
Code generated by petri-pilot.
warehouse/order
Code generated by petri-pilot.
Code generated by petri-pilot.
internal
llm
Package llm provides an abstraction layer for LLM providers.
Package llm provides an abstraction layer for LLM providers.
version
Package version provides build-time version information.
Package version provides build-time version information.
pkg
bridge
Package bridge provides code generation helpers for petri-pilot.
Package bridge provides code generation helpers for petri-pilot.
bundle
Package bundle is petri-pilot's authoring surface for composed applications: N entity nets joined into one go-pflow metamodel.Bundle, flattened for code generation.
Package bundle is petri-pilot's authoring surface for composed applications: N entity nets joined into one go-pflow metamodel.Bundle, flattened for code generation.
codegen/core
Package core generates a dependency-free, single-file state machine from a Petri net model — the "core" the model specifies, with nothing app-shaped around it.
Package core generates a dependency-free, single-file state machine from a Petri net model — the "core" the model specifies, with nothing app-shaped around it.
codegen/esmodules
Package esmodules generates vanilla JavaScript frontend applications from Petri net models.
Package esmodules generates vanilla JavaScript frontend applications from Petri net models.
codegen/golang
Package golang generates Go code from Petri net models.
Package golang generates Go code from Petri net models.
codegen/zkgo
Package zkgo generates ZK circuit code from Petri net models.
Package zkgo generates ZK circuit code from Petri net models.
delegate
Package delegate provides a client for delegating app generation to GitHub Copilot.
Package delegate provides a client for delegating app generation to GitHub Copilot.
dsl
Package dsl implements a guard expression DSL for Petri net transitions.
Package dsl implements a guard expression DSL for Petri net transitions.
extensions
Package extensions provides adapters for integrating the new extension-based ApplicationSpec with the existing petri-pilot codegen system.
Package extensions provides adapters for integrating the new extension-based ApplicationSpec with the existing petri-pilot codegen system.
feedback
Package feedback generates structured prompts for LLM refinement.
Package feedback generates structured prompts for LLM refinement.
generator
Package generator provides LLM-based Petri net model generation.
Package generator provides LLM-based Petri net model generation.
mcp
Package mcp provides MCP server prompt handlers for guided Petri net workflows.
Package mcp provides MCP server prompt handlers for guided Petri net workflows.
metamodel
Package metamodel provides the core metamodel types for Petri net execution.
Package metamodel provides the core metamodel types for Petri net execution.
runtime/api
Package api provides HTTP API abstractions for generated applications.
Package api provides HTTP API abstractions for generated applications.
runtime/engine
Package engine provides a runtime engine that wraps the metamodel.Runtime with event sourcing capabilities for petri-pilot generated applications.
Package engine provides a runtime engine that wraps the metamodel.Runtime with event sourcing capabilities for petri-pilot generated applications.
runtime/sim
Package sim runs a model forward in time without changing it.
Package sim runs a model forward in time without changing it.
runtime/sim/internal/paritygolden command
Command paritygolden writes the byte-exact parity goldens that go-pflow's stochastic package checks itself against forever.
Command paritygolden writes the byte-exact parity goldens that go-pflow's stochastic package checks itself against forever.
serve
Package serve provides unified GraphQL support for Petri-pilot services.
Package serve provides unified GraphQL support for Petri-pilot services.
services/pflowxyz
Package pflowxyz provides a service adapter for pflow-xyz.
Package pflowxyz provides a service adapter for pflow-xyz.
validator
Package validator provides formal validation of Petri net models using go-pflow.
Package validator provides formal validation of Petri net models using go-pflow.
Package jsonschema embeds the Petri net model JSON Schema.
Package jsonschema embeds the Petri net model JSON Schema.
Package services embeds service Petri net models.
Package services embeds service Petri net models.
Package zkode implements a ZK circuit that proves correct execution of a Tsit5 ODE solver over encrypted Petri net state.
Package zkode implements a ZK circuit that proves correct execution of a Tsit5 ODE solver over encrypted Petri net state.
cmd/export-ttt-verifier command
Command export-ttt-verifier compiles the TTT heatmap circuit, generates keys, and exports the Solidity verifier contract.
Command export-ttt-verifier compiles the TTT heatmap circuit, generates keys, and exports the Solidity verifier contract.
cmd/submit-ttt-proof command
Command submit-ttt-proof generates TTT ZK proofs using the heatmap circuit (tactical win/block detection) and prints cast send commands for on-chain submission.
Command submit-ttt-proof generates TTT ZK proofs using the heatmap circuit (tactical win/block detection) and prints cast send commands for on-chain submission.
Package zkpoker provides GraphQL support for ZK poker operations.
Package zkpoker provides GraphQL support for ZK poker operations.
Package zktictactoe provides GraphQL support for ZK proof operations.
Package zktictactoe provides GraphQL support for ZK proof operations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL