domain.events.registry¶
src.domain.events.registry
¶
Domain Events Registry - Single Source of Truth.
This registry catalogs ALL domain events in the system with their metadata. Used for: - Container wiring (automated subscription) - Validation tests (verify no drift) - Documentation generation (always accurate) - Gap detection (missing handlers, audit actions, etc.)
Architecture: - Domain layer (no dependencies on infrastructure) - Imported by container for automated wiring - Verified by tests to catch drift
Adding new events: 1. Define event dataclass in appropriate *_events.py file 2. Add entry to EVENT_REGISTRY below 3. Run tests - they'll tell you what's missing: - Handler methods needed - AuditAction enums needed - Container subscriptions needed (auto-wired)
Reference
- docs/architecture/domain-events-architecture.md
- F7.7 Phase 1.5: Event Registry implementation
Classes¶
EventCategory
¶
Bases: Enum
Event categories for organization and filtering.
Source code in src/domain/events/registry.py
WorkflowPhase
¶
Bases: Enum
3-state workflow phases for ATTEMPT → OUTCOME pattern.
Source code in src/domain/events/registry.py
EventMetadata
dataclass
¶
Metadata for a domain event.
Attributes:
| Name | Type | Description |
|---|---|---|
event_class |
Type[DomainEvent]
|
The event dataclass. |
category |
EventCategory
|
Event category. |
workflow_name |
str
|
Name of workflow (e.g., "user_registration"). |
phase |
WorkflowPhase
|
Workflow phase (attempted/succeeded/failed/operational). |
requires_logging |
bool
|
LoggingEventHandler handles this event. |
requires_audit |
bool
|
AuditEventHandler handles this event. |
requires_email |
bool
|
EmailEventHandler handles this event. |
requires_session |
bool
|
SessionEventHandler handles this event. |
audit_action_name |
str
|
Expected AuditAction enum name (for validation). |
Source code in src/domain/events/registry.py
Functions¶
get_all_events
¶
Get all registered event classes.
Returns:
| Type | Description |
|---|---|
list[Type[DomainEvent]]
|
List of event classes in registry. |
get_events_requiring_handler
¶
Get events requiring specific handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler_type
|
str
|
"logging", "audit", "email", or "session" |
required |
Returns:
| Type | Description |
|---|---|
list[Type[DomainEvent]]
|
List of event classes requiring that handler. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If handler_type is invalid. |
Source code in src/domain/events/registry.py
get_workflow_events
¶
Get all events for a workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow_name
|
str
|
Workflow name (e.g., "user_registration") |
required |
Returns:
| Type | Description |
|---|---|
dict[WorkflowPhase, Type[DomainEvent]]
|
Dict mapping phase to event class. |
Source code in src/domain/events/registry.py
get_expected_audit_actions
¶
Get mapping of event to expected AuditAction enum name.
Returns:
| Type | Description |
|---|---|
dict[Type[DomainEvent], str]
|
Dict mapping event class to audit action name. |
Source code in src/domain/events/registry.py
get_statistics
¶
Get registry statistics.
Returns:
| Type | Description |
|---|---|
dict[str, int | dict[str, int]]
|
Dict with counts by category, handler requirements, etc. |