# ajackti/go-ecommerce-microservices architecture

> Architecture diagram of the GitHub repository ajackti/go-ecommerce-microservices, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ajackti/go-ecommerce-microservices
- Repository: https://github.com/ajackti/go-ecommerce-microservices

## Overview

##### Main Components
- Microservices: At the core, you have distinct services such as the Catalog Read Service, Catalog Write Service, and Orders Service. Each microservice is a vertical slice encapsulating its own API endpoints (using Echo for REST and gRPC for internal calls), command & query handlers, data models, domain logic, and associated infrastructure code.
- Data Stores: Show multiple databases:
– Write-side databases: Postgres and EventStoreDB (for transactions and event sourcing).
– Read-side databases: MongoDB and Elasticsearch for NoSQL queries.
– Caching and other store components such as Redis.
- Observability/Monitoring & Logging: Identify components like OpenTelemetry (for distributed tracing, metrics collection), Prometheus with Grafana, and logging frameworks (Zap, structured logging with Uber FX).
- External Interfaces: Illustrate how clients or external systems access the application services through RESTful endpoints (Echo framework) and gRPC, along with Swagger/OpenAPI interfaces for documentation.
- Deployment and DevOps: Include Docker and docker-compose (plus Kubernetes/Helm aspects as noted) highlighting the deployment pipelines, container configurations, and CI/CD components (GitHub workflows, devcontainer setup).

##### Relationships and Data Flow
- Database Interactions: Represent how each service interacts with its underlying databases. For example, orders service writing to Postgres or EventStoreDB for audit purposes, while writing updated projections to MongoDB/Elasticsearch.
- Dependency Injection & Integration: Indicate that each service uses DI (via uber-go/fx) to resolve dependencies like logging, database connections, messaging pipelines, and HTTP/gRPC servers.

##### Underline Architectural Patterns and Design Principles
- Domain Driven Design: Make note of the domain, repository, infrastructure, and application (or service) layers that appear in each microservice slice.

##### Relevant Technologies and Components
- For the API layer: Echo (REST), swaggo/swag for documentation.
- For messaging: RabbitMQ (with its producers and consumers), and related libraries (amqp091-go).
- For storage: Postgres, MongoDB, Elasticsearch, EventStoreDB, Redis.
- For observability: OpenTelemetry (tracing and metrics), Prometheus, Grafana.
- For dependency injection: Uber Fx.
- For testing: Use mocks (via Mockery) and integration testing containers (testcontainers-go) – you might annotate these in a “development & testing tools” section.

##### Recommended Elements
- Clear Labels: Each service, database, message broker, and external system should have a distinct label.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Interfaces
    Client["Client Request"]:::external

    subgraph "External Interfaces"
        EchoAPI["Echo API (REST)"]:::api
        Swagger["Swagger/OpenAPI Docs"]:::api
        gRPC["gRPC Communication"]:::api
    end

    Client -->|"REST/gRPC_call"| EchoAPI
    Client -->|"Docs_access"| Swagger
    Client -->|"gRPC_call"| gRPC

    %% Microservices Layer
    subgraph "Microservices Layer"
        CR["Catalog Read Service"]:::service
        CW["Catalog Write Service"]:::service
        OS["Orders Service"]:::service
    end

    EchoAPI -->|"forward_call"| CR
    EchoAPI -->|"forward_call"| CW
    EchoAPI -->|"forward_call"| OS
    gRPC -->|"internal_call"| CR
    gRPC -->|"internal_call"| CW
    gRPC -->|"internal_call"| OS

    %% Messaging Infrastructure
    RMQ["RabbitMQ Messaging Bus"]:::message
    CR -.->|"subscribe_publish"| RMQ
    CW -.->|"submit_commands"| RMQ
    OS -.->|"event_sourcing"| RMQ
    RMQ -->|"event_delivery"| CR
    RMQ -->|"event_delivery"| CW
    RMQ -->|"event_delivery"| OS

    %% Write-side Databases
    subgraph "Write-side Databases"
        PG1["Postgres (gorm)"]:::db
        PG2["Postgres (pgx)"]:::db
        PG3["Postgres (sqlx)"]:::db
        ESD["EventStoreDB"]:::db
    end

    %% Read-side & Cache Databases
    subgraph "Read-side & Cache Databases"
        MDB["MongoDB"]:::db
        ES["Elasticsearch"]:::db
        RED["Redis Cache"]:::db
    end

    %% Microservice to Database Interactions
    CW -->|"writes_to"| PG1
    CW -->|"writes_to"| PG2
    CW -->|"writes_to"| PG3

    OS -->|"writes_events"| ESD
    OS -->|"writes_audit"| PG1

    CR -->|"reads_from"| MDB
    CR -->|"reads_from"| ES
    CR -->|"cache_lookup"| RED

    OS -->|"reads_projections"| MDB
    OS -->|"searches"| ES

    %% Observability & Monitoring
    subgraph "Observability & Monitoring"
        OT["OpenTelemetry"]:::obs
        PROM["Prometheus"]:::obs
        GRAF["Grafana"]:::obs
    end

    CR -->|"traces_metrics"| OT
    CW -->|"traces_metrics"| OT
    OS -->|"traces_metrics"| OT

    CR -->|"monitors"| PROM
    CW -->|"monitors"| PROM
    OS -->|"monitors"| PROM

    CR -->|"dashboards"| GRAF
    CW -->|"dashboards"| GRAF
    OS -->|"dashboards"| GRAF

    %% Deployment & DevOps
    subgraph "Deployment & DevOps"
        DOCKER["Docker & docker-compose"]:::devops
        DEVCONT["Devcontainer"]:::devops
        K8S["Kubernetes/Helm"]:::devops
        KUSTOMIZE["Kustomize"]:::devops
    end

    CR -->|"deployed_via"| DOCKER
    CW -->|"deployed_via"| DOCKER
    OS -->|"deployed_via"| DOCKER

    %% Styling Classes
    classDef external fill:#f9f,stroke:#333,stroke-width:2px;
    classDef api fill:#bbf,stroke:#333,stroke-width:2px;
    classDef service fill:#ff9,stroke:#333,stroke-width:2px;
    classDef message fill:#cfc,stroke:#333,stroke-width:2px;
    classDef db fill:#fcf,stroke:#333,stroke-width:2px;
    classDef obs fill:#cff,stroke:#333,stroke-width:2px;
    classDef devops fill:#ffc,stroke:#333,stroke-width:2px;

    %% Click Events
    click CR "https://github.com/ajackti/go-ecommerce-microservices/tree/main/internal/services/catalogreadservice"
    click CW "https://github.com/ajackti/go-ecommerce-microservices/tree/main/internal/services/catalogwriteservice"
    click OS "https://github.com/ajackti/go-ecommerce-microservices/tree/main/internal/services/orderservice"
    click RMQ "https://github.com/ajackti/go-ecommerce-microservices/tree/main/internal/pkg/rabbitmq"
    click PG1 "https://github.com/ajackti/go-ecommerce-microservices/tree/main/internal/pkg/postgresgorm"
    click PG2 "https://github.com/ajackti/go-ecommerce-microservices/tree/main/internal/pkg/postgrespgx"
    click PG3 "https://github.com/ajackti/go-ecommerce-microservices/tree/main/internal/pkg/postgressqlx"
    click ESD "https://github.com/ajackti/go-ecommerce-microservices/tree/main/internal/pkg/eventstroredb"
    click MDB "https://github.com/ajackti/go-ecommerce-microservices/tree/main/internal/pkg/mongodb"
    click ES "https://github.com/ajackti/go-ecommerce-microservices/tree/main/internal/pkg/elasticsearch"
    click RED "https://github.com/ajackti/go-ecommerce-microservices/tree/main/internal/pkg/redis"
    click EchoAPI "https://github.com/ajackti/go-ecommerce-microservices/tree/main/internal/pkg/http/customecho"
    click Swagger "https://github.com/ajackti/go-ecommerce-microservices/tree/main/api/openapi"
    click gRPC "https://github.com/ajackti/go-ecommerce-microservices/tree/main/internal/pkg/grpc"
    click OT "https://github.com/ajackti/go-ecommerce-microservices/tree/main/internal/pkg/otel"
    click GRAF "https://github.com/ajackti/go-ecommerce-microservices/blob/main/deployments/docker-compose/monitoring/grafana.yaml"
    click PROM "https://github.com/ajackti/go-ecommerce-microservices/blob/main/deployments/docker-compose/monitoring/prometheus.yml"
    click DOCKER "https://github.com/ajackti/go-ecommerce-microservices/tree/main/deployments/docker-compose"
    click DEVCONT "https://github.com/ajackti/go-ecommerce-microservices/blob/main/.devcontainer"
    click K8S "https://github.com/ajackti/go-ecommerce-microservices/tree/main/deployments/kubernetes"
    click KUSTOMIZE "https://github.com/ajackti/go-ecommerce-microservices/tree/main/deployments/kustomize"
```
