This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
# Build the package
swift build
# Run all tests
swift test
# Run specific test file or test
swift test --filter StateGraphTests.NodeObserveTests
# Build for release
swift build -c release
# Clean build artifacts
swift package clean# Update dependencies
swift package update
# Resolve dependencies
swift package resolve
# Generate Xcode project (if needed)
swift package generate-xcodeprojSwift State Graph is a reactive state management library that uses a Directed Acyclic Graph (DAG) to manage data flow and dependencies. The architecture consists of:
-
Node System - The foundation of the reactive graph:
Node<Value>: Type-safe node protocol for storing and computing valuesStored: Mutable nodes that serve as sources of truthComputed: Read-only nodes that derive values from other nodesEdge: Represents dependencies between nodes with automatic cleanup
-
Macro System - Swift macros for cleaner syntax:
@GraphStored: Property wrapper for stored values@GraphComputed: Property wrapper for computed values@GraphIgnored: Marks properties to be ignored by observation@GraphView: Generates view logic for state management
-
Storage Abstraction - Flexible backing storage:
InMemoryStorage: Default volatile storageUserDefaultsStorage: Persistent storage backed by UserDefaults- Protocol-based design allows custom storage implementations
-
Integration Points:
- SwiftUI:
GraphObjectprotocol for Environment propagation, binding support - UIKit:
withGraphTrackingfor reactive updates in UIKit views - Observable: Compatible with Swift's Observable protocol (iOS 17+)
- SwiftUI:
- Automatic Dependency Tracking: Nodes automatically track which other nodes they depend on
- Lazy Evaluation: Computed values only recalculate when accessed after dependencies change
- Thread Safety: Uses
NSRecursiveLockfor concurrent access protection - Memory Management: Weak references and automatic edge cleanup prevent retain cycles
StateGraph: Core reactive graph implementationStateGraphMacro: Swift macro implementationsStateGraphNormalization: Data normalization for relational data management
The library emphasizes declarative state management with minimal boilerplate while maintaining type safety and performance.