Architecture

Core architecture and design concepts


Architecture

The Graph Engine is a finite state machine (FSM) executor designed for AI workflows.

System Overview

┌─────────────────────────────────────────────────────────────────┐
│                     defineWorkflow() DSL                         │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                       Graph Engine                               │
│  ┌─────────────┐    ┌─────────────┐    ┌─────────────┐         │
│  │ State       │    │ Node        │    │ Transition  │         │
│  │ Manager     │◀──▶│ Executor    │◀──▶│ Resolver    │         │
│  └─────────────┘    └─────────────┘    └─────────────┘         │
│         │                  │                                     │
│         ▼                  ▼                                     │
│  ┌─────────────┐    ┌─────────────────────────────────┐         │
│  │ Persistence │    │         Node Types              │         │
│  │ (.json)     │    │  ┌────────┐ ┌────────┐ ┌──────┐│         │
│  └─────────────┘    │  │ Agent  │ │Command │ │Slash ││         │
│                     │  │  Node  │ │  Node  │ │ Cmd  ││         │
│                     │  └────────┘ └────────┘ └──────┘│         │
│                     └─────────────────────────────────┘         │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                    Claude Agent SDK                              │
└─────────────────────────────────────────────────────────────────┘

Core Components

State Manager

Manages workflow state throughout execution:

Node Executor

Executes individual nodes:

Transition Resolver

Determines workflow routing:

Persistence Layer

Enables checkpoint/resume:

Execution Flow

┌─────────────┐     ┌─────────────┐     ┌─────────────┐
│   START     │────▶│  EXECUTE    │────▶│  PERSIST    │
│ Load State  │     │    Node     │     │   State     │
└─────────────┘     └─────────────┘     └─────────────┘
                           │                    │
                           │                    ▼
                           │            ┌─────────────┐
                           │            │  RESOLVE    │
                           │            │ Transition  │
                           │            └─────────────┘
                           │                    │
                           ▼                    ▼
                    ┌─────────────┐     ┌─────────────┐
                    │   ERROR     │     │   NEXT      │
                    │  Handler    │     │   Node?     │
                    └─────────────┘     └─────────────┘
                                               │
                                    ┌──────────┴──────────┐
                                    │                     │
                                    ▼                     ▼
                             ┌─────────────┐       ┌─────────────┐
                             │   LOOP      │       │    END      │
                             │  (next node)│       │  Complete   │
                             └─────────────┘       └─────────────┘
  1. Start: Load existing state or initialize new workflow
  2. Execute: Run the current node’s logic
  3. Persist: Save state to disk
  4. Resolve: Determine next node from transition
  5. Loop or End: Continue to next node or complete workflow

Design Principles

Single Responsibility

Each node type handles one concern:

Immutable State Updates

Nodes return partial state updates that are merged:

// Node returns partial update
return { context: { ...state.context, result: data } };

// Engine merges into full state
newState = { ...oldState, ...partialUpdate };

Deterministic Transitions

Transitions are pure functions of state:

// Given the same state, always returns the same next node
then: (state) => state.context.success ? 'DEPLOY' : 'ROLLBACK'

Fail-Safe Persistence

State is saved after every successful node:

File Structure

project/
├── atomic.config.ts          # Workflow definition
└── .graph-state/
    └── {workflow-id}.json    # Persisted state