Rule: A conditional inference: HEAD :- BODY means "HEAD holds if BODY holds". grandparent(X, Z) :- parent(X, Y), parent(Y, Z). In logic programming, a rule states that something is true if certain conditions hold. In Prolog, grandparent(X, Z) :- parent(X, Y), parent(Y, Z). means X is a grandparent of Z if X is a parent of some Y who is a parent of Z.
Rules let the system derive new facts from existing ones. You describe relationships once, and the engine can answer many different questions with them.
What should you keep in mind with Rule?
Business software is full of rules: discounts, permissions, shipping costs, eligibility. When those rules grow into deeply nested if statements, expressing them more declaratively helps. That can be a rules table in the database, a small rules engine, or simply a set of clearly named functions, one per rule, so each can be read and tested separately.
Implement proven backend architecture patterns including Clean Architecture, Hexagonal Architecture, and Domain-Driven Design. Use this skill when designing clean architecture for a new microservice, when refactoring a monolith to use bounded contexts, when implementing hexagonal or onion architecture patterns, or when debugging dependency cycles between application layers.