Hanzo
CommerceCommerce Modules

Commerce Modules

Core modules that power Hanzo Commerce

Hanzo Commerce is composed of independent, composable modules. Each module owns a specific domain and exposes both a Go service API and REST endpoints.

Module Map

Module Structure

Every module follows the same internal pattern:

// module.go -- registration
type ProductModule struct {
    service    *ProductService
    repository *ProductRepository
    handler    *ProductHandler
}

func NewProductModule(db *sql.DB, bus events.Bus) *ProductModule {
    repo := NewProductRepository(db)
    svc  := NewProductService(repo, bus)
    h    := NewProductHandler(svc)
    return &ProductModule{service: svc, repository: repo, handler: h}
}

func (m *ProductModule) RegisterRoutes(r chi.Router) {
    r.Route("/product", func(r chi.Router) {
        r.Get("/", m.handler.List)
        r.Post("/", m.handler.Create)
        r.Get("/{id}", m.handler.Get)
        r.Patch("/{id}", m.handler.Update)
        r.Delete("/{id}", m.handler.Delete)
    })
}

Events

Modules communicate through domain events:

EventProducerConsumers
product.createdProductSearch, Analytics
order.confirmedOrderInventory, Fulfillment, Analytics
payment.capturedPaymentOrder, Analytics
inventory.lowInventoryNotification
cart.abandonedCartAnalytics, Notification

Configuration

Enable or disable modules in your commerce.yml:

modules:
  product: true
  order: true
  cart: true
  payment: true
  customer: true
  fulfillment: true
  inventory: true
  pricing: true
  promotion: true
  tax: true
  region: true
  analytics: true
  subscription: false  # opt-in

How is this guide?

Last updated on

On this page