# levinhne/event-driven-architecture-in-golang architecture

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

- Interactive diagram: https://gitdiagram.com/levinhne/event-driven-architecture-in-golang
- Repository: https://github.com/levinhne/event-driven-architecture-in-golang

## Overview

##### Main Components
- Common Infrastructure/Shared Libraries: Include components representing shared directories (internal/ddd, internal/es for event sourcing, internal/logger, internal/registry, etc.) which underlie multiple bounded contexts.
- API Gateway & Communication Interfaces: Show how gRPC and REST “gateways” and associated protobuf definitions (look for files in “*.pb.go”, “*.proto”, and “api.swagger.json” or OpenAPI files) are used to expose services.
- Deployment & Containerization: Represent the docker-compose, Dockerfiles, and database initialization scripts. Use a component to denote the containerized environment or the underlying Postgres databases (as suggested by the docker/database folder).
- Command-Line Entrypoints: Mark the “cmd/mallbots” (and possibly other entry points) as the actual application launch points which bind these modules together.

##### Relationships and Interactions
- Communication Paths: Within each module, illustrate the flow from incoming requests (via REST or gRPC) through application services (commands, queries, event handlers) to the domain layer, and further down to the repository/persistence layer (e.g., postgres integrations).
- Shared Infrastructure: Identify and show how common components (DDD foundations, event sourcing mechanisms, logging and monitoring) connect to each module.

##### Architectural Patterns & Design Principles
- Modular Monolith Architecture: The project is structured using modular monolith principles. Each domain is self-contained with its own internal layers, yet they all run within an integrated system.
- Domain-Driven Design (DDD): Stress the presence of Aggregates, Domain Events, Repositories, and Application Services (as seen in the internal application and domain folders).
- Event Sourcing Elements: Components under internal/es and the presence of snapshot and event stores indicate an event-driven design.
- API Layer Separation: There is a clear separation between REST and gRPC interfaces, which suggests adherence to a separation of concerns principle in the communication layer.

##### Technologies, Frameworks, and Tools
- Go: The entire codebase is implemented in Go.
- Protobuf/gRPC: Used extensively for API definitions and service communication.
- Docker & Docker-Compose: For containerizing the system and setting up Postgres databases.
- PostgreSQL: Evidenced by database initialization scripts that create and load various schemas.
- Swagger/OpenAPI: For REST API documentation.
- Internal Libraries: Custom DDD, event sourcing, logging, and registry libraries that underpin the business logic.

##### Elements to be Included
- Each Bounded Context: Clearly drawn with subgroupings (API layer, application logic, domain layer, persistence layer).
- Technology Annotations: Next to each component include technology or protocol labels (e.g., “gRPC”, “REST”, “Postgres”).
- Shared Infrastructure Layer: A common layer that includes event sourcing, logging, and DDD support libraries.

– Clearly decomposes the project into its major bounded contexts (baskets, customers, depot, notifications, ordering, payments, stores).
– Demonstrates the layered architecture (API, application, domain, persistence) within each context.
– Clearly annotates the protocol/technology used by each component (gRPC, REST, protobuf, Docker, PostgreSQL).

## Diagram (Mermaid)

```mermaid
flowchart TD
    CMD["Mallbots Entrypoint"]:::cmd

    subgraph "Bounded Context: Baskets"
        BMODULE["Baskets Module"]:::module
        BAPI["API Layer (gRPC/REST)"]:::api
        BAPP["Application Layer"]:::app
        BDOM["Domain Layer"]:::domain
        BPERS["Persistence (Postgres)"]:::db
        BMODULE --> BAPI
        BAPI --> BAPP
        BAPP --> BDOM
        BDOM --> BPERS
    end

    subgraph "Bounded Context: Customers"
        CMODULE["Customers Module"]:::module
        CAPI["API Layer (gRPC/REST)"]:::api
        CAPP["Application Layer"]:::app
        CDOM["Domain Layer"]:::domain
        CPERS["Persistence (Postgres)"]:::db
        CMODULE --> CAPI
        CAPI --> CAPP
        CAPP --> CDOM
        CDOM --> CPERS
    end

    subgraph "Bounded Context: Depot"
        DMODULE["Depot Module"]:::module
        DAPI["API Layer (gRPC/REST)"]:::api
        DAPP["Application Layer"]:::app
        DDOM["Domain Layer"]:::domain
        DPERS["Persistence (Postgres)"]:::db
        DMODULE --> DAPI
        DAPI --> DAPP
        DAPP --> DDOM
        DDOM --> DPERS
    end

    subgraph "Bounded Context: Notifications"
        NMODULE["Notifications Module"]:::module
        NAPI["API Layer (gRPC/REST)"]:::api
        NAPP["Application Layer"]:::app
        NDOM["Domain Layer"]:::domain
        NPERS["Persistence (Postgres)"]:::db
        NMODULE --> NAPI
        NAPI --> NAPP
        NAPP --> NDOM
        NDOM --> NPERS
    end

    subgraph "Bounded Context: Ordering"
        OMODULE["Ordering Module"]:::module
        OAPI["API Layer (gRPC/REST)"]:::api
        OAPP["Application Layer"]:::app
        ODOM["Domain Layer"]:::domain
        OPERS["Persistence (Postgres)"]:::db
        OMODULE --> OAPI
        OAPI --> OAPP
        OAPP --> ODOM
        ODOM --> OPERS
    end

    subgraph "Bounded Context: Payments"
        PMODULE["Payments Module"]:::module
        PAPI["API Layer (gRPC/REST)"]:::api
        PAPP["Application Layer"]:::app
        PDOM["Domain Layer"]:::domain
        PPERS["Persistence (Postgres)"]:::db
        PMODULE --> PAPI
        PAPI --> PAPP
        PAPP --> PDOM
        PDOM --> PPERS
    end

    subgraph "Bounded Context: Stores"
        SMODULE["Stores Module"]:::module
        SAPI["API Layer (gRPC/REST)"]:::api
        SAPP["Application Layer"]:::app
        SDOM["Domain Layer"]:::domain
        SPERS["Persistence (Postgres)"]:::db
        SMODULE --> SAPI
        SAPI --> SAPP
        SAPP --> SDOM
        SDOM --> SPERS
    end

    %% Inter-service communication (Ordering calls Baskets, Customers, Payments synchronously)
    OMODULE -->|"sync"| BMODULE
    OMODULE -->|"sync"| CMODULE
    OMODULE -->|"sync"| PMODULE

    %% Entrypoint connections to each module
    CMD --> BMODULE
    CMD --> CMODULE
    CMD --> DMODULE
    CMD --> NMODULE
    CMD --> OMODULE
    CMD --> PMODULE
    CMD --> SMODULE

    %% Shared Infrastructure Subgraph
    subgraph "Shared Infrastructure"
        SHARED_COMMON["Shared Infrastructure"]:::shared
        DDD["DDD Infrastructure"]:::shared
        ES["Event Sourcing"]:::shared
        LOGGER["Logging Infrastructure"]:::shared
        REGISTRY["Registry & Serialization"]:::shared
        SHARED_COMMON --> DDD
        SHARED_COMMON --> ES
        SHARED_COMMON --> LOGGER
        SHARED_COMMON --> REGISTRY
    end

    %% Each bounded context uses shared infrastructure
    BMODULE --> SHARED_COMMON
    CMODULE --> SHARED_COMMON
    DMODULE --> SHARED_COMMON
    NMODULE --> SHARED_COMMON
    OMODULE --> SHARED_COMMON
    PMODULE --> SHARED_COMMON
    SMODULE --> SHARED_COMMON

    %% Deployment & Containerization Subgraph
    subgraph "Deployment"
        DOCKER["Docker & Containerization"]:::container
        DB["PostgreSQL Database"]:::db
        DOCKER -->|"configures"| DB
    end

    %% Styles
    classDef module fill:#f9e79f,stroke:#8e44ad,stroke-width:2px;
    classDef api fill:#aed6f1,stroke:#2471a3,stroke-width:2px;
    classDef app fill:#abebc6,stroke:#1e8449,stroke-width:2px;
    classDef domain fill:#f9e79f,stroke:#d35400,stroke-width:2px;
    classDef db fill:#fadbd8,stroke:#cb4335,stroke-width:2px;
    classDef shared fill:#d5f5e3,stroke:#27ae60,stroke-width:2px;
    classDef container fill:#f5b7b1,stroke:#c0392b,stroke-width:2px;
    classDef cmd fill:#ecf0f1,stroke:#7f8c8d,stroke-width:2px;

    %% Click Events for Component Mapping
    click BMODULE "https://github.com/levinhne/event-driven-architecture-in-golang/blob/master/baskets/module.go"
    click CMODULE "https://github.com/levinhne/event-driven-architecture-in-golang/blob/master/customers/module.go"
    click DMODULE "https://github.com/levinhne/event-driven-architecture-in-golang/blob/master/depot/module.go"
    click NMODULE "https://github.com/levinhne/event-driven-architecture-in-golang/blob/master/notifications/module.go"
    click OMODULE "https://github.com/levinhne/event-driven-architecture-in-golang/blob/master/ordering/module.go"
    click PMODULE "https://github.com/levinhne/event-driven-architecture-in-golang/blob/master/payments/module.go"
    click SMODULE "https://github.com/levinhne/event-driven-architecture-in-golang/blob/master/stores/module.go"
    click DDD "https://github.com/levinhne/event-driven-architecture-in-golang/tree/master/internal/ddd/"
    click ES "https://github.com/levinhne/event-driven-architecture-in-golang/tree/master/internal/es/"
    click LOGGER "https://github.com/levinhne/event-driven-architecture-in-golang/blob/master/internal/logger/logger.go"
    click REGISTRY "https://github.com/levinhne/event-driven-architecture-in-golang/tree/master/internal/registry/"
    click DOCKER "https://github.com/levinhne/event-driven-architecture-in-golang/tree/master/docker/"
    click CMD "https://github.com/levinhne/event-driven-architecture-in-golang/tree/master/cmd/mallbots/"
```
