Files
2026-11-14 19:16:24 +05:00

2.3 KiB

Deliveries

Deliveries are a concept of clean architecture that is responsible for network API interaction. It consists of:

  • Handling structure.
  • Interface that describes API requirements for domain's service structure.

Deliveries should be placed in delivery/DELIVERY_TYPE directory within domain, like internal/domains/core/config/delivery/http_external for configuration-related HTTP API that is accessible to external clients.

Handling structure

Delivery's handling structure is similar to domain's one:

  • It initializes with Initialize(app *application.Application, dmn domain) error function.
  • It should have own logger (see Logging).
  • It should not be exported (private structure).

And that's it:

  • It SHOULD NOT register itself with Application singleton as domain.
  • It CANNOT have or use storages.
  • It CANNOT have models or DTOs, delivery should re-use domain's models.
  • If application's client isn't present - API data structure should be in same file with handler function and unexported.
  • It SHOULD NOT conform to Domain interface (e.g. Configure(), ConnectDependencies() and other interface's functions shouldn't be present).
  • It should use only own domain and CANNOT use others.
    • With notable exception of HTTP server's handlers registration.
  • It should specify own domain contract as unexported interface named domain in same-named file.

Yet it should receive *application.Application on initialization like a regular domain to obtain logger.

Domain itself should be passed to delivery as second parameter and initializer should receive it as own domain's service interface (see below).

API handlers

API handlers registration should happen in (h *handler) registerHandlers() error function.

Domain's service interface

Delivery should have own domain interface that is different from inter-domain API and is described in domain.go file in delivery's package.

Models, schemas

As delivery is actually a part of domain, working internally with domain's models is allowed, but responses should always use different structures (delivery schemas or application's client schemas).

Delivery schemas are request and response structures that are placed in same file with request handling function. They should be unexported so they do not pollute IDE's autocompletion.