Skip to content

Comments

feat: implement event-driven module communication#352

Open
Chemaclass wants to merge 2 commits intomainfrom
feat/event-driven-modules
Open

feat: implement event-driven module communication#352
Chemaclass wants to merge 2 commits intomainfrom
feat/event-driven-modules

Conversation

@Chemaclass
Copy link
Member

@Chemaclass Chemaclass commented Feb 13, 2026

TL;DR

Adds EventBus and ModuleEvent infrastructure to enable loose coupling between modules through event-driven architecture, improving modularity and testability.

Summary

  • EventBus for publishing and subscribing to module events with type-safe listener registration
  • ModuleEvent base class with metadata support for custom event data
  • Comprehensive documentation with practical examples and usage patterns
  • Full test coverage for event bus functionality and module events

Key Features

Loose Coupling: Modules can communicate without direct dependencies through event-driven patterns

Type Safety: Strongly typed event handling with generics for compile-time safety

Metadata Support: Attach arbitrary data to events for flexible event payloads

Listener Management: Subscribe/unsubscribe event listeners dynamically at runtime

Testability: Easy to mock and test event-driven interactions in isolation

Use Cases

  • Module lifecycle events (initialization, shutdown, configuration changes)
  • Cross-module notifications without tight coupling
  • Decoupled feature communication between bounded contexts
  • Event sourcing patterns for audit trails and debugging
  • Plugin and extension systems

Example Usage

use Gacela\Framework\Event\EventBus;
use Gacela\Framework\Event\ModuleEvent;

// Subscribe to events
EventBus::subscribe('user.created', function(ModuleEvent $event) {
    $userId = $event->getMetadata('user_id');
    // Handle user creation
});

// Publish events
EventBus::publish(new ModuleEvent('user.created', [
    'user_id' => 123,
    'timestamp' => time(),
]));

Add EventBus and ModuleEvent infrastructure to enable loose coupling
between modules through event-driven architecture.

Key features:
- EventBus for publishing and subscribing to module events
- ModuleEvent base class with metadata support
- Type-safe event handling with listener registration
- Comprehensive documentation with examples
- Full test coverage

This enables modules to communicate without direct dependencies,
improving modularity and testability.
@Chemaclass Chemaclass self-assigned this Feb 13, 2026
@Chemaclass Chemaclass added the enhancement New feature or request label Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Development

Successfully merging this pull request may close these issues.

1 participant