You keep the rules, the AI keeps the rest
Keeping the business rules apart from the rest of the code was never a technical problem. It was a discipline problem.
You had to plan for it. Domain-Driven Design helped, because it gave the rules somewhere to belong. And you needed buy-in from the developers, all of them, on every change. That was the hard part. The buy-in was real, and it lasted until the first deadline. Then somebody put an if statement in a service, just this once, and it’s still there.
With AI this gets a lot easier. Not because the AI knows better than we did. It just does what you ask, every time, including on a Friday afternoon.
Left alone, the AI buries them too
Section titled “Left alone, the AI buries them too”I took a small order service, with no rulii and no instructions, and asked Claude Code for one thing: add free shipping for gold customers on orders of 100 or more. This is what it changed:
@Componentpublic class ShippingRates {
private static final BigDecimal FLAT_RATE = new BigDecimal("9.95"); private static final BigDecimal GOLD_FREE_SHIPPING_MINIMUM = new BigDecimal("100");
public BigDecimal quote(Order order, Customer customer) { if (customer.getTier() == Tier.GOLD && order.getTotal().compareTo(GOLD_FREE_SHIPPING_MINIMUM) >= 0) { return BigDecimal.ZERO; } return FLAT_RATE; }}It works, and it wrote the tests to prove it. It’s also exactly what we used to do, which isn’t a surprise. It learned from us.
The rule is now one condition inside the class that quotes shipping rates. That’s a perfectly reasonable place for it, which is the problem. The next rule will go somewhere just as reasonable, and somewhere else. The only real difference is the speed. What took a team a few years now takes an afternoon.
Ask for the rules to be kept apart
Section titled “Ask for the rules to be kept apart”The fix is an instruction, written once, in the file your assistant reads before every task. For Claude Code that’s CLAUDE.md:
## Business rules
- A business rule is a rulii rule: one rule per class, in `com.acme.orders.rules`.- Every rule has a name, a description in plain English and a category.- Services don't decide anything. They run a rule set and act on the result.- Every rule gets a test of its own.That’s the buy-in. It used to take a workshop.
I added rulii to the build, copied in the skills (they’re next), put those four lines in, and asked for the same feature in the same words. This time the decision came back on its own:
@Rule("GoldFreeShippingRule")@Description("Gold customers get free shipping on orders of 100 or more.")@Category("Shipping")public class GoldFreeShippingRule {
private static final BigDecimal MINIMUM_TOTAL = new BigDecimal("100");
@Given public boolean when(Customer customer, Order order) { return customer.getTier() == Tier.GOLD && order.getTotal().compareTo(MINIMUM_TOTAL) >= 0; }
@Then public void then(Order order) { order.setShipping(BigDecimal.ZERO); }}With it came a shippingRules rule set, and a service that’s back to being plumbing. I’ve shortened the call it wrote to rulii’s one-line form:
public Order place(OrderRequest request) { Customer buyer = customers.find(request.getCustomerId()); Order newOrder = Order.from(request); newOrder.setShipping(rates.quote(newOrder));
shippingRules.run(customer -> buyer, order -> newOrder);
return orders.save(newOrder);}It no longer knows what a gold customer is, or what the threshold is. It asks.
I also tried it with rulii in the build and no instruction at all. It wrote a rule anyway, because the library was sitting there unused, and it said so. But that rule had no category, wasn’t in a rule set and had no test of its own. The assistant will take a hint. The instruction is what got the rest.
The skills are already written
Section titled “The skills are already written”You don’t have to teach your assistant rulii. The repositories ship with Claude Code skills that do it:
| Skill | What it covers |
|---|---|
/new-rule |
A rule as a class or a lambda: conditions, actions, otherwise, pre-conditions |
/new-ruleset |
Rule sets: ordering, lifecycle hooks, stop conditions, validating mode |
/new-ruleflow |
Rule flows: steps, decisions, loops, async, exception handling |
/new-validation-rule |
A custom validation rule and its builder |
/new-xml-ruleset |
Rules, rule sets and validators in Spring XML |
/new-xml-ruleflow |
Rule flows in Spring XML |
/write-test |
Tests for PASS, FAIL and SKIP, with and without Spring |
/debug-rule |
Why a rule didn’t fire, or fired when it shouldn’t have |
The first four, with the test and debug skills, are in rulii. rulii-spring has its own versions that know about Spring wiring, plus the two XML ones. If you’re on Spring Boot, take the rulii-spring set and add /new-ruleflow from rulii.
Copy them into your project and Claude Code finds them on its own:
cp -r <path-to-rulii-spring>/.claude/skills/* .claude/skills/cp -r <path-to-rulii>/.claude/skills/new-ruleflow .claude/skills/Each one is a Markdown file, so an assistant that isn’t Claude can be pointed at it too. The documentation is also published as plain text for assistants, at rulii.org/llms.txt.
Small enough to read
Section titled “Small enough to read”An assistant produces a lot of code, and nobody reads all of it the way they’d read their own. A rule is different. It’s a name, a sentence and a few lines, so you can follow along.
The session tested the rule five ways, including at exactly 100 and at 99.99. It started the whole application to do it, which it didn’t need to. A rule runs on its own:
@Testvoid goldCustomerOverTheThresholdShipsFree() { Rule rule = Rule.builder().build(GoldFreeShippingRule.class); Customer gold = new Customer("C-200", Tier.GOLD); Order placed = new Order("C-200", new BigDecimal("120.00")); placed.setShipping(new BigDecimal("9.95"));
RuleResult result = rule.run(customer -> gold, order -> placed);
assertEquals(RuleExecutionStatus.PASS, result.status()); assertEquals(BigDecimal.ZERO, placed.getShipping());}No Spring context, no database and no mocks. If the assistant gets a rule wrong, this is where you’ll see it, and it’s a dozen lines.
The explorer shows you all of them
Section titled “The explorer shows you all of them”Reading one rule is easy. Knowing what all of them are, after six months of an assistant adding them, is the other half.
That’s what the explorer is for. It’s a read-only viewer for the rules of a running application. Add the starter to a Spring Boot application:
<dependency> <groupId>org.rulii</groupId> <artifactId>rulii-explorer-spring-boot-starter</artifactId> <version>1.1.0</version></dependency>It’s off until you switch it on, so production never shows its rules by accident:
rulii.explorer.enabled=truemanagement.endpoints.web.exposure.include=health,ruliiThen open /rulii.
Every rule, rule set and flow gets a page: what it’s for, what it reads and writes, which rule sets and flows run it, and the file and line it lives on. Rules written as expressions or in XML are read out in plain English. A rule that’s a compiled class shows its description and its signature, which is why the instruction above asks for a description on every one.
It also has a Problems page, and the list could have been written with an assistant in mind: a rule nothing runs, a step that runs something that isn’t registered, duplicate names, missing descriptions. Those are the mistakes you make when you’re moving quickly, and an assistant is always moving quickly.
The same information can be written to a JSON file at build time and compared between releases. So when the assistant tells you it only tidied up the service, you can check whether a rule changed.
Who maintains what
Section titled “Who maintains what”You keep the rules and the AI keeps the rest. That’s the split I’d aim for.
The controllers, the mappers, the repositories and the configuration are the AI’s to maintain. You review them the way you review any code, but there’s rarely anything in them the business would care about.
The rules are yours. When the business changes its mind, and it will, the change is one rule. You can ask the AI to make it, and what you read afterwards is a diff of five lines with a name on it.
I said on the Why page that AI helped me polish, test and document rulii, and that the thinking was already done. It’s the same here. Knowing what the rules are is the hard part, and that’s still your job.
Try it
Section titled “Try it”You don’t have to take my word for any of this. The order service I started from is in rulii-samples, with the four lines and the skills already in place. Clone it, type the same request and see what your assistant does.
Or start with Installation, add the four lines to your own CLAUDE.md, and see where the next rule ends up.