Hybrid Mode
Hybrid Mode combines Bus Mode (CQRS) and Direct Mode (Use Case) within the same application. Each module independently chooses the appropriate mode based on complexity.
Architecture Flexibility
Phexium supports mixing both modes:
- Bus Mode for complex operations
- Direct Mode for simple operations
- Both coexist without conflict
- Shared plugin system and infrastructure
Example from Demo Application
The demo application demonstrates hybrid architecture:
- Homepage: Simple welcome message → Direct Mode
- Library: Book CRUD with events and permissions → Bus Mode
- Loan: Complex borrowing/return workflows → Bus Mode
- User: Authentication with security events → Bus Mode
Benefits
- Optimal Complexity: Simple features stay simple, complex features get proper structure
- Development Speed: Prototype quickly with Direct Mode, refactor to Bus Mode when needed
- Gradual Migration: Migrate features incrementally without big-bang changes
Configuration
Both modes share infrastructure in config/container.php. Bus dependencies (CommandBus, QueryBus) and Direct Mode dependencies (UseCases) are registered in the same container.
Migration Path
Controllers change minimally when migrating:
// Before (Direct Mode)
$this->useCase->execute($request);
// After (Bus Mode)
$this->commandBus->dispatch($command);
See Also
- Demo Application Overview - Hybrid architecture in action