# eyazici90/go-ddd architecture

> Architecture diagram of the GitHub repository eyazici90/go-ddd, 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/eyazici90/go-ddd
- Repository: https://github.com/eyazici90/go-ddd

## Overview

##### Project Type and Purpose
- This project is a full-stack backend application focused on DDD & CQRS for order management. It implements a practical bounded context for orders using a mediator-based command dispatcher with pipeline behaviors.
- The README confirms its purpose by listing features like command validation, context timeout (cancellation), command handling (create, pay, ship, cancel orders), and integration with observability tools (OTEL, structured logging) alongside infrastructure tooling (Docker, Kubernetes, Helm).

##### File Structure
- Key top-level directories include:
– cmd: Contains the main entry point and configuration files (e.g., main.go and config.json).
– internal: Divided into submodules:
▪ app: Houses the application layer with behaviors (pipeline logic), commands, events, and queries.
▪ domain: Contains the core business logic (domain models) for customer, order, and product, as well as domain events.
▪ http: Implements the API (HTTP routes, server, middlewares) using the Echo framework.
▪ infra: Provides persistence layer implementations (both in-memory and MongoDB stores) and event bus logic.
– pkg: Provides generic/utility packages that support shuttling errors, tracing (OTEL integration), and graceful shutdown routines.
– docs, docker, helm: Support documentation generation (Swagger docs), containerization (Dockerfile/docker-compose) and deployment (Helm charts).

##### Key Components and Their Relationships
a. API (HTTP) Layer (internal/http):
- Exposes endpoints (with integrated middleware) and handles HTTP requests.
- Integrates with Echo and serves Swagger docs for API documentation.

b. Application Layer (internal/app):
- Encapsulates business logic using commands (e.g., CreateOrder, PayOrder, ShipOrder) and queries.
- Uses the mediator pattern to dispatch commands and to include pipeline behaviors (validation, cancellation, tracing, logging, retry).
- Behaviors are applied in a sequential pipeline where order matters.

c. Domain Layer (internal/domain):
- Contains the domain models (e.g., Order, Customer, Product) and encapsulates domain logic and events.
- Follows DDD principles: aggregates, invariants, and entity versioning.

d. Infrastructure Layer (internal/infra):
- Provides support for data persistence through different implementations (in-memory and MongoDB).
- Manages the event bus and external resource integrations.

e. Supporting/Utility Packages (pkg):
- Additional components such as aggregate helpers, HTTP error handling, OTEL integration for tracing, and graceful shutdown support.

f. External & Deployment Components:
- Docker and Helm configurations support container-based deployment strategies.
- Configuration management via Viper (to be integrated as noted in future improvements).

##### Architectural Patterns & Design Principles
- DDD and CQRS: Clear separation of domain logic, command/query segregation, and bounded contexts.
- Mediator Pattern: Centralized command dispatching with a customizable pipeline for pre- and post-processing (behaviors).
- Vertical-Slice Architecture (as noted on the alternate branch): Organizing code functions around features.
- Infrastructure as Code (IAC): Docker and Helm configurations indicate containerization and Kubernetes deployment readiness.

## Diagram (Mermaid)

```mermaid
graph TD
    A["Entry & Config: cmd/go-ddd"]:::entry
    B["API Layer (Echo, Swagger)"]:::api
    C["Application Layer: Mediator & Pipeline (Validation, Cancellation, Logging, Tracing)"]:::app
    D["Domain Layer: Models & Events (Order, Customer, Product)"]:::domain
    E["Infrastructure: Persistence (In-Memory, MongoDB) & Event Bus"]:::infra
    F["Utility Components: Tracing, HTTP Errors, Shutdown, Aggregates"]:::util
    subgraph "Deployment & Configuration"
        H["Docker Deployment"]:::deploy
        I["Helm Deployment"]:::deploy
    end

    A -->|"startup"| B
    B -->|"HTTPRequest"| C
    C -->|"DispatchCommand"| D
    D -->|"EmitEvents"| E
    C -->|"Monitor"| F
    D -->|"DomainErrors"| F
    A -->|"configAccess"| H
    H -->|"deploysTo"| I
    E -->|"DataUpdate"| D

    click A "https://github.com/eyazici90/go-ddd/tree/master/cmd/go-ddd"
    click B "https://github.com/eyazici90/go-ddd/tree/master/internal/http"
    click C "https://github.com/eyazici90/go-ddd/tree/master/internal/app"
    click D "https://github.com/eyazici90/go-ddd/tree/master/internal/domain"
    click E "https://github.com/eyazici90/go-ddd/tree/master/internal/infra"
    click F "https://github.com/eyazici90/go-ddd/tree/master/pkg"
    click H "https://github.com/eyazici90/go-ddd/tree/master/docker"
    click I "https://github.com/eyazici90/go-ddd/tree/master/helm"

    classDef api fill:#f9c74f,stroke:#333,stroke-width:2px;
    classDef app fill:#90be6d,stroke:#333,stroke-width:2px;
    classDef domain fill:#f9844a,stroke:#333,stroke-width:2px;
    classDef infra fill:#43aa8b,stroke:#333,stroke-width:2px;
    classDef util fill:#577590,stroke:#fff,stroke-width:2px;
    classDef deploy fill:#277da1,stroke:#333,stroke-width:2px;
    classDef entry fill:#f3722c,stroke:#333,stroke-width:2px;
```
