domain.events.sse_registry¶
src.domain.events.sse_registry
¶
SSE Event Registry - Single Source of Truth.
This registry catalogs all SSE event types and their mappings from domain events. Used for: - Container wiring (automated SSEEventHandler subscriptions) - Validation tests (verify no drift) - Documentation generation (always accurate) - Gap detection (missing mappings)
Architecture
- Domain layer (no dependencies on infrastructure)
- Imported by container for automated wiring
- Verified by tests to catch drift
Adding new SSE mappings (separate issues, not foundation): 1. Add mapping to DOMAIN_TO_SSE_MAPPING 2. Run tests - they validate the mapping 3. Container auto-wires SSEEventHandler subscriptions
Reference
- docs/architecture/sse-architecture.md
Classes¶
SSEEventMetadata
dataclass
¶
Metadata for an SSE event type.
Attributes:
| Name | Type | Description |
|---|---|---|
event_type |
SSEEventType
|
The SSE event type enum value. |
category |
SSEEventCategory
|
Event category for filtering. |
description |
str
|
Human-readable description. |
payload_fields |
list[str]
|
Expected fields in the event data payload. |
Source code in src/domain/events/sse_registry.py
DomainToSSEMapping
dataclass
¶
Mapping from a domain event to an SSE event.
Defines how a domain event is transformed into an SSE event for real-time client notification.
Attributes:
| Name | Type | Description |
|---|---|---|
domain_event_class |
Type[DomainEvent]
|
The domain event class to listen for. |
sse_event_type |
SSEEventType
|
The SSE event type to emit. |
payload_extractor |
Callable[[DomainEvent], dict[str, Any]]
|
Function to extract SSE payload from domain event. Takes (domain_event, user_id) and returns dict payload. |
user_id_extractor |
Callable[[DomainEvent], Any]
|
Function to extract user_id from domain event. Takes domain_event and returns UUID. |
Source code in src/domain/events/sse_registry.py
Functions¶
get_domain_event_to_sse_mapping
¶
Get mapping from domain event class to SSE mapping.
Used by SSEEventHandler to determine if a domain event should trigger an SSE notification and how to transform it.
Returns:
| Type | Description |
|---|---|
dict[Type[DomainEvent], DomainToSSEMapping]
|
Dict mapping domain event classes to their SSE mapping metadata. |
Example
mapping = get_domain_event_to_sse_mapping() if AccountSyncSucceeded in mapping: ... sse_mapping = mapping[AccountSyncSucceeded] ... # Transform and publish SSE event
Source code in src/domain/events/sse_registry.py
get_sse_event_metadata
¶
Get metadata for an SSE event type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_type
|
SSEEventType
|
The SSE event type to look up. |
required |
Returns:
| Type | Description |
|---|---|
SSEEventMetadata | None
|
SSEEventMetadata if found, None otherwise. |
Source code in src/domain/events/sse_registry.py
get_events_by_category
¶
Get all SSE event metadata for a category.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
category
|
SSEEventCategory
|
The category to filter by. |
required |
Returns:
| Type | Description |
|---|---|
list[SSEEventMetadata]
|
List of SSEEventMetadata for events in that category. |
Source code in src/domain/events/sse_registry.py
get_all_sse_event_types
¶
Get list of all registered SSE event types.
Returns:
| Type | Description |
|---|---|
list[SSEEventType]
|
List of all SSE event types in the registry. |
get_registry_statistics
¶
Get statistics about the SSE event registry.
Returns:
| Name | Type | Description |
|---|---|---|
dict[str, object]
|
Dict with counts by category and totals. |
|
Keys |
dict[str, object]
|
total_event_types (int), total_mappings (int), by_category (dict[str, int]). |
Example
stats = get_registry_statistics() print(stats) { "total_event_types": 21, "total_mappings": 0, # Until use case issues implemented "by_category": { "data_sync": 9, "provider": 4, "ai": 3, ... } }