Skip to main content

Shared Projection

Description

A read-model (Projection) that is part of the Shared Kernel.

Definition Schema

The definition for a shared_projection component expects the following structure:

{
"$defs": {
"ProjectionStateFieldDTO": {
"properties": {
"name": {
"title": "Name",
"type": "string"
},
"type_str": {
"title": "Type Str",
"type": "string"
},
"default_value_str": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Default Value Str"
},
"is_factory": {
"default": false,
"title": "Is Factory",
"type": "boolean"
}
},
"required": [
"name",
"type_str"
],
"title": "ProjectionStateFieldDTO",
"type": "object"
}
},
"example": {
"description": "Tracks the state of order statuses for projection.",
"fields": [
{
"name": "projection_id",
"type_str": "ProjectionId"
},
{
"name": "order_id",
"type_str": "str"
},
{
"name": "status",
"type_str": "str"
},
{
"default_value_str": "None",
"name": "last_processed_event_id",
"type_str": "Optional[str]"
},
{
"default_value_str": "datetime.datetime.now(datetime.timezone.utc)",
"is_factory": true,
"name": "last_updated_at",
"type_str": "datetime.datetime"
}
],
"name": "OrderStatusProjectionState",
"projection_abstractions_module": "castlecraft_engineer.abstractions.projection"
},
"properties": {
"name": {
"description": "Name of the ProjectionState class (e.g., 'OrderStatusProjectionState')",
"title": "Name",
"type": "string"
},
"description": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Optional description for the class.",
"title": "Description"
},
"fields": {
"description": "Fields of the projection state dataclass.",
"items": {
"$ref": "#/$defs/ProjectionStateFieldDTO"
},
"title": "Fields",
"type": "array"
},
"projection_abstractions_module": {
"default": "castlecraft_engineer.abstractions.projection",
"description": "Module for ProjectionId, etc.",
"title": "Projection Abstractions Module",
"type": "string"
}
},
"required": [
"name"
],
"title": "ProjectionStateEngineInputDTO",
"type": "object"
}

Naming and Location Conventions

Class: PascalCase, typically ends with 'Projection'. File: ${shared_projection_name}.py (based on ${shared_projection_name}). Location: app/domain/shared_kernel/projections.

Example Definition

{
"name": "OrderStatusProjectionState",
"description": "Tracks the state of order statuses for projection.",
"fields": [
{
"name": "projection_id",
"type_str": "ProjectionId"
},
{
"name": "order_id",
"type_str": "str"
},
{
"name": "status",
"type_str": "str"
},
{
"name": "last_processed_event_id",
"type_str": "Optional[str]",
"default_value_str": "None"
},
{
"name": "last_updated_at",
"type_str": "datetime.datetime",
"default_value_str": "datetime.datetime.now(datetime.timezone.utc)",
"is_factory": true
}
],
"projection_abstractions_module": "castlecraft_engineer.abstractions.projection"
}