Skip to main content

Shared Event Sourced Aggregate

Description

An Event Sourced Aggregate that is part of the Shared Kernel.

Definition Schema

The definition for a shared_event_sourced_aggregate component expects the following structure:

{
"$defs": {
"AggregateCreationParameterInputDTO": {
"description": "Defines a parameter for the initiate_creation class method.",
"example": {
"param_name": "title",
"param_type_str": "str"
},
"properties": {
"param_name": {
"title": "Param Name",
"type": "string"
},
"param_type_str": {
"title": "Param Type Str",
"type": "string"
}
},
"required": [
"param_name",
"param_type_str"
],
"title": "AggregateCreationParameterInputDTO",
"type": "object"
},
"AggregateStateParameterInputDTO": {
"description": "Defines a state field within the aggregate.",
"example": {
"param_name": "title",
"param_type_str": "str"
},
"properties": {
"param_name": {
"title": "Param Name",
"type": "string"
},
"param_type_str": {
"title": "Param Type Str",
"type": "string"
}
},
"required": [
"param_name",
"param_type_str"
],
"title": "AggregateStateParameterInputDTO",
"type": "object"
},
"EventToApplierMappingDTO": {
"properties": {
"event_name_str": {
"description": "Name of the event class (e.g., 'OrderCreated')",
"title": "Event Name Str",
"type": "string"
},
"event_module_str": {
"description": "Module path for the event (e.g., 'app_root_name.domain.ordering.events')",
"title": "Event Module Str",
"type": "string"
},
"applier_method_name": {
"description": "Name of the method in the aggregate that applies this event (e.g., '_apply_order_created')",
"title": "Applier Method Name",
"type": "string"
}
},
"required": [
"event_name_str",
"event_module_str",
"applier_method_name"
],
"title": "EventToApplierMappingDTO",
"type": "object"
},
"SnapshotStateFieldDTO": {
"properties": {
"param_name": {
"title": "Param Name",
"type": "string"
},
"param_type_str": {
"title": "Param Type Str",
"type": "string"
}
},
"required": [
"param_name",
"param_type_str"
],
"title": "SnapshotStateFieldDTO",
"type": "object"
}
},
"example": {
"creation_event_module": "app_root_name.domain.ticketing.events",
"creation_event_name": "TicketOpenedEvent",
"creation_parameters": [
{
"param_name": "title",
"param_type_str": "str"
},
{
"param_name": "reported_by_id",
"param_type_str": "uuid.UUID"
}
],
"event_appliers": [
{
"applier_method_name": "_apply_ticket_opened",
"event_module_str": "app_root_name.domain.ticketing.events",
"event_name_str": "TicketOpenedEvent"
},
{
"applier_method_name": "_apply_ticket_closed",
"event_module_str": "app_root_name.domain.ticketing.events",
"event_name_str": "TicketClosedEvent"
}
],
"id_type_str": "uuid.UUID",
"map_aggregate_id_to_event_field": "ticket_id",
"name": "TicketAggregate",
"snapshot_fields": [
{
"param_name": "title",
"param_type_str": "str"
},
{
"param_name": "status",
"param_type_str": "str"
}
],
"state_parameters": [
{
"param_name": "title",
"param_type_str": "str"
},
{
"param_name": "status",
"param_type_str": "str"
}
]
},
"properties": {
"name": {
"description": "Name of the Event-Sourced Aggregate class (e.g., 'OrderAggregate')",
"title": "Name",
"type": "string"
},
"id_type_str": {
"description": "Type hint for the aggregate's ID (e.g., 'uuid.UUID', 'int')",
"title": "Id Type Str",
"type": "string"
},
"state_parameters": {
"description": "Fields representing the aggregate's mutable state.",
"items": {
"$ref": "#/$defs/AggregateStateParameterInputDTO"
},
"title": "State Parameters",
"type": "array"
},
"event_appliers": {
"description": "Mappings of events to their applier methods.",
"items": {
"$ref": "#/$defs/EventToApplierMappingDTO"
},
"title": "Event Appliers",
"type": "array"
},
"snapshot_fields": {
"description": "Fields to include in the snapshot state.",
"items": {
"$ref": "#/$defs/SnapshotStateFieldDTO"
},
"title": "Snapshot Fields",
"type": "array"
},
"creation_event_name": {
"description": "Name of the event raised upon creation (e.g., 'OrderCreated')",
"title": "Creation Event Name",
"type": "string"
},
"creation_event_module": {
"description": "Module path for the creation event (e.g., 'app_root_name.domain.ordering.events')",
"title": "Creation Event Module",
"type": "string"
},
"creation_parameters": {
"description": "Parameters for the 'create' classmethod.",
"items": {
"$ref": "#/$defs/AggregateCreationParameterInputDTO"
},
"title": "Creation Parameters",
"type": "array"
},
"map_aggregate_id_to_event_field": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Name of the field in the creation event that should be populated with the aggregate's ID (e.g., 'ticket_id', 'aggregate_id').",
"title": "Map Aggregate Id To Event Field"
}
},
"required": [
"name",
"id_type_str",
"creation_event_name",
"creation_event_module"
],
"title": "EventSourcedAggregateEngineInputDTO",
"type": "object"
}

Naming and Location Conventions

Class: PascalCase, typically ends with 'EventSourcedAggregate'. File: ${shared_event_sourced_aggregate_name}.py (based on ${shared_event_sourced_aggregate_name}). Location: app/domain/shared_kernel/event_sourced_aggregates.

Example Definition

{
"name": "TicketAggregate",
"id_type_str": "uuid.UUID",
"state_parameters": [
{
"param_name": "title",
"param_type_str": "str"
},
{
"param_name": "status",
"param_type_str": "str"
}
],
"event_appliers": [
{
"event_name_str": "TicketOpenedEvent",
"event_module_str": "app_root_name.domain.ticketing.events",
"applier_method_name": "_apply_ticket_opened"
},
{
"event_name_str": "TicketClosedEvent",
"event_module_str": "app_root_name.domain.ticketing.events",
"applier_method_name": "_apply_ticket_closed"
}
],
"snapshot_fields": [
{
"param_name": "title",
"param_type_str": "str"
},
{
"param_name": "status",
"param_type_str": "str"
}
],
"creation_event_name": "TicketOpenedEvent",
"creation_event_module": "app_root_name.domain.ticketing.events",
"creation_parameters": [
{
"param_name": "title",
"param_type_str": "str"
},
{
"param_name": "reported_by_id",
"param_type_str": "uuid.UUID"
}
],
"map_aggregate_id_to_event_field": "ticket_id"
}