Skip to content

Port ​

A port is an abstraction contract between the application layer and external systems. It defines capabilities required by use cases while keeping infrastructure details out of business code.

Example ​

How it works ​

C.createPort<GenericPort>() returns a port handler. Its goal is simple: force you to provide an implementation that exactly matches the GenericPort contract (parameters, returns, async, etc.).

INFO

This helper is intentionally minimal: it provides no runtime logic. Its value is in typing and composition with useCase.

Declare a contract ​

The contract of a port is generally an interface of the application layer (e.g. send, notify, publish, ...).

Once the handler is created, you can pass it as a dependency to C.createUseCase(...) and instantiate the use case with a real implementation (infrastructure layer).

Methods and Properties ​

A PortHandler<GenericPort> exposes:

Methods ​

createImplementation() ​

Returns the provided implementation, ensuring it matches the contract.

typescript
function createImplementation(
	implementation: GenericPort
): GenericPort

See also ​

Released under the MIT license.