Merge _configs/ into config/ for single configuration directory. Update all path references. Changes: - Move _configs/* to config/ - Update .gitignore for new patterns - No code references to _configs/ found Impact: -1 root directory (layout_conventions.md compliance)
8.9 KiB
SurrealDB Integration Documentation
Complete analysis and implementation guide for migrating syntaxis from SQLite to SurrealDB.
Quick Answer
Q: What happens if we want to use SurrealDB instead of SQLite?
A:
- ✅ Possible - Excellent code separation (single persistence module)
- 📊 Effort - Medium (40-50 hours, 1 developer-month)
- 🎯 Approach - Trait-based abstraction (supports both systems)
- ✨ Benefits - Graph queries, real-time updates, built-in versioning
Documentation Files
1. 📋 SURREALDB_QUICK_REFERENCE.md (START HERE)
Best for: Quick overview, executive summary
- TL;DR answer
- Architecture diagram
- Key benefits
- 5-week implementation roadmap
- Risk assessment
- Read time: 5 minutes
2. 📚 SURREALDB_MIGRATION.md (DETAILED GUIDE)
Best for: Comprehensive planning and implementation
- Current architecture analysis
- Migration strategy (4 phases)
- Database schema mapping
- Configuration examples
- Risk mitigation
- Detailed code references
- Read time: 30 minutes
3. 💻 SURREALDB_EXAMPLE.rs (WORKING CODE)
Best for: Understanding implementation details
- Complete Database trait definition
- SQLite implementation (adapter pattern)
- SurrealDB implementation (adapter pattern)
- Runtime selection pattern
- Usage examples
- Read time: 20 minutes (code review)
4. ⚖️ SURREALDB_COMPARISON.md (FEATURE ANALYSIS)
Best for: Understanding pros/cons of each database
- Feature comparison table
- Real-world query examples (6 scenarios)
- Performance comparison
- Cost analysis
- When to use each system
- Migration path options
- Read time: 25 minutes
Quick Summary
Current System (SQLite)
✅ Strengths:
- Single file, zero configuration
- Embedded in application
- No server overhead
- Perfect for CLI tools
❌ Limitations:
- No real-time updates (polling only)
- Poor graph query support (complex JOINs)
- Manual audit trails
- Not suitable for distributed systems
Proposed System (SurrealDB)
✅ Strengths:
- Graph-native (perfect for phases/tasks/dependencies)
- Real-time WebSocket subscriptions
- Built-in versioning and audit trails
- Multi-model (document + graph + SQL)
- Cloud-ready and distributed
- JSON-native documents
⚠️ Trade-offs:
- Requires server process
- Minimal configuration needed
- New query language to learn (SurrealQL)
- Slightly higher operational overhead
Why SurrealDB Fits syntaxis
1. Graph Relationships (Natural Fit)
Syntaxis:
Project → Phase 1 → Phase 2 → Phase 3 → Complete
│ │ │ │
├─→ Checklist Items
├─→ Tasks/Dependencies
└─→ Security Assessments
SurrealDB handles this naturally with graph edges (RELATE).
2. Real-time Dashboard Updates
- SQLite: Poll every 5 seconds (inefficient)
- SurrealDB: WebSocket push (instant, real-time)
3. Flexible Tool Configurations
- SQLite: JSON strings to parse
- SurrealDB: Native document storage with type checking
4. Audit Trail Tracking
- SQLite: Manual activity_logs table
- SurrealDB: Built-in versioning and time-travel queries
Implementation Approach (Zero Breaking Changes)
Strategy: Trait-Based Abstraction
Database Trait (abstract interface)
↓
├─→ SqliteDatabase (current implementation)
└─→ SurrealDatabase (new implementation)
Result:
- Both backends implement same interface
- Application code unchanged
- Configuration-driven backend selection
- Can coexist during migration
Why This Works
- No breaking changes - Existing code uses trait, not specific implementation
- Gradual migration - Deploy with SQLite, optionally switch to SurrealDB
- Testable - Create mock implementations for tests
- Future-proof - Easy to add PostgreSQL, MongoDB, etc. later
5-Week Implementation Plan
| Week | Phase | Tasks | Effort |
|---|---|---|---|
| 1 | Design | Define Database trait, write tests | Low |
| 1-2 | Refactor | Move SQLite to adapter pattern | Medium |
| 2-3 | Implementation | Build SurrealDB adapter | High |
| 4 | Integration | Update CLI, TUI, API, Dashboard | Medium |
| 5 | Testing | E2E tests, performance benchmarks | Medium |
Total: 40-50 hours, 1 developer-week per phase
Current Code Status
Persistence Layer (syntaxis-core/src/persistence.rs)
- Size: 1492 lines
- Coupling: ✅ Good - single module, no leakage
- Abstraction: ⚠️ Tightly coupled to SQLite
- Tests: ✅ Comprehensive (173 tests in syntaxis-core)
Cargo Dependencies
# Current
sqlx = { version = "0.8", features = ["sqlite", ...] }
# Add SurrealDB
surrealdb = { version = "2.0", features = ["ws"] }
Configuration (TOML-based)
[database]
engine = "sqlite" # Current
sqlite_path = "workspace.db"
# Or in future:
# engine = "surrealdb"
# [database.surrealdb]
# url = "ws://localhost:8000"
Decision Matrix
Choose SQLite if:
- ✅ Single-user deployment (CLI tool)
- ✅ Minimal operational overhead needed
- ✅ Budget and resources constrained
- ✅ Simple relational data is sufficient
- ✅ No real-time updates required
Choose SurrealDB if:
- ✅ Multi-user/team collaboration needed
- ✅ Real-time dashboard updates required
- ✅ Complex graph relationships important
- ✅ Cloud deployment planned
- ✅ Distributed architecture needed
- ✅ Audit trail and versioning critical
Recommendation for syntaxis
✅ Implement Both (Trait Pattern)
- Keep SQLite as simple default
- Add SurrealDB as advanced option
- Configuration-driven selection
- Users choose what fits their needs
- Zero breaking changes
Next Steps
-
Review Documentation
- Start with
SURREALDB_QUICK_REFERENCE.md(5 min) - Deep dive into
SURREALDB_MIGRATION.md(30 min) - Study
SURREALDB_EXAMPLE.rscode (20 min) - Compare with
SURREALDB_COMPARISON.md(25 min)
- Start with
-
Evaluate for Your Use Case
- Single user or team?
- Need real-time updates?
- Operational overhead acceptable?
- Budget for implementation?
-
Plan Implementation
- Decide if pursuing SurrealDB support
- Estimate timeline for your team
- Create feature branch
- Start Phase 1 (trait definition)
-
Reference Code Examples
- See
SURREALDB_EXAMPLE.rsfor working code - Trait definitions
- SQLite adapter implementation
- SurrealDB adapter implementation
- Runtime selection pattern
- See
Key Files Delivered
| File | Purpose | Size | Read Time |
|---|---|---|---|
| SURREALDB_QUICK_REFERENCE.md | Executive summary | 7 KB | 5 min |
| SURREALDB_MIGRATION.md | Technical guide | 14 KB | 30 min |
| SURREALDB_EXAMPLE.rs | Working code | 15 KB | 20 min |
| SURREALDB_COMPARISON.md | Feature analysis | 12 KB | 25 min |
Total: 48 KB, ~80 minutes to fully understand
Questions to Consider
For Development Team
- Scope: Just syntaxis-cli, or all binaries (TUI, API, Dashboard)?
- Timeline: Next quarter (soon), or future?
- Resources: How many developers can dedicate time?
- Users: Single developers or teams with multiple users?
For Architecture
- Complexity: Worth adding server dependency?
- Deployment: Docker/Kubernetes, or just binaries?
- Scaling: Is distributed database ever needed?
- Data: Do we need graph queries or real-time updates?
For Operations
- Support: Can we support two backends?
- Migration: Data migration strategy needed?
- Testing: Test coverage for both backends?
- Fallback: Easy to rollback if SurrealDB doesn't work out?
Contacts & Resources
Documentation
- SurrealDB Official: https://surrealdb.com/docs
- SurrealDB Rust Client: https://github.com/surrealdb/surrealdb.rs
- SQLx Rust Async SQL: https://github.com/launchbadge/sqlx
Key References
- Graph Database Patterns: https://surrealdb.com/docs/surrealql/statements/relate
- Time-Travel Queries: https://surrealdb.com/docs/surrealql/statements/select#versioning
- Live Subscriptions: https://surrealdb.com/docs/surrealql/statements/live
Example Code
See SURREALDB_EXAMPLE.rs for:
- Database trait definition
- SQLite adapter implementation
- SurrealDB adapter implementation
- Runtime selection pattern
Summary
Can we use SurrealDB instead of SQLite?
✅ YES
- Clean code separation exists
- Trait-based design enables both backends
- Medium effort (40-50 hours)
- Zero breaking changes
- Significant benefits for multi-user/real-time use cases
Recommended Approach:
- Keep SQLite as default (current behavior)
- Add SurrealDB support incrementally
- Configuration-driven selection
- Let users choose what fits their needs
Timeline: 5 weeks with dedicated team
Document created: November 15, 2025 Status: Complete analysis and implementation guide ready for review