The port is the contract
The domain declares what it needs. Infrastructure decides how to provide it.
// The domain defines the port; infrastructure implements it.
export interface OrderRepository {
save(order: Order): Promise<void>;
byId(id: OrderId): Promise<Order | null>;
}
export class PlaceOrder {
constructor(private readonly orders: OrderRepository) {}
async execute(command: PlaceOrderCommand): Promise<OrderId> {
const order = Order.place(command.customerId, command.lines);
await this.orders.save(order);
return order.id;
}
}