How j5ik2o/pekko-persistence-typed-fsm works
Main Components
• Core Library Interfaces:
• Effector: The key trait that wraps around event persistence operations.
• EffectorConfig: Provides the configuration needed to initiate an effector for a particular domain.
• MessageConverter: Handles wrapping of persisted events and recovered state, ensuring type safety and conversion between internal representations.
• Domain Logic:
• The provided example (BankAccount) acts as a case study where commands (e.g., DepositCash) trigger domain operations that yield events (e.g., CashDeposited) and then lead to state transitions.
• Aggregate state types (such as NotCreated and Created) along with associated events (and handlers) represent the DDD style of domain modeling.
• Integration with Apache Pekko:
• The actors in the system follow a Behavior-based actor model (Pekko’s recommendation). The "Effector" is typically used within an actor (child actor under an aggregate actor) for persisting state updates.
Identifying Relationships and Interactions
• How a domain actor (e.g., BankAccountAggregate) uses Effector to persist events when handling a command.
Architectural Patterns and Design Principles
• Event Sourcing Pattern:
• Actor Model:
• That the persistent actor (created via Effector) is the core component and that it is a child of the main aggregate actor.
• Separation of Concerns:
• Clear separation of persistence logic (Effector and its configuration) from domain logic (state transitions and command handling).
• Type Safety and Extensibility:
• Usage of Scala 3 type system features to enforce type safety in the definitions of state, events, and messages.
• Be as detailed as possible within each component block. For instance, you could annotate the Effector block with key functions (persist, persistAll) and include a note that this is used to eliminate double execution of domain logic.