MABEAM Extraction Plan: Comprehensive Migration Strategy
Executive Summary
This plan safely extracts MABEAM from lib/foundation/
to top-level lib/mabeam/
while maintaining full functionality and test coverage. The migration addresses critical circular dependencies and implements a clean pseudo-monorepo structure.
Current State Analysis
Critical Issues Identified
- Circular Dependency: Foundation.Application directly supervises 8 MABEAM services (lines 135-198)
- Configuration Coupling: Config references
Foundation.MABEAM.ProcessRegistry.Backend.LocalETS
- Test Infrastructure: MABEAM test helpers embedded in Foundation test support
- Namespace Conflicts: Potential conflicts between Foundation and MABEAM modules
Assets to Migrate
- Source Files: 17 modules in
lib/foundation/mabeam/
- Test Files: 19 comprehensive test files with 332 passing tests
- Configuration: MABEAM-specific config in
config/config.exs
- Supervision: 8 GenServer processes requiring supervision
Migration Strategy: Safe Extraction with Integration Layer
Phase 1: File Structure Migration
- Move Source Code:
lib/foundation/mabeam/
→lib/mabeam/
- Move Tests:
test/foundation/mabeam/
→test/mabeam/
- Update Namespaces:
Foundation.MABEAM
→MABEAM
- Preserve Test Structure: Maintain pseudo-monorepo test organization
Phase 2: Dependency Resolution
- Break Circular Dependencies: Update Foundation.Application to conditionally load MABEAM
- Configuration Migration: Update config to reference new namespaces
- Integration Layer: Create optional MABEAM integration for Foundation
- Test Infrastructure: Extract MABEAM test helpers to appropriate location
Phase 3: Supervision Architecture
- MABEAM Application: Create
lib/mabeam/application.ex
for MABEAM supervision - Foundation Integration: Update Foundation.Application to optionally include MABEAM
- Service Discovery: Ensure MABEAM services can discover Foundation services
- Graceful Degradation: Foundation works with or without MABEAM
Phase 4: Test Structure Enhancement
- Pseudo-Monorepo Support: Organize tests by logical components
- Integration Tests: Create cross-component integration test suite
- Test Helpers: Properly distribute test utilities
- Coverage Maintenance: Ensure all 332 tests continue passing
Detailed Implementation Steps
Step 1: Pre-Migration Validation
# Verify current test status
mix test
# Expected: 332 tests, 0 failures
# Backup current state
git add -A && git commit -m "Pre-MABEAM migration checkpoint"
Step 2: File Movement and Namespace Updates
# Move source files
mv lib/foundation/mabeam lib/mabeam
# Move test files
mkdir -p test/mabeam
mv test/foundation/mabeam/* test/mabeam/
rmdir test/foundation/mabeam
# Update all namespaces
find lib test -name "*.ex" -o -name "*.exs" | xargs sed -i 's/Foundation\.MABEAM/MABEAM/g'
Step 3: Application Architecture Updates
# lib/mabeam/application.ex (NEW)
defmodule MABEAM.Application do
use Application
def start(_type, _args) do
children = [
# All MABEAM services moved here
{MABEAM.Core, name: :mabeam_core},
{MABEAM.AgentRegistry, name: :mabeam_agent_registry},
# ... other MABEAM services
]
opts = [strategy: :one_for_one, name: MABEAM.Supervisor]
Supervisor.start_link(children, opts)
end
end
# lib/foundation/application.ex (UPDATED)
defmodule Foundation.Application do
# Remove MABEAM services from children list
# Add conditional MABEAM integration if desired
end
Step 4: Configuration Updates
# config/config.exs
config :mabeam, [
use_unified_registry: true,
legacy_registry: [
backend: MABEAM.ProcessRegistry.Backend.LocalETS,
auto_start: false
]
]
Step 5: Integration Layer (Optional)
# lib/foundation/mabeam_integration.ex (NEW)
defmodule Foundation.MABEAMIntegration do
@moduledoc """
Optional integration layer for MABEAM services.
Provides backward compatibility and service discovery.
"""
def mabeam_available?, do: Code.ensure_loaded?(MABEAM.Core)
def start_mabeam_services do
if mabeam_available?() do
MABEAM.Application.start(:normal, [])
else
{:error, :mabeam_not_available}
end
end
end
Risk Mitigation
Test Coverage Protection
- Pre-migration: Capture current test results
- Post-migration: Verify all tests still pass
- Rollback Plan: Git checkpoint before each major step
Dependency Safety
- Foundation Independence: Ensure Foundation works without MABEAM
- MABEAM Dependencies: Maintain MABEAM’s dependency on Foundation services
- Service Discovery: Use runtime checks for service availability
Configuration Compatibility
- Backward Compatibility: Support old config structure during transition
- Migration Warnings: Log warnings for deprecated config
- Documentation: Clear upgrade path for users
Validation Criteria
Success Metrics
- ✅ All 332 tests pass after migration
- ✅ Foundation.Application starts successfully without MABEAM references
- ✅ MABEAM services can be started independently
- ✅ No circular dependencies between Foundation and MABEAM
- ✅ Configuration properly references new namespaces
- ✅ Test structure supports pseudo-monorepo pattern
Post-Migration Verification
# Test compilation
mix compile
# Test suite execution
mix test
# Dependency analysis
mix xref graph --format dot
# Module availability
iex -S mix -c "Code.ensure_loaded?(MABEAM.Core)"
Rollback Strategy
If migration fails:
- Git Reset:
git reset --hard HEAD~1
to checkpoint - Dependency Check: Verify all references restored
- Test Validation: Ensure original test suite passes
- Issue Analysis: Identify specific failure points
Post-Migration Benefits
- Clean Architecture: Clear separation of concerns
- Independent Development: MABEAM can evolve independently
- Optional Integration: Foundation users can choose MABEAM inclusion
- Better Testing: Pseudo-monorepo structure supports better test organization
- Maintainability: Reduced coupling improves long-term maintenance
Timeline
- Phase 1: File Migration (30 minutes)
- Phase 2: Dependency Resolution (1 hour)
- Phase 3: Supervision Updates (45 minutes)
- Phase 4: Test Structure (30 minutes)
- Total: ~2.5 hours with validation
Next Steps
- Execute the comprehensive migration script
- Validate all tests pass
- Update documentation to reflect new structure
- Create integration examples for users
- Plan for eventual MABEAM library extraction