liveBook · Manning

Business logic

As explained in Grokking Software Architecture

Business logic is the application code that implements domain-specific rules and coordinates the system's behavior.

Business logic is the code that carries out an application’s rules and coordinates its work. Think of it as a hospital team: each specialist has a job, but someone must coordinate the patient’s care. Mixing that coordination with the user interface or data storage makes each part harder to change independently. section 1.5.4 section 4.2.2

A favorite button

When a user clicks a favorite button, the UI handles the click and displays the heart’s state. The logic checks whether the user is logged in, tells the data component to update the status, and tells the UI to change. The data component stores the link between the user and article. section 1.5.4

Business logic has two related jobs. Domain rules govern entities such as orders and customers. Orchestration coordinates a use case: for example, load an order, validate it, and save it. section 5.3.1

In a layered architecture, business logic sits apart from presentation and data access. Hexagonal architecture protects it inside a core that has no dependencies on databases, UI, or frameworks. The core defines ports—interfaces describing what it needs or can do—and outside adapters connect technologies to those ports. Dependencies point inward. section 4.2.2 section 5.11

Keeping technical concerns outside the logic has a payoff. An order service can receive a logger through an interface: a fake logger makes unit testing easier, and a different logger can be substituted without changing the business logic. The tradeoff is a little setup complexity for the interface and constructor. section 4.5.3

Checkout under stress

If checkout logic opens network connections to a payment provider directly, testing the flow can require a live network, and switching providers can mean changing core checkout code. A dropped response can also lead to a double charge if a retry has no unique identifier. section 10.4.1

Business logic can also be split across client and server, but duplication adds complexity and leaves outdated client versions in circulation. A practical boundary is to give clients quick feedback, such as checking email format, while keeping critical rules, such as whether an email may register, on the server. section 6.2.4

How Grokking Software Architecture covers it

How deep it goes
Explains separation through layered and hexagonal designs, including ports, adapters, dependency direction, and testing tradeoffs.
Examples
Illustrates logic with a favorite button, order processing, injected logging, and checkout connected to a payment provider.
What you can do after
Evaluate application boundaries and identify coupling that makes business logic harder to test or change.
How it connects
Connects business logic to separation of concerns, dependency injection, single responsibility, and hexagonal architecture.

Also explained in

Compare how 15 books explain business logic →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.