Workspace Migration Quick Start
This guide provides a quick overview of the workspace refactoring and how to get started.
What Changed
Rhema has been refactored from a single monolithic crate to a multi-crate workspace:
Before: Single src/ directory with all modules
After: Multiple focused crates in crates/ directory
Quick Migration Steps
1. Run the Migration Script
./scripts/migrate-to-workspace.shThis will:
-
Create a backup of your current
src/directory -
Move files to appropriate crates
-
Create initial
lib.rsfiles
2. Build the Workspace
cargo build3. Fix Compilation Errors
The migration will likely introduce import errors. You’ll need to:
-
Update imports to use crate dependencies
-
Add missing dependencies to Cargo.toml files
-
Resolve circular dependencies by moving shared code to
rhema-core
4. Test the Build
cargo test
cargo run -p rhemaCrate Overview
| Crate | Purpose | Key Modules |
|---|---|---|
rhema-core | Core data structures | schema, scope, error |
rhema-query | Query engine | query, repo_analysis |
rhema-git | Git integration | git/, git_basic |
rhema-ai | AI services | ai_service, context_injection |
rhema-mcp | MCP daemon | mcp/ |
rhema-config | Configuration | config/, safety/ |
rhema-monitoring | Performance | performance, monitoring |
rhema-integrations | External services | integrations/ |
rhema | Command line | commands/, main.rs |
rhema | Main binary | Thin wrapper around CLI |
Common Tasks
Build a Specific Crate
cargo build -p rhema-core
cargo build -p rhemaRun Tests for a Crate
cargo test -p rhema-core
cargo test -p rhema-queryRun the Binary
cargo run -p rhemaCheck Dependencies
cargo tree -p rhemaTroubleshooting
Import Errors
If you see errors like:
error[E0432]: unresolved import `crate::schema`Update the import to use the crate dependency:
// Before
use crate::schema::*;
// After
use rhema_core::schema::*;Missing Dependencies
If you see errors about missing types, add the dependency to the crate’s Cargo.toml:
[dependencies]
rhema-core = { path = "../core" }Circular Dependencies
If you get circular dependency errors, move shared code to rhema-core:
// Move common types to rhema-core
pub struct SharedType {
// ...
}Rollback
If you need to rollback:
# Restore original structure
rm -rf src
cp -r src.backup.* src/
git checkout Cargo.tomlBenefits You’ll See
-
Faster compilation - Parallel builds of independent crates
-
Better organization - Clear separation of concerns
-
Easier testing - Test individual components
-
Reusability - Use specific crates in other projects
Next Steps
-
Complete the migration by fixing all compilation errors
-
Update CI/CD pipelines to work with the workspace
-
Update documentation to reflect the new structure
-
Consider publishing individual crates to crates.io
For detailed information, see REFACTORING_TO_WORKSPACE.md.