# j5ik2o/event-store-adapter-go architecture

> Architecture diagram of the GitHub repository j5ik2o/event-store-adapter-go, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/j5ik2o/event-store-adapter-go
- Repository: https://github.com/j5ik2o/event-store-adapter-go

## Overview

##### 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

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Layer
    UA["User Account Repository"]:::repo

    %% Abstraction Layer
    ES["EventStore (Interface)"]:::interface

    %% Concrete Implementations
    ESDyn["EventStoreOnDynamoDB"]:::adapter
    ESMem["EventStoreOnMemory"]:::adapter

    %% External Service
    AWS["AWS DynamoDB Service"]:::external

    %% Support Utilities
    Serializer["Serializer"]:::utility
    KeyResolver["Key Resolver"]:::utility
    CommonDynamo["Common DynamoDB Utilities"]:::utility

    %% Connections
    UA -->|"StoreEvent"| ES
    UA -->|"ReplayEvents"| ES

    ES -->|"implBy"| ESDyn
    ES -->|"implBy"| ESMem

    ESDyn -->|"uses"| Serializer
    ESDyn -->|"uses"| KeyResolver
    ESDyn -->|"uses"| CommonDynamo
    ESDyn -->|"calls"| AWS

    %% Click Events
    click UA "https://github.com/j5ik2o/event-store-adapter-go/blob/main/test/user_account_repository_test.go"
    click ES "https://github.com/j5ik2o/event-store-adapter-go/blob/main/pkg/event_store.go"
    click ESDyn "https://github.com/j5ik2o/event-store-adapter-go/blob/main/pkg/event_store_on_dynamodb.go"
    click ESMem "https://github.com/j5ik2o/event-store-adapter-go/blob/main/pkg/event_store_on_memory.go"
    click Serializer "https://github.com/j5ik2o/event-store-adapter-go/blob/main/pkg/serializer.go"
    click KeyResolver "https://github.com/j5ik2o/event-store-adapter-go/blob/main/pkg/key_resolver.go"
    click CommonDynamo "https://github.com/j5ik2o/event-store-adapter-go/blob/main/pkg/common/dynamodb.go"

    %% Styles
    classDef repo fill:#ffe6e6,stroke:#cc0000,stroke-width:2px
    classDef interface fill:#e6f7ff,stroke:#0066cc,stroke-width:2px
    classDef adapter fill:#e6ffe6,stroke:#009933,stroke-width:2px
    classDef external fill:#fff2cc,stroke:#e6b800,stroke-width:2px
    classDef utility fill:#f2e6ff,stroke:#8000cc,stroke-width:2px
```
