# thefabric-io/eventsourcing architecture

> Architecture diagram of the GitHub repository thefabric-io/eventsourcing, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/thefabric-io/eventsourcing
- Repository: https://github.com/thefabric-io/eventsourcing

## Overview

##### Core Components (Middle Layer)
a. Aggregate Component
- As a central component
- Generic type parameter [S AggregateState]

b. Event Component
- Adjacent to Aggregate
- Generic type parameter [S AggregateState]
- Connection to EventStore interface

- AggregateState
- EventState
- Identifiable
- InceptionRecorder
- ModificationRecorder
- StorageNamer

##### Storage Layer (Bottom)
- EventStore Interface (Abstract)
- PostgreSQL Implementation (Concrete)
- Database tables/schema structure

##### Specific details
- PostgreSQL event store implementation details
- Schema name: "eventsourcing"
- Event tables based on aggregate types
- Version tracking mechanism

##### Interaction flows
- Event application flow
- Storage operations (Save, Load, History)
- State changes propagation

Detailed Component Relationships:

**Client Application**
- ↓
**[Aggregate Manager]**
- ↙     ↓    ↘
**[Events] → [State] → [Version]**
- ↓
**[Event Store Interface]**
- ↓
**[PostgreSQL Implementation]**
- ↓
**[Database]**

Key Elements to Include:

##### Type System
- Generic type relationships
- Interface implementations
- Type constraints

##### Data Flow
- Event creation and application
- State mutations
- Storage operations

##### Storage Layer
- Table structure
- Schema organization
- Event serialization

##### Configuration
- Environment variables
- Connection settings
- Schema definitions

- Blue: Core components
- Green: Interfaces
- Yellow: Implementation details
- Red: Critical paths
- Gray: External systems

- Component relationships

Remember to include notes about:
- Generic type safety
- Version management
- Event application flow
- Storage naming conventions
- Transaction boundaries

This will provide a clear understanding of both the architectural patterns and the practical implementation details of the library.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Define styles
    classDef core fill:#2374AB,stroke:#2374AB,color:white
    classDef interface fill:none,stroke:#57A773,stroke-dasharray: 5 5
    classDef storage fill:#484D6D,stroke:#484D6D,color:white
    classDef client fill:#EE6352,stroke:#EE6352,color:white
    classDef implementation fill:#57A773,stroke:#57A773,color:white

    subgraph Client["Client Application Layer"]
        ClientApp["Client Application"]:::client
    end

    subgraph Core["Event Sourcing Core Layer"]
        Aggregate["Aggregate[S AggregateState]"]:::core
        Event["Event[S AggregateState]"]:::core
        
        subgraph Interfaces["Core Interfaces"]
            direction TB
            AggState["AggregateState"]:::interface
            EventState["EventState"]:::interface
            Identifiable["Identifiable"]:::interface
            InceptionRec["InceptionRecorder"]:::interface
            ModificationRec["ModificationRecorder"]:::interface
            StorageNamer["StorageNamer"]:::interface
        end
    end

    subgraph Storage["Storage Layer"]
        EventStore["EventStore Interface"]:::interface
        
        subgraph PostgreSQL["PostgreSQL Implementation"]
            PgEventStore["PostgreSQL Event Store"]:::implementation
            DBStorage["Storage Implementation"]:::implementation
            DBModel["Database Model"]:::implementation
            DBInit["Database Initialization"]:::implementation
        end
        
        Database[(PostgreSQL DB<br>schema: eventsourcing)]:::storage
    end

    %% Relationships
    ClientApp --> Aggregate
    Aggregate <--> Event
    Event --> EventStore
    EventStore --> PgEventStore
    PgEventStore --> DBStorage
    DBStorage --> DBModel
    DBInit --> Database
    DBModel --> Database
    
    %% Component Mappings
    click Aggregate "https://github.com/thefabric-io/eventsourcing/blob/main/aggregate.go"
    click Event "https://github.com/thefabric-io/eventsourcing/blob/main/event.go"
    click EventStore "https://github.com/thefabric-io/eventsourcing/blob/main/eventstore.go"
    click PgEventStore "https://github.com/thefabric-io/eventsourcing/tree/main/pgeventstore/"
    click DBStorage "https://github.com/thefabric-io/eventsourcing/blob/main/pgeventstore/storage.go"
    click DBModel "https://github.com/thefabric-io/eventsourcing/blob/main/pgeventstore/model.go"
    click DBInit "https://github.com/thefabric-io/eventsourcing/blob/main/pgeventstore/initialize.go"

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Interfaces"]:::interface
        L3["Storage"]:::storage
        L4["Client"]:::client
        L5["Implementation"]:::implementation
    end
```
