Usually, when I create a domain entity (for example a bank account) it includes things like account id and starting balance.
But I have seen some Hexagonal projects that also have functions like calculateBalance or createAccount.
I usually put these functions it ports though.
My question is, what are the rules for deciding where to put the domain specific functions between the ports and domain entities?
As a rule of thumb, domain entities should contain domain-specific functions that operate on properties or make calculations based on properties without the need for external data to be involved in decision making, for example:
If, on the other hand, you want to make business decisions based on external data, you should create that logical unit as a function inside a service ("domain service") and have your port call this function. For example: