# premchandkpc/flowrulz architecture

> Architecture diagram of the GitHub repository premchandkpc/flowrulz, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/premchandkpc/flowrulz
- Repository: https://github.com/premchandkpc/flowrulz

## Overview

FlowRulZ is a distributed workflow and messaging runtime: clients publish, request, execute rules, or subscribe; the server compiles and distributes plans, then workers execute them through the Rust VM and route service calls and replies. The graph preserves the DSL stages, plan lifecycle, runtime, service integration, and key cluster capabilities documented in the README. Source excerpts show the DSL-to-plan path and engine compilation; several server and runtime subsystem links are documented rather than visible in sampled implementation, so those links are dashed.

Main entry points: [`runtime/src/dsl/compiler/mod.rs`](https://github.com/premchandkpc/flowrulz/blob/main/runtime/src/dsl/compiler/mod.rs) (Plan Compiler), [`server/internal/node/prod.go`](https://github.com/premchandkpc/flowrulz/blob/main/server/internal/node/prod.go) (Execution Node), [`server/internal/engine/engine.go`](https://github.com/premchandkpc/flowrulz/blob/main/server/internal/engine/engine.go) (Plan Engine), [`server/bridge/compile.go`](https://github.com/premchandkpc/flowrulz/blob/main/server/bridge/compile.go) (FFI Bridge)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["Client Access"]
  node_sdks["Client SDKs<br/>[client.go]"]
  node_nodeapi["Node API<br/>[handlers.go]"]
  node_admin["Admin API<br/>[api.go]"]
end

subgraph group_compile["Rule Compilation"]
  node_dsl["DSL Lexer<br/>[mod.rs]"]
  node_parser["DSL Parser<br/>[mod.rs]"]
  node_optimizer["DSL Optimizer<br/>[mod.rs]"]
  node_compiler["Plan Compiler<br/>[mod.rs]"]
end

subgraph group_runtime["Execution Runtime"]
  node_plan["Execution Plan<br/>[plan.rs]"]
  node_bridge["FFI Bridge<br/>[compile.go]"]
  node_engine["Plan Engine<br/>[engine.go]"]
  node_vm["Bytecode VM<br/>[vm.rs]"]
  node_execution["Execution Runtime<br/>[runtime.rs]"]
  node_types["Schema Types<br/>[resolved_type.rs]"]
  node_memory["Arena Memory<br/>[arena.rs]"]
  node_persistence[("Rule Persistence<br/>[persistence.go]")]
end

subgraph group_cluster["Cluster Operations"]
  node_scheduler["Lane Scheduler<br/>[worker.go]"]
  node_node["Execution Node<br/>[prod.go]"]
  node_partition["Partition Manager<br/>[manager.go]"]
  node_membership["Membership<br/>[membership.go]"]
  node_distribution["Plan Distribution<br/>[distributor.go]"]
  node_clusterbus["Cluster Bus<br/>[transport.go]"]
end

subgraph group_integrations["Service Integrations"]
  node_transport["Event Transport<br/>[producer.go]"]
  node_registry[("Service Registry<br/>[registry.go]")]
  node_servicecaller["Service Caller<br/>[service_caller.go]"]
  node_replyrouter["Reply Router<br/>[router.go]"]
  node_reliability["Reliability Controls<br/>[circuitbreaker.go]"]
end

node_user(("Application"))

node_user -->|"uses"| node_sdks
node_sdks -.->|"sends operations"| node_nodeapi
node_user -.->|"manages rules"| node_admin
node_admin -.->|"manages plans"| node_engine
node_nodeapi -.->|"executes rules"| node_engine
node_engine -->|"compiles DSL"| node_bridge
node_bridge -.->|"calls compile"| node_compiler
node_compiler -->|"uses tokens"| node_dsl
node_compiler -->|"reads AST"| node_parser
node_compiler -->|"uses optimized pipeline"| node_optimizer
node_dsl -.->|"produces tokens"| node_parser
node_parser -.->|"produces AST"| node_optimizer
node_optimizer -.->|"supplies pipeline"| node_compiler
node_compiler -->|"emits bytecode"| node_plan
node_compiler -->|"validates schema"| node_types
node_plan -.->|"executes bytecode"| node_vm
node_node -.->|"loads active plans"| node_engine
node_engine -.->|"persists rules"| node_persistence
node_engine -.->|"routes by lane"| node_scheduler
node_scheduler -.->|"dispatches work"| node_node
node_node -.->|"invokes VM"| node_bridge
node_bridge -.->|"executes steps"| node_execution
node_vm -.->|"uses runtime"| node_execution
node_execution -.->|"allocates buffers"| node_memory
node_membership -.->|"informs rebalance"| node_partition
node_partition -.->|"assigns shards"| node_distribution
node_distribution -.->|"distributes plans"| node_clusterbus
node_clusterbus -.->|"coordinates nodes"| node_node
node_node -.->|"produces events"| node_transport
node_node -.->|"calls services"| node_servicecaller
node_servicecaller -->|"resolves instances"| node_registry
node_servicecaller -->|"uses circuit breaker"| node_reliability
node_node -.->|"routes replies"| node_replyrouter
node_transport -.->|"delivers events"| node_user

click node_sdks "https://github.com/premchandkpc/flowrulz/blob/main/sdk/flow/client.go"
click node_nodeapi "https://github.com/premchandkpc/flowrulz/blob/main/server/internal/node/handlers.go"
click node_admin "https://github.com/premchandkpc/flowrulz/blob/main/server/internal/admin/api.go"
click node_dsl "https://github.com/premchandkpc/flowrulz/blob/main/runtime/src/dsl/lexer/mod.rs"
click node_parser "https://github.com/premchandkpc/flowrulz/blob/main/runtime/src/dsl/parser/mod.rs"
click node_optimizer "https://github.com/premchandkpc/flowrulz/blob/main/runtime/src/dsl/optimizer/mod.rs"
click node_compiler "https://github.com/premchandkpc/flowrulz/blob/main/runtime/src/dsl/compiler/mod.rs"
click node_plan "https://github.com/premchandkpc/flowrulz/blob/main/runtime/src/bytecode/plan.rs"
click node_bridge "https://github.com/premchandkpc/flowrulz/blob/main/server/bridge/compile.go"
click node_engine "https://github.com/premchandkpc/flowrulz/blob/main/server/internal/engine/engine.go"
click node_vm "https://github.com/premchandkpc/flowrulz/blob/main/runtime/src/executor/vm.rs"
click node_execution "https://github.com/premchandkpc/flowrulz/blob/main/runtime/src/executor/runtime.rs"
click node_types "https://github.com/premchandkpc/flowrulz/blob/main/runtime/src/bytecode/resolved_type.rs"
click node_memory "https://github.com/premchandkpc/flowrulz/blob/main/runtime/src/memory/arena.rs"
click node_scheduler "https://github.com/premchandkpc/flowrulz/blob/main/server/internal/scheduler/worker.go"
click node_node "https://github.com/premchandkpc/flowrulz/blob/main/server/internal/node/prod.go"
click node_partition "https://github.com/premchandkpc/flowrulz/blob/main/server/internal/partition/manager.go"
click node_membership "https://github.com/premchandkpc/flowrulz/blob/main/server/internal/membership/membership.go"
click node_distribution "https://github.com/premchandkpc/flowrulz/blob/main/server/internal/plandist/distributor.go"
click node_clusterbus "https://github.com/premchandkpc/flowrulz/blob/main/server/internal/cluster/transport.go"
click node_persistence "https://github.com/premchandkpc/flowrulz/blob/main/server/internal/engine/persistence.go"
click node_transport "https://github.com/premchandkpc/flowrulz/blob/main/server/internal/transport/producer.go"
click node_registry "https://github.com/premchandkpc/flowrulz/blob/main/server/internal/registry/registry.go"
click node_servicecaller "https://github.com/premchandkpc/flowrulz/blob/main/server/internal/node/service_caller.go"
click node_replyrouter "https://github.com/premchandkpc/flowrulz/blob/main/server/internal/replyrouter/router.go"
click node_reliability "https://github.com/premchandkpc/flowrulz/blob/main/server/internal/reliability/circuitbreaker.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_sdks,node_nodeapi,node_admin toneBlue
class node_dsl,node_parser,node_optimizer,node_compiler toneAmber
class node_plan,node_bridge,node_engine,node_vm,node_execution,node_types,node_memory,node_persistence toneMint
class node_scheduler,node_node,node_partition,node_membership,node_distribution,node_clusterbus toneRose
class node_transport,node_registry,node_servicecaller,node_replyrouter,node_reliability,node_user toneIndigo
```

## Components

### Client Access

- [Client SDKs](https://github.com/premchandkpc/flowrulz/blob/main/sdk/flow/client.go): `sdk/flow/client.go`
- [Node API](https://github.com/premchandkpc/flowrulz/blob/main/server/internal/node/handlers.go): `server/internal/node/handlers.go`
- [Admin API](https://github.com/premchandkpc/flowrulz/blob/main/server/internal/admin/api.go): `server/internal/admin/api.go`

### Rule Compilation

- [DSL Lexer](https://github.com/premchandkpc/flowrulz/blob/main/runtime/src/dsl/lexer/mod.rs): `runtime/src/dsl/lexer/mod.rs`
- [DSL Parser](https://github.com/premchandkpc/flowrulz/blob/main/runtime/src/dsl/parser/mod.rs): `runtime/src/dsl/parser/mod.rs`
- [DSL Optimizer](https://github.com/premchandkpc/flowrulz/blob/main/runtime/src/dsl/optimizer/mod.rs): `runtime/src/dsl/optimizer/mod.rs`
- [Plan Compiler](https://github.com/premchandkpc/flowrulz/blob/main/runtime/src/dsl/compiler/mod.rs): `runtime/src/dsl/compiler/mod.rs`

### Execution Runtime

- [Execution Plan](https://github.com/premchandkpc/flowrulz/blob/main/runtime/src/bytecode/plan.rs): `runtime/src/bytecode/plan.rs`
- [FFI Bridge](https://github.com/premchandkpc/flowrulz/blob/main/server/bridge/compile.go): `server/bridge/compile.go`
- [Plan Engine](https://github.com/premchandkpc/flowrulz/blob/main/server/internal/engine/engine.go): `server/internal/engine/engine.go`
- [Bytecode VM](https://github.com/premchandkpc/flowrulz/blob/main/runtime/src/executor/vm.rs): `runtime/src/executor/vm.rs`
- [Execution Runtime](https://github.com/premchandkpc/flowrulz/blob/main/runtime/src/executor/runtime.rs): `runtime/src/executor/runtime.rs`
- [Schema Types](https://github.com/premchandkpc/flowrulz/blob/main/runtime/src/bytecode/resolved_type.rs): `runtime/src/bytecode/resolved_type.rs`
- [Arena Memory](https://github.com/premchandkpc/flowrulz/blob/main/runtime/src/memory/arena.rs): `runtime/src/memory/arena.rs`
- [Rule Persistence](https://github.com/premchandkpc/flowrulz/blob/main/server/internal/engine/persistence.go): `server/internal/engine/persistence.go`

### Cluster Operations

- [Lane Scheduler](https://github.com/premchandkpc/flowrulz/blob/main/server/internal/scheduler/worker.go): `server/internal/scheduler/worker.go`
- [Execution Node](https://github.com/premchandkpc/flowrulz/blob/main/server/internal/node/prod.go): `server/internal/node/prod.go`
- [Partition Manager](https://github.com/premchandkpc/flowrulz/blob/main/server/internal/partition/manager.go): `server/internal/partition/manager.go`
- [Membership](https://github.com/premchandkpc/flowrulz/blob/main/server/internal/membership/membership.go): `server/internal/membership/membership.go`
- [Plan Distribution](https://github.com/premchandkpc/flowrulz/blob/main/server/internal/plandist/distributor.go): `server/internal/plandist/distributor.go`
- [Cluster Bus](https://github.com/premchandkpc/flowrulz/blob/main/server/internal/cluster/transport.go): `server/internal/cluster/transport.go`

### Service Integrations

- [Event Transport](https://github.com/premchandkpc/flowrulz/blob/main/server/internal/transport/producer.go): `server/internal/transport/producer.go`
- [Service Registry](https://github.com/premchandkpc/flowrulz/blob/main/server/internal/registry/registry.go): `server/internal/registry/registry.go`
- [Service Caller](https://github.com/premchandkpc/flowrulz/blob/main/server/internal/node/service_caller.go): `server/internal/node/service_caller.go`
- [Reply Router](https://github.com/premchandkpc/flowrulz/blob/main/server/internal/replyrouter/router.go): `server/internal/replyrouter/router.go`
- [Reliability Controls](https://github.com/premchandkpc/flowrulz/blob/main/server/internal/reliability/circuitbreaker.go): `server/internal/reliability/circuitbreaker.go`

### Other components

- **Application**

## Connections

- Application → Client SDKs: uses
- Client SDKs → Node API: sends operations
- Application → Admin API: manages rules
- Admin API → Plan Engine: manages plans
- Node API → Plan Engine: executes rules
- Plan Engine → FFI Bridge: compiles DSL (evidence: `server/internal/engine/engine.go`)
- FFI Bridge → Plan Compiler: calls compile
- Plan Compiler → DSL Lexer: uses tokens (evidence: `runtime/src/dsl/compiler/mod.rs`)
- Plan Compiler → DSL Parser: reads AST (evidence: `runtime/src/dsl/compiler/mod.rs`)
- Plan Compiler → DSL Optimizer: uses optimized pipeline (evidence: `runtime/src/dsl/compiler/mod.rs`)
- DSL Lexer → DSL Parser: produces tokens (evidence: `runtime/src/dsl/parser/mod.rs`)
- DSL Parser → DSL Optimizer: produces AST (evidence: `runtime/src/dsl/optimizer/mod.rs`)
- DSL Optimizer → Plan Compiler: supplies pipeline (evidence: `runtime/src/dsl/compiler/mod.rs`)
- Plan Compiler → Execution Plan: emits bytecode (evidence: `runtime/src/dsl/compiler/mod.rs`)
- Plan Compiler → Schema Types: validates schema (evidence: `runtime/src/dsl/compiler/mod.rs`)
- Execution Plan → Bytecode VM: executes bytecode
- Execution Node → Plan Engine: loads active plans
- Plan Engine → Rule Persistence: persists rules
- Plan Engine → Lane Scheduler: routes by lane
- Lane Scheduler → Execution Node: dispatches work
- Execution Node → FFI Bridge: invokes VM
- FFI Bridge → Execution Runtime: executes steps
- Bytecode VM → Execution Runtime: uses runtime
- Execution Runtime → Arena Memory: allocates buffers
- Membership → Partition Manager: informs rebalance
- Partition Manager → Plan Distribution: assigns shards
- Plan Distribution → Cluster Bus: distributes plans
- Cluster Bus → Execution Node: coordinates nodes
- Execution Node → Event Transport: produces events
- Execution Node → Service Caller: calls services
- Service Caller → Service Registry: resolves instances (evidence: `server/internal/node/service_caller.go`)
- Service Caller → Reliability Controls: uses circuit breaker (evidence: `server/internal/node/service_caller.go`)
- Execution Node → Reply Router: routes replies
- Event Transport → Application: delivers events
