Architecture & Internals

VaakWorkflow Architecture

State-machine execution model engineered with write-ahead persistence, distributed worker dispatching, and zero-loss crash recovery.

Engine Architecture

Decoupled state management and worker execution guaranteeing reliable distributed operations.

Directed Acyclic Graph (DAG)

Declarative graph definition supporting linear, branching, conditional fan-out, and join barrier coordination with strict cycle detection.

Durable State Machines

Every transition is committed to durable storage (SQLite / PostgreSQL / Redis) before invoking step handlers, allowing zero-loss recovery from crashes.

Granular Telemetry & Logs

Full step-by-step audit traces capturing input payloads, output results, memory utilization, step durations, and error stack snapshots.

Pluggable Worker Pools

Execute tasks across local in-process threads, distributed worker queues, serverless lambdas, or containerized background jobs seamlessly.

Part I

Logical Architecture

Functional domain decomposition, conceptual boundaries, and mathematical finite-state automata progression models independent of physical infrastructure.

1. LOGICAL PERSONAS & EVENT INGESTION Client Microservices Human Approvers Temporal Schedulers External Webhooks 2. PRESENTATION, DSL & DEFINITION REGISTRY Fluent WorkflowBuilder DSL WorkflowEngine Dispatch API Immutable Definition Registry 3. DETERMINISTIC FSM CORE & HUMAN-IN-THE-LOOP GOVERNANCE FSM State Coordinator • Mathematical FSM delta(q, e, c) • Guard expressions & custom fns • Strict cycle & loop detection Approval Quorum Gate • Multi-stakeholder quorum rule • State visit counter scoping • Auto-escalation timeout monitors Action & Plugin Hooks • onEnter / onExit side-effects • validateTransition observer veto • Transactional outbox emitter 4. POLICY, PROTO-SHIELD & STORAGE ABSTRACTION Prototype Shield Blocks __proto__ & constructor 85% Memory Governor Drains bursts before OOM Optimistic Locking Atomic revision counter Audit Journal Repo Monotonic seq + UUID corrId
Part II

Technical Architecture & Physical Deployment Topology

Physical Kubernetes pod sizing, container resource envelopes, network ports, concurrency models, and high availability active-active clustering.

1. NETWORK PERIMETER & INGRESS CONTROLLER Cloud Load Balancer / Envoy Gateway (TLS 1.3 Term.) WAF Rate Limiting & Zero-Trust mTLS Mesh 2. KUBERNETES DEPLOYMENT TOPOLOGY (1GB POD ENVELOPES) VaakWorkflow Pod 1 (Active) • Node.js 24 LTS (--max-old-space-size=768) • CPU Limit: 1000m | RAM Limit: 1024Mi • Port 4300 (REST / Fastify) | Port 9090 (Prometheus) • Memory Governor: 85% Hard Ceiling (15% GC Headroom) VaakWorkflow Pod 2 (Active) • Node.js 24 LTS (--max-old-space-size=768) • CPU Limit: 1000m | RAM Limit: 1024Mi • Port 4300 (REST / Fastify) | Port 9090 (Prometheus) • Graceful Draining: /readyz (503) vs /healthz (200) 3. CLUSTERED DATA, REDIS & OBJECT STORAGE TIER PostgreSQL 16 Primary • Write-Ahead Log (WAL) • Row-Level Security (RLS) Redis 7 Cluster • Distributed Lock (Redlock) • Real-time event pub/sub Object Storage (S3 / GCS) • Context spill (> 2MB) • 365-day cold audit retention Disaster Recovery Metrics: RPO = 0ms (Sync WAL) RTO < 5s (K8s Pod Rescheduling) Availability: 99.999%

Fluent Workflow DSL

Type-safe DAG definition with intellisense, autocomplete, and compile-time input/output contract enforcement.

typescript — order-fulfillment-workflow.ts Type-Safe DAG
import { WorkflowBuilder } from '@vaakworkflow/sdk';

interface OrderContext {
  orderId: string;
  amount: number;
  userId: string;
  paymentConfirmed?: boolean;
  inventoryReserved?: boolean;
}

export const orderFulfillment = new WorkflowBuilder<OrderContext>('order-fulfillment')
  .startWith('validate-order', async ({ context }) => {
    if (context.amount <= 0) throw new Error('Invalid order amount');
    return { status: 'VALIDATED' };
  })
  .then('charge-payment', async ({ context }) => {
    const charge = await paymentGateway.charge(context.userId, context.amount);
    return { paymentConfirmed: true, transactionId: charge.id };
  }, {
    retry: { maxAttempts: 3, backoffMs: 1000, exponent: 2 }
  })
  .parallel('provision-services', [
    builder => builder.step('reserve-inventory', async ({ context }) => {
      await inventoryService.reserve(context.orderId);
    }),
    builder => builder.step('generate-tax-invoice', async ({ context }) => {
      await invoiceService.create(context.orderId, context.amount);
    })
  ])
  .then('dispatch-notification', async ({ context }) => {
    await notificationService.sendOrderConfirmation(context.userId, context.orderId);
  })
  .build();