# jaimeirazabal1/event-sourcing-app architecture

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

- Interactive diagram: https://gitdiagram.com/jaimeirazabal1/event-sourcing-app
- Repository: https://github.com/jaimeirazabal1/event-sourcing-app

## Overview

##### Main Components
- • API/Server Layer: The entry point for requests (src/server.ts) which sets up an Express API.
- • Command Component: Located in src/commands (e.g., task.commands.ts) – responsible for handling write operations (commands) such as creating or updating tasks.
- • Query Component: Found in src/queries (e.g., task.queries.ts) – used exclusively for read operations to retrieve data.
- • Event Store: In src/events (with event.store.ts) – the core element that captures and saves events, including metadata like type and payload.
- • Event Emitter: Located in src/infrastructure (event.emitter.ts) – which notifies other components of new events.
- • Projector Component: In src/projectors (e.g., task.projector.ts) – listens for events (like TASK_CREATED) and updates the read models (e.g., tasks table) accordingly.
- • Infrastructure Layer: In src/infrastructure (database.ts, event.emitter.ts) – handles dependencies such as database connections and event emission mechanisms.
- • Configuration/Deployment Components: Dockerfile, docker-compose.yml, .env which are used for containerization and deployment.

##### Relationships and Interactions
- Commands (write operations) trigger the Event Store to persist an event (e.g., TASK_CREATED) and then immediately use an Event Emitter to notify subscribers.
- The Projector subscribes to specific events and updates the database (read models) accordingly.
- Queries then pull data from the updated database, ensuring a clear separation from the write model.
- The server (API layer) routes incoming HTTP requests to the proper command or query handlers.
- All components communicate in an event-driven manner that underpins the CQRS model.

##### Architectural Patterns and Design Principles
- Event Sourcing: Indicate that every change is captured as an immutable event stored in a dedicated Event Store.
- Separation of Concerns: Attest to how command handling, query retrieval, event storage, and projecting changes are organized into distinct modules.

##### Relevant Technologies and Tools
- Node.js/Express (for the API/server in src/server.ts).
- TypeScript (as indicated by .ts files and tsconfig.json).
- Database integration (abstracted through src/infrastructure/database.ts, possibly using an ORM).
- Event Emitter pattern (src/infrastructure/event.emitter.ts) that notifies projectors of changes.
- Containerization (Dockerfile and docker-compose.yml) to manage deployments.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "API Layer"
        A["API/Server (Express)"]:::server
    end

    subgraph "Commands (Write Model)"
        CMD["Command Component"]:::commands
        ES["Event Store"]:::events
        EE["Event Emitter"]:::events
        PRJ["Projector Component"]:::events
        DB["Database (Read Model)"]:::infra
    end

    subgraph "Queries (Read Model)"
        Q["Query Component"]:::queries
    end

    subgraph "Configuration/Deployment"
        ENV[".env"]:::deployment
        DF["Dockerfile"]:::deployment
        DC["docker-compose.yml"]:::deployment
    end

    A -->|"command"| CMD
    CMD -->|"persist_event"| ES
    ES -->|"notify"| EE
    EE -->|"project_event"| PRJ
    PRJ -->|"update_read_model"| DB

    A -->|"query"| Q
    Q -->|"fetch_data"| DB

    A ---|"deployed_with"| ENV
    A ---|"deployed_with"| DF
    A ---|"deployed_with"| DC

    click A "https://github.com/jaimeirazabal1/event-sourcing-app/blob/main/src/server.ts"
    click CMD "https://github.com/jaimeirazabal1/event-sourcing-app/blob/main/src/commands/task.commands.ts"
    click Q "https://github.com/jaimeirazabal1/event-sourcing-app/blob/main/src/queries/task.queries.ts"
    click ES "https://github.com/jaimeirazabal1/event-sourcing-app/blob/main/src/events/event.store.ts"
    click EE "https://github.com/jaimeirazabal1/event-sourcing-app/blob/main/src/infrastructure/event.emitter.ts"
    click PRJ "https://github.com/jaimeirazabal1/event-sourcing-app/blob/main/src/projectors/task.projector.ts"
    click DB "https://github.com/jaimeirazabal1/event-sourcing-app/blob/main/src/infrastructure/database.ts"
    click ENV "https://github.com/jaimeirazabal1/event-sourcing-app/blob/main/.env"
    click DF "https://github.com/jaimeirazabal1/event-sourcing-app/tree/main/Dockerfile"
    click DC "https://github.com/jaimeirazabal1/event-sourcing-app/blob/main/docker-compose.yml"

    classDef server fill:#FFCCCC,stroke:#900,stroke-width:2px;
    classDef commands fill:#CCFFCC,stroke:#090,stroke-width:2px;
    classDef events fill:#FFFFCC,stroke:#990,stroke-width:2px;
    classDef queries fill:#CCCCFF,stroke:#009,stroke-width:2px;
    classDef infra fill:#CCE5FF,stroke:#007,stroke-width:2px;
    classDef deployment fill:#FFD700,stroke:#DAA520,stroke-width:2px;
```
