Skip to main content
Version: Latest

Hybrid Architecture Implementation Summary

Overview

The hybrid architecture successfully combines Spring's profile-based dependency injection with Brobot's runtime delegation pattern, enabling flexible execution modes and gradual migration paths.

Completed Implementation

Phase 1: Profile-Based Configuration ✅

Created foundational profile support:

  • BrobotProfileAutoConfiguration - Auto-configures based on active profiles
  • brobot-test-defaults.properties - Test-optimized defaults
  • application-test.properties - Application-specific test configuration
  • Profile validation to ensure consistency

Phase 2: Component Refactoring ✅

Demonstrated refactoring pattern with text typing:

  1. Interface Extraction: TextTyper interface
  2. Profile Implementations:
    • MockTextTyper - Test profile implementation
    • LiveTextTyper - Production profile implementation
  3. Default Implementation: DefaultTextTyper - Main text typing implementation

Phase 3: Hybrid Wrapper Pattern ✅

Implemented wrapper pattern for mixed-mode execution:

  • HybridTextTyper - Bridges profile and runtime architectures
  • HybridExecutionConfiguration - Manages hybrid mode
  • Support for dynamic mode switching

Phase 4: Documentation ✅

Comprehensive documentation created:

  • Profile-based architecture guide
  • Runtime delegation migration guide
  • Mixed-mode execution guide
  • Example test scenarios

Architecture Benefits

1. Performance

  • No runtime overhead in pure profile mode
  • Better JVM optimization with static dispatch
  • Reduced complexity in execution paths

2. Flexibility

  • Three execution modes:
    • Pure profile-based (fastest)
    • Pure runtime delegation (legacy)
    • Hybrid (maximum flexibility)
  • Gradual migration path from legacy to modern
  • Dynamic switching for complex test scenarios

3. Maintainability

  • Clear separation of test and production code
  • Single responsibility for each implementation
  • Type-safe with compile-time verification

Migration Strategy

For New Components

// 1. Define interface
public interface ComponentExecutor {
Result execute(Input input);
}

// 2. Create profile implementations
@Component
@Profile("test")
public class MockComponentExecutor implements ComponentExecutor { }

@Component
@Profile("!test")
public class LiveComponentExecutor implements ComponentExecutor { }

For Existing Components

// Keep original for compatibility
public class LegacyComponent {
public Result execute() {
if (FrameworkSettings.mock) {
return mockExecute();
}
return liveExecute();
}
}

// Add hybrid wrapper
@Component
@Primary
public class HybridComponent {
@Autowired(required = false)
private MockComponent mock;

@Autowired(required = false)
private LiveComponent live;

@Autowired
private LegacyComponent legacy;

public Result execute() {
// Try profile-based first, fall back to legacy
if (mock != null && FrameworkSettings.mock) {
return mock.execute();
}
if (live != null && !FrameworkSettings.mock) {
return live.execute();
}
return legacy.execute();
}
}

Usage Examples

Standard Test Profile

@SpringBootTest
@ActiveProfiles("test")
public class StandardTest {
// Automatically uses mock implementations
}

Mixed-Mode Test

@SpringBootTest
@TestPropertySource(properties = "brobot.hybrid.enabled=true")
public class MixedModeTest {
@Autowired
private HybridComponentConfigurer configurer;

@Test
public void testWithModeSwitching() {
configurer.switchAllToMock();
// Mock operations

configurer.switchAllToLive();
// Live operations
}
}

Gradual Migration

# Start with hybrid mode
brobot.hybrid.enabled=true

# Migrate components incrementally
brobot.component.text-typer.mode=profile
brobot.component.click-executor.mode=hybrid
brobot.component.scene-provider.mode=legacy

Key Files Created

Library Level (Brobot)

  • /brobot/library/src/main/resources/brobot-test-defaults.properties
  • /brobot/library/src/main/java/io/github/jspinak/brobot/config/BrobotProfileAutoConfiguration.java
  • /brobot/library/src/main/java/io/github/jspinak/brobot/config/HybridExecutionConfiguration.java
  • /brobot/library/src/main/java/io/github/jspinak/brobot/action/internal/text/TextTyper.java
  • /brobot/library/src/main/java/io/github/jspinak/brobot/action/internal/text/MockTextTyper.java
  • /brobot/library/src/main/java/io/github/jspinak/brobot/action/internal/text/LiveTextTyper.java
  • /brobot/library/src/main/java/io/github/jspinak/brobot/action/internal/text/HybridTextTyper.java

Application Level (Claude Automator)

  • /claude-automator/src/main/resources/application-test.properties
  • /claude-automator/src/test/java/com/claude/automator/ProfileBasedMockVerificationTest.java
  • /claude-automator/src/test/java/com/claude/automator/MixedModeExecutionTest.java

Documentation

  • /brobot/docs/docs/04-testing/profile-based-architecture.md
  • /brobot/docs/docs/04-testing/mixed-mode-execution.md
  • /brobot/docs/docs/04-testing/mock-mode-guide.md
  • /brobot/docs/docs/03-core-library/guides/runtime-delegation-migration.md
  • /brobot/docs/docs/04-testing/hybrid-architecture-summary.md

Next Steps

Short Term

  1. Component Migration: Migrate high-impact components first

    • SingleClickExecutor
    • SceneProvider
    • MouseWheel
  2. Test Coverage: Add tests for hybrid mode scenarios

    • Mode switching under load
    • Concurrent mode changes
    • Error recovery patterns
  3. Performance Metrics: Benchmark profile vs. runtime approaches

    • Startup time comparison
    • Execution speed analysis
    • Memory usage patterns

Long Term

  1. Full Migration: Convert all runtime checks to profile-based
  2. Deprecation: Mark legacy runtime checks as deprecated
  3. Optimization: Remove runtime overhead completely
  4. Tooling: Create migration automation tools

Best Practices

Do's

  • ✅ Use profiles for clear environment separation
  • ✅ Implement interfaces for testability
  • ✅ Keep legacy code during migration
  • ✅ Document mode requirements clearly
  • ✅ Test both modes thoroughly

Don'ts

  • ❌ Mix profile and runtime checks in new code
  • ❌ Force immediate migration of stable components
  • ❌ Remove legacy code without migration period
  • ❌ Use hybrid mode in production (test only)
  • ❌ Switch modes during critical operations

Conclusion

The hybrid architecture successfully provides:

  1. Immediate benefits through profile-based testing
  2. Backward compatibility with existing code
  3. Flexible migration path for gradual adoption
  4. Enhanced testing capabilities with mixed-mode execution

The implementation demonstrates that Brobot can evolve from runtime delegation to profile-based architecture while maintaining stability and providing powerful new testing capabilities.