How j5ik2o/event-store-adapter-go works
Project Type and Purpose
• This is a library (adapter) intended for Event Sourcing within a CQRS system.
• Its main purpose is to abstract the persistence mechanism, either using DynamoDB or an in-memory store, so that developers can use it to implement event-based repositories for aggregates.
• It is not a full standalone application; rather, it is a core component that would be integrated into a larger system, generally on the backend.
File Structure Insights
• The “pkg” directory hosts the core domain logic and multiple implementations:
• pkg/event_store.go defines the event store interface and its basic functionality.
• pkg/event_store_on_dynamodb.go and pkg/event_store_on_memory.go provide concrete implementations.
• Additional utilities (serializer, key resolver, common functionality) are available in pkg/common.
• The “test” folder includes tests for each adapter and repository functionality, ensuring that core interactions are validated.
• The “docs” folder contains documentation for the database schema and migration, highlighting deployment and integration considerations.
Key Components
• EventStore Interface: The abstraction that defines the operations for persisting and retrieving events, including support for snapshots.
• Concrete Implementations:
• DynamoDB-based adapter: This component interacts with the external AWS DynamoDB service. It will encapsulate table names for journal entries and snapshots, index usage, and version control.
• In-memory adapter: Meant primarily for testing or simple scenarios where persistence is not needed across sessions.
• Aggregate & Repository (example usage):
• The user repository uses the EventStore to persist events and snapshots, then calls replay functions to recreate aggregate state.
• Utility Components:
• Serializer: In charge of converting events to/from a format that can be stored in DynamoDB.
• Key Resolver: Likely involved in addressing or routing events to their proper places in the database.
• Component Blocks:
1. UserAccountRepository (or a generic repository handling domain aggregates)
2. EventStore (Interface)
a. EventStoreOnDynamoDB (implementation)
• AWS DynamoDB Service
• Utilizes: Serializer, Key Resolver
b. EventStoreOnMemory (alternative implementation)
3. Support Utilities (Serializer, Key Resolver)
• Connectors:
• Repository → EventStore: “StoreEvent”, “StoreEventAndSnapshot”, “GetLatestSnapshotById”, “GetEventsByIdSinceSeqNr”
• Adapter (DynamoDB) ↔ AWS DynamoDB Service