A port is an interface that defines how an application’s business logic interacts with something outside it. In hexagonal architecture, ports are contracts; adapters provide concrete implementations. This separates the application core from transport, database, and other service details. section 4.1.3 section 4.1
Direction matters. A driving port exposes actions that an external actor can request. A driven port defines a capability the application needs, such as saving an order or charging a customer. An adapter translates between its port and a specific technology. section 4.1.1 section 4.1.4
For an Order service, keep each contract focused on its role:
- APIPort exposes PlaceOrder to an incoming adapter, such as gRPC. section 4.2.4 section 4.2.1
- DBPort supplies Get and Save operations without making application logic depend on a particular database adapter. section 4.2.4
- PaymentPort supplies Charge(*domain.Order) error so placing an order can include a payment step without depending on a specific payment implementation. section 5.2.1 section 5.2.3
package ports
import "github.com/huseyinbabal/microservices/order/internal/application/core/domain"
type APIPort interface {
PlaceOrder(order domain.Order) (domain.Order, error)
}
The Go APIPort listing shows a contract expressed as one business operation, PlaceOrder, with a domain object as its argument and result. section 4.2.4
Define the interfaces in internal/ports, implement the business logic in the application, and place concrete integrations in adapters. At startup, construct the database adapter, pass it to the application, then pass the application to the gRPC adapter. An adapter can be replaced when it satisfies the same interface; tests can likewise substitute mocks for DBPort and PaymentPort to control dependent-system behavior. section 4.2.1 section 4.2.7 section 7.2.3
Do not confuse an architectural port with a network port. APPLICATION_PORT is the numbered endpoint on which the Order service runs; it configures the gRPC adapter, rather than defining an application contract. section 4.2.7


