# premchandkpc/flow-rulz architecture

> Architecture diagram of the GitHub repository premchandkpc/flow-rulz, 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/flow-rulz
- Repository: https://github.com/premchandkpc/flow-rulz

## Overview

FlowRulz is an event-driven rules runtime with a control-plane API and a separate worker data plane. Producers publish sharded events to JetStream; workers process leased shards, evaluate rules, commit transactional state and delivery intents, then asynchronously dispatch effects. The graph also preserves documented scheduling, subscriptions, management, and console capabilities. README statements support the main lifecycle links; Rust worker internals are represented as an experimental implementation, without asserting unshown equivalence.

Main entry points: [`cmd/worker/main.go`](https://github.com/premchandkpc/flow-rulz/blob/main/cmd/worker/main.go) (Go worker), [`internal/services/events/service.go`](https://github.com/premchandkpc/flow-rulz/blob/main/internal/services/events/service.go) (Event execution), [`internal/adapters/nats/jetstream.go`](https://github.com/premchandkpc/flow-rulz/blob/main/internal/adapters/nats/jetstream.go) (JetStream log), [`internal/adapters/http/handlers`](https://github.com/premchandkpc/flow-rulz/tree/main/internal/adapters/http/handlers) (Management handlers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Control plane"]
  node_api["HTTP control API<br/>[main.go]"]
  node_http_handlers["Management handlers"]
  node_rules_config["Rules and domains<br/>[service.go]"]
  node_workflow_config["Workflow definitions<br/>[service.go]"]
  node_contract_registry["Contracts<br/>[contract.go]"]
  node_codegen["Contract codegen<br/>[generator.go]"]
end

subgraph group_processing["Event processing"]
  node_worker["Go worker<br/>[main.go]"]
  node_leases["Shard leases<br/>[lease.go]"]
  node_key_queue["Per-key queue<br/>[queue.go]"]
  node_event_service["Event execution<br/>[service.go]"]
  node_rule_engine["Rule evaluation<br/>[evaluator.go]"]
  node_subscriber_router["Subscriber routing"]
  node_rust_worker["Experimental Rust worker<br/>[main.rs]"]
  node_rust_engine["Rust event engine<br/>[engine.rs]"]
end

subgraph group_persistence["Durable state and messaging"]
  node_jetstream["JetStream log<br/>[jetstream.go]"]
  node_postgres[("Transactional state")]
  node_cache[("Runtime caches<br/>[cache.go]")]
end

subgraph group_delivery["Effects and scheduling"]
  node_outbox["Outbox delivery<br/>[worker_delivery.go]"]
  node_effect_router["Effect routing<br/>[router.go]"]
  node_scheduler["Scheduled events<br/>[scheduler.go]"]
end

subgraph group_operations["Clients and operations"]
  node_console["Operations console<br/>[App.tsx]"]
end

node_producer(("Event producer"))

node_producer -->|"publishes events"| node_jetstream
node_jetstream -->|"delivers shards"| node_worker
node_worker -->|"claims shards"| node_leases
node_worker -->|"serializes keys"| node_key_queue
node_worker -->|"processes events"| node_event_service
node_event_service -->|"evaluates rules"| node_rule_engine
node_event_service -->|"routes subscribers"| node_subscriber_router
node_event_service -->|"commits execution"| node_postgres
node_event_service -.->|"uses accelerators"| node_cache
node_worker -->|"dispatches intents"| node_outbox
node_outbox -->|"routes effects"| node_effect_router
node_effect_router -->|"publishes effects"| node_jetstream
node_worker -->|"starts scheduler"| node_scheduler
node_scheduler -->|"publishes due events"| node_jetstream
node_api -->|"serves management"| node_http_handlers
node_http_handlers -->|"manages rules"| node_rules_config
node_http_handlers -->|"manages workflows"| node_workflow_config
node_http_handlers -->|"manages contracts"| node_contract_registry
node_console -.->|"requests operations"| node_api
node_codegen -->|"generates from schemas"| node_contract_registry
node_rust_worker -->|"runs engine"| node_rust_engine
node_rust_engine -.->|"consumes events"| node_jetstream

click node_api "https://github.com/premchandkpc/flow-rulz/blob/main/cmd/api/main.go"
click node_http_handlers "https://github.com/premchandkpc/flow-rulz/tree/main/internal/adapters/http/handlers"
click node_rules_config "https://github.com/premchandkpc/flow-rulz/blob/main/internal/services/rules/service.go"
click node_workflow_config "https://github.com/premchandkpc/flow-rulz/blob/main/internal/services/workflow/service.go"
click node_contract_registry "https://github.com/premchandkpc/flow-rulz/blob/main/internal/adapters/postgres/contract.go"
click node_console "https://github.com/premchandkpc/flow-rulz/blob/main/web/console/src/App.tsx"
click node_jetstream "https://github.com/premchandkpc/flow-rulz/blob/main/internal/adapters/nats/jetstream.go"
click node_worker "https://github.com/premchandkpc/flow-rulz/blob/main/cmd/worker/main.go"
click node_leases "https://github.com/premchandkpc/flow-rulz/blob/main/internal/runtime/shard/lease.go"
click node_key_queue "https://github.com/premchandkpc/flow-rulz/blob/main/internal/runtime/keyqueue/queue.go"
click node_event_service "https://github.com/premchandkpc/flow-rulz/blob/main/internal/services/events/service.go"
click node_rule_engine "https://github.com/premchandkpc/flow-rulz/blob/main/internal/rules/evaluator.go"
click node_subscriber_router "https://github.com/premchandkpc/flow-rulz/blob/main/internal/services/events/subscriber_router.go"
click node_postgres "https://github.com/premchandkpc/flow-rulz/tree/main/internal/adapters/postgres"
click node_cache "https://github.com/premchandkpc/flow-rulz/blob/main/internal/adapters/redis/cache.go"
click node_outbox "https://github.com/premchandkpc/flow-rulz/blob/main/internal/application/worker_delivery.go"
click node_effect_router "https://github.com/premchandkpc/flow-rulz/blob/main/internal/services/effects/router.go"
click node_scheduler "https://github.com/premchandkpc/flow-rulz/blob/main/internal/runtime/scheduler/scheduler.go"
click node_rust_worker "https://github.com/premchandkpc/flow-rulz/blob/main/rust-worker/src/main.rs"
click node_rust_engine "https://github.com/premchandkpc/flow-rulz/blob/main/rust-worker/src/engine.rs"
click node_codegen "https://github.com/premchandkpc/flow-rulz/blob/main/internal/codegen/generator.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_api,node_http_handlers,node_rules_config,node_workflow_config,node_contract_registry,node_codegen toneBlue
class node_worker,node_leases,node_key_queue,node_event_service,node_rule_engine,node_subscriber_router,node_rust_worker,node_rust_engine toneAmber
class node_jetstream,node_postgres,node_cache toneMint
class node_outbox,node_effect_router,node_scheduler toneRose
class node_console,node_producer toneIndigo
```

## Components

### Control plane

- [HTTP control API](https://github.com/premchandkpc/flow-rulz/blob/main/cmd/api/main.go): `cmd/api/main.go`
- [Management handlers](https://github.com/premchandkpc/flow-rulz/tree/main/internal/adapters/http/handlers): `internal/adapters/http/handlers`
- [Rules and domains](https://github.com/premchandkpc/flow-rulz/blob/main/internal/services/rules/service.go): `internal/services/rules/service.go`
- [Workflow definitions](https://github.com/premchandkpc/flow-rulz/blob/main/internal/services/workflow/service.go): `internal/services/workflow/service.go`
- [Contracts](https://github.com/premchandkpc/flow-rulz/blob/main/internal/adapters/postgres/contract.go): `internal/adapters/postgres/contract.go`
- [Contract codegen](https://github.com/premchandkpc/flow-rulz/blob/main/internal/codegen/generator.go): `internal/codegen/generator.go`

### Event processing

- [Go worker](https://github.com/premchandkpc/flow-rulz/blob/main/cmd/worker/main.go): `cmd/worker/main.go`
- [Shard leases](https://github.com/premchandkpc/flow-rulz/blob/main/internal/runtime/shard/lease.go): `internal/runtime/shard/lease.go`
- [Per-key queue](https://github.com/premchandkpc/flow-rulz/blob/main/internal/runtime/keyqueue/queue.go): `internal/runtime/keyqueue/queue.go`
- [Event execution](https://github.com/premchandkpc/flow-rulz/blob/main/internal/services/events/service.go): `internal/services/events/service.go`
- [Rule evaluation](https://github.com/premchandkpc/flow-rulz/blob/main/internal/rules/evaluator.go): `internal/rules/evaluator.go`
- [Subscriber routing](https://github.com/premchandkpc/flow-rulz/blob/main/internal/services/events/subscriber_router.go): `internal/services/events/subscriber_router.go`
- [Experimental Rust worker](https://github.com/premchandkpc/flow-rulz/blob/main/rust-worker/src/main.rs): `rust-worker/src/main.rs`
- [Rust event engine](https://github.com/premchandkpc/flow-rulz/blob/main/rust-worker/src/engine.rs): `rust-worker/src/engine.rs`

### Durable state and messaging

- [JetStream log](https://github.com/premchandkpc/flow-rulz/blob/main/internal/adapters/nats/jetstream.go): `internal/adapters/nats/jetstream.go`
- [Transactional state](https://github.com/premchandkpc/flow-rulz/tree/main/internal/adapters/postgres): `internal/adapters/postgres`
- [Runtime caches](https://github.com/premchandkpc/flow-rulz/blob/main/internal/adapters/redis/cache.go): `internal/adapters/redis/cache.go`

### Effects and scheduling

- [Outbox delivery](https://github.com/premchandkpc/flow-rulz/blob/main/internal/application/worker_delivery.go): `internal/application/worker_delivery.go`
- [Effect routing](https://github.com/premchandkpc/flow-rulz/blob/main/internal/services/effects/router.go): `internal/services/effects/router.go`
- [Scheduled events](https://github.com/premchandkpc/flow-rulz/blob/main/internal/runtime/scheduler/scheduler.go): `internal/runtime/scheduler/scheduler.go`

### Clients and operations

- [Operations console](https://github.com/premchandkpc/flow-rulz/blob/main/web/console/src/App.tsx): `web/console/src/App.tsx`

### Other components

- **Event producer**

## Connections

- Event producer → JetStream log: publishes events
- JetStream log → Go worker: delivers shards
- Go worker → Shard leases: claims shards
- Go worker → Per-key queue: serializes keys
- Go worker → Event execution: processes events
- Event execution → Rule evaluation: evaluates rules
- Event execution → Subscriber routing: routes subscribers
- Event execution → Transactional state: commits execution
- Event execution → Runtime caches: uses accelerators
- Go worker → Outbox delivery: dispatches intents
- Outbox delivery → Effect routing: routes effects
- Effect routing → JetStream log: publishes effects
- Go worker → Scheduled events: starts scheduler
- Scheduled events → JetStream log: publishes due events
- HTTP control API → Management handlers: serves management (evidence: `cmd/api/main.go`)
- Management handlers → Rules and domains: manages rules
- Management handlers → Workflow definitions: manages workflows
- Management handlers → Contracts: manages contracts
- Operations console → HTTP control API: requests operations
- Contract codegen → Contracts: generates from schemas
- Experimental Rust worker → Rust event engine: runs engine (evidence: `rust-worker/src/main.rs`)
- Rust event engine → JetStream log: consumes events
