ruvswarm-persistence ๐๏ธ
High-performance, ACID-compliant persistence layer for ruvswarm with SQLite and cross-platform support.
๐ฏ Overview
ruvswarm-persistence is the foundational data persistence layer for the ruvswarm distributed agent system. It provides robust, type-safe data storage with full ACID compliance, real-time persistence, and seamless cross-platform compatibility.
Built with modern Rust principles, this crate delivers memory-safe database operations, connection pooling, transaction support, and a flexible repository pattern for managing swarm agent state, task coordination, event sourcing, and performance metrics.
โจ Key Features
๐ ACID Compliance & Reliability
- Full ACID transaction support with automatic rollback
- WAL (Write-Ahead Logging) mode for optimal concurrency
- Automatic connection pooling with configurable limits
- Built-in data integrity checks and foreign key constraints
๐ High Performance
- Connection pooling with R2D2 for efficient resource management
- Optimized SQLite configuration with NORMAL synchronous mode
- Comprehensive indexing strategy for fast queries
- Automatic vacuum and checkpoint operations
๐ Cross-Platform Support
- Native: SQLite backend for desktop and server deployments
- WASM: IndexedDB backend for browser-based applications
- Memory: In-memory storage for testing and development
- Unified async/await API across all platforms
๐๏ธ Developer Experience
- Type-safe query builder with compile-time validation
- Repository pattern for clean data access abstractions
- Comprehensive error handling with detailed error types
- Extensive test coverage with property-based testing
๐ Rich Data Models
- Agents: Complete lifecycle management with heartbeat tracking
- Tasks: Priority-based task queue with dependency resolution
- Events: Event sourcing with timestamp and sequence tracking
- Messages: Inter-agent communication with read receipts
- Metrics: Performance monitoring with aggregation support
๐ Installation
Add to your Cargo.toml:
[]
= "0.1.0"
# For WASM support
[]
= { = "0.1.0", = ["wasm"] }
๐ Quick Start
Basic Usage
use ;
use HashMap;
async
Transaction Support
use ;
async
Query Builder
use ;
// Type-safe query construction
let query = new
.where_eq
.where_like
.order_by
.limit
.build;
println!;
// Output: SELECT * FROM agents WHERE status = 'active' AND agent_type LIKE 'research%' ORDER BY created_at DESC LIMIT 50
Event Sourcing
use ;
async
Real-time Metrics
use ;
async
๐๏ธ Database Schema
The persistence layer uses a comprehensive schema optimized for swarm operations:
Core Tables
agents- Agent lifecycle and metadata managementtasks- Priority-based task queue with dependenciesevents- Event sourcing for audit trailsmessages- Inter-agent communicationmetrics- Performance and monitoring dataschema_migrations- Version tracking for database evolution
Optimized Indexing
-- Performance-optimized indexes
(status);
(priority DESC);
(timestamp);
(to_agent, read);
(metric_type, timestamp);
PRAGMA Configuration
-- Optimized for concurrent access
PRAGMA foreign_keys = ON;
PRAGMA journal_mode = WAL;
PRAGMA synchronous = NORMAL;
๐๏ธ Configuration
Connection Pool Settings
use SqliteStorage;
// Custom pool configuration
let storage = builder
.max_connections
.min_idle_connections
.connection_timeout
.idle_timeout
.build
.await?;
Feature Flags
[]
= {
version = "0.1.0",
= ["wasm", "migrations"]
}
Available features:
wasm- Enable WASM/IndexedDB supportmigrations- Database migration utilitiesrusqlite-backend(default) - Native SQLite support
๐ Performance Benchmarks
Benchmarks on Apple M1 Pro with SQLite WAL mode:
| Operation | Throughput | Latency (p99) |
|---|---|---|
| Agent Insert | 15,000 ops/sec | 2.1ms |
| Task Query | 25,000 ops/sec | 1.8ms |
| Event Batch | 30,000 ops/sec | 1.2ms |
| Metric Aggregation | 8,000 ops/sec | 3.5ms |
| Transaction Commit | 5,000 ops/sec | 4.2ms |
Run cargo bench for platform-specific benchmarks
๐งช Testing
The crate includes comprehensive test coverage:
# Run all tests
# Run with coverage
# Property-based testing
# WASM testing
๐ง Advanced Usage
Custom Storage Implementation
use ;
use async_trait;
Migration Management
use ;
let migration = new;
let runner = new;
runner.run_migration.await?;
๐ API Reference
Core Traits
Storage- Main persistence interfaceTransaction- ACID transaction supportRepository<T>- Type-safe data access pattern
Data Models
AgentModel- Swarm agent representationTaskModel- Work item with priority and dependenciesEventModel- Event sourcing recordMessageModel- Inter-agent communicationMetricModel- Performance and monitoring data
Error Types
StorageError- Comprehensive error handlingDatabase- SQL execution errorsSerialization- JSON serialization issuesNotFound- Resource lookup failuresTransaction- ACID transaction errors
๐ค Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Setup
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Related Projects
- ruv-fann - Main repository and neural network foundation
- ruvswarm - Distributed agent coordination system
- ruvswarm-core - Core swarm coordination logic
๐ Support
- Documentation: docs.rs/ruvswarm-persistence
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Created by rUv - Building the future of distributed AI systems with Rust ๐ฆ