# bxcodec/golang-ddd-modular-monolith-with-hexagonal architecture

> Architecture diagram of the GitHub repository bxcodec/golang-ddd-modular-monolith-with-hexagonal, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal
- Repository: https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal

## Overview

This is a Go modular-monolith example with payment and payment-settings bounded contexts. The principal workflow is an HTTP request entering the REST command, reaching a module controller and service, then reading or writing PostgreSQL through a repository; payment creation also consults payment settings. A separate CLI command runs payment updates through a cron adapter. The README documents migrations and the architectural capabilities, but their runtime wiring is not shown in the sampled source, so those links are omitted. Some controller and cron-to-service calls are likewise not evidenced by the excerpts.

Main entry points: [`modules/payment/factory/factory.go`](https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment/factory/factory.go) (Payment wiring), [`cmd/rest.go`](https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/cmd/rest.go) (REST bootstrap), [`modules/payment/internal/service/service.go`](https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment/internal/service/service.go) (Payment service), [`modules/payment-settings/factory/factory.go`](https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment-settings/factory/factory.go) (Settings wiring)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application runtime"]
  node_rest_bootstrap["REST bootstrap<br/>[rest.go]"]
  node_cron_command["Update command"]
end

subgraph group_payment["Payment context"]
  node_payment_factory["Payment wiring<br/>[factory.go]"]
  node_payment_controller["Payment REST<br/>[rest.go]"]
  node_payment_service["Payment service<br/>[service.go]"]
  node_payment_domain["Payment model<br/>[payment.go]"]
  node_payment_ports["Payment ports"]
  node_payment_repository["Payment repository"]
  node_payment_cron["Payment updater<br/>[payment_updater.go]"]
end

subgraph group_settings["Settings context"]
  node_settings_factory["Settings wiring<br/>[factory.go]"]
  node_settings_controller["Settings REST<br/>[rest.go]"]
  node_settings_service["Settings service<br/>[service.go]"]
  node_settings_domain["Settings model<br/>[settings.go]"]
  node_settings_ports["Settings port"]
  node_settings_repository["Settings repository"]
end

subgraph group_shared["Shared infrastructure"]
  node_postgres[("PostgreSQL")]
  node_middleware["HTTP middleware<br/>[error_handler.go]"]
  node_migrations["Schema migrations"]
end

node_http_client(("HTTP client"))
node_cli_user(("CLI user"))

node_http_client -->|"sends HTTP"| node_rest_bootstrap
node_cli_user -->|"runs command"| node_cron_command
node_rest_bootstrap -->|"initializes"| node_settings_factory
node_rest_bootstrap -->|"initializes"| node_payment_factory
node_rest_bootstrap -->|"configures"| node_middleware
node_payment_factory -->|"constructs"| node_payment_service
node_payment_factory -->|"constructs"| node_payment_repository
node_payment_factory -->|"registers"| node_payment_controller
node_payment_factory -->|"constructs"| node_payment_cron
node_settings_factory -->|"constructs"| node_settings_service
node_settings_factory -->|"constructs"| node_settings_repository
node_settings_factory -->|"registers"| node_settings_controller
node_payment_service -->|"uses contracts"| node_payment_ports
node_payment_service -->|"calls persistence"| node_payment_repository
node_payment_service -.->|"queries settings"| node_settings_service
node_settings_service -->|"uses contract"| node_settings_ports
node_settings_service -->|"calls persistence"| node_settings_repository
node_payment_repository -->|"reads writes"| node_postgres
node_settings_repository -->|"reads writes"| node_postgres
node_migrations -.->|"defines schema"| node_postgres

click node_rest_bootstrap "https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/cmd/rest.go"
click node_cron_command "https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/cmd/cron_update_payment.go"
click node_payment_factory "https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment/factory/factory.go"
click node_payment_controller "https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment/internal/adapter/controller/rest.go"
click node_payment_service "https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment/internal/service/service.go"
click node_payment_domain "https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment/payment.go"
click node_payment_ports "https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment/internal/ports/paymentrepository.go"
click node_payment_repository "https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment/internal/adapter/repository/paymentrepository.go"
click node_payment_cron "https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment/internal/adapter/cron/payment_updater.go"
click node_settings_factory "https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment-settings/factory/factory.go"
click node_settings_controller "https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment-settings/internal/adapter/controller/rest.go"
click node_settings_service "https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment-settings/internal/service/service.go"
click node_settings_domain "https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment-settings/settings.go"
click node_settings_ports "https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment-settings/internal/ports/paymentsettingsrepository.go"
click node_settings_repository "https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment-settings/internal/adapter/repository/paymentsettingsrepository.go"
click node_middleware "https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/pkg/middlewares/error_handler.go"
click node_migrations "https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/tree/main/migrations"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_rest_bootstrap,node_cron_command,node_http_client,node_cli_user toneBlue
class node_payment_factory,node_payment_controller,node_payment_service,node_payment_domain,node_payment_ports,node_payment_repository,node_payment_cron toneAmber
class node_settings_factory,node_settings_controller,node_settings_service,node_settings_domain,node_settings_ports,node_settings_repository toneMint
class node_postgres,node_middleware,node_migrations toneRose
```

## Components

### Application runtime

- [REST bootstrap](https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/cmd/rest.go): `cmd/rest.go`
- [Update command](https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/cmd/cron_update_payment.go): `cmd/cron_update_payment.go`

### Payment context

- [Payment wiring](https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment/factory/factory.go): `modules/payment/factory/factory.go`
- [Payment REST](https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment/internal/adapter/controller/rest.go): `modules/payment/internal/adapter/controller/rest.go`
- [Payment service](https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment/internal/service/service.go): `modules/payment/internal/service/service.go`
- [Payment model](https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment/payment.go): `modules/payment/payment.go`
- [Payment ports](https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment/internal/ports/paymentrepository.go): `modules/payment/internal/ports/paymentrepository.go`
- [Payment repository](https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment/internal/adapter/repository/paymentrepository.go): `modules/payment/internal/adapter/repository/paymentrepository.go`
- [Payment updater](https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment/internal/adapter/cron/payment_updater.go): `modules/payment/internal/adapter/cron/payment_updater.go`

### Settings context

- [Settings wiring](https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment-settings/factory/factory.go): `modules/payment-settings/factory/factory.go`
- [Settings REST](https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment-settings/internal/adapter/controller/rest.go): `modules/payment-settings/internal/adapter/controller/rest.go`
- [Settings service](https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment-settings/internal/service/service.go): `modules/payment-settings/internal/service/service.go`
- [Settings model](https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment-settings/settings.go): `modules/payment-settings/settings.go`
- [Settings port](https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment-settings/internal/ports/paymentsettingsrepository.go): `modules/payment-settings/internal/ports/paymentsettingsrepository.go`
- [Settings repository](https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/modules/payment-settings/internal/adapter/repository/paymentsettingsrepository.go): `modules/payment-settings/internal/adapter/repository/paymentsettingsrepository.go`

### Shared infrastructure

- **PostgreSQL**
- [HTTP middleware](https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/blob/main/pkg/middlewares/error_handler.go): `pkg/middlewares/error_handler.go`
- [Schema migrations](https://github.com/bxcodec/golang-ddd-modular-monolith-with-hexagonal/tree/main/migrations): `migrations`

### Other components

- **HTTP client**
- **CLI user**

## Connections

- HTTP client → REST bootstrap: sends HTTP (evidence: `README.md`)
- CLI user → Update command: runs command (evidence: `README.md`)
- REST bootstrap → Settings wiring: initializes (evidence: `cmd/rest.go`)
- REST bootstrap → Payment wiring: initializes (evidence: `cmd/rest.go`)
- REST bootstrap → HTTP middleware: configures (evidence: `cmd/rest.go`)
- Payment wiring → Payment service: constructs (evidence: `modules/payment/factory/factory.go`)
- Payment wiring → Payment repository: constructs (evidence: `modules/payment/factory/factory.go`)
- Payment wiring → Payment REST: registers (evidence: `modules/payment/factory/factory.go`)
- Payment wiring → Payment updater: constructs (evidence: `modules/payment/factory/factory.go`)
- Settings wiring → Settings service: constructs (evidence: `modules/payment-settings/factory/factory.go`)
- Settings wiring → Settings repository: constructs (evidence: `modules/payment-settings/factory/factory.go`)
- Settings wiring → Settings REST: registers (evidence: `modules/payment-settings/factory/factory.go`)
- Payment service → Payment ports: uses contracts (evidence: `modules/payment/internal/service/service.go`)
- Payment service → Payment repository: calls persistence (evidence: `modules/payment/internal/service/service.go`)
- Payment service → Settings service: queries settings
- Settings service → Settings port: uses contract (evidence: `modules/payment-settings/internal/service/service.go`)
- Settings service → Settings repository: calls persistence (evidence: `modules/payment-settings/internal/service/service.go`)
- Payment repository → PostgreSQL: reads writes (evidence: `modules/payment/internal/adapter/repository/paymentrepository.go`)
- Settings repository → PostgreSQL: reads writes (evidence: `modules/payment-settings/internal/adapter/repository/paymentsettingsrepository.go`)
- Schema migrations → PostgreSQL: defines schema (evidence: `README.md`)
