Appearance
A framework runs your code and trusts it. TypeRule understands the whole model: the data, the states, the rules and the automations. So it can tell you when the logic is wrong, not only the syntax, before a single record is saved.
Business systems break in the same places: amounts in the wrong currency, state machines with dead ends, automations that set off other automations, and nobody able to say why a number is what it is. Here is what TypeRule does about each of them. The messages on this page come from the TypeRule tools.
A general-purpose framework makes you spell out how: tables, migrations, serializers, validation, status checks, locking, audit tables. TypeRule is made for one job, so you write only what: the data, the rules and the flow. The whole order system on the home page is 39 lines.
On the right, shipping an order: first in TypeRule, then in a typical web framework.
The framework version is not badly written. It has to say everything: lock the rows, check the status, check the stock, write the audit log by hand, save each field. Every one of those lines is a place where a bug can hide, and every reviewer has to read them all.
In TypeRule the flow says when ship may run, the type of stock says it can't go below zero, the transaction and the history come with every action. What is left is the business.
stock: Int where >= 0
state: enum(Draft, Confirmed, Shipped) default Draft
flow state:
Confirmed -> Shipped by ship
action ship:
for l in lines:
l.product.stock = l.product.stock - l.qtyclass Order(models.Model):
class State(models.TextChoices):
DRAFT = "draft"
CONFIRMED = "confirmed"
SHIPPED = "shipped"
state = models.CharField(max_length=20, choices=State.choices, default=State.DRAFT)
def ship(self, user):
with transaction.atomic():
order = Order.objects.select_for_update().get(pk=self.pk)
if order.state != Order.State.CONFIRMED:
raise ValidationError(f"Cannot ship an order in state {order.state}")
for line in order.lines.select_related("product").select_for_update():
product = line.product
if line.qty > product.stock:
raise ValidationError("Not enough stock")
old = product.stock
product.stock -= line.qty
product.save(update_fields=["stock"])
AuditLog.objects.create(user=user, record=product, field="stock",
old=old, new=product.stock, cause=f"order {order.pk} shipped")
order.state = Order.State.SHIPPED
order.save(update_fields=["state"])
AuditLog.objects.create(user=user, record=order, field="state",
old="confirmed", new="shipped", cause="ship")Still to write: the permission check, the API endpoint, the form, the migration, and the audit table itself. And nothing stops another piece of code from writing state = "shipped".
Short code is not a trick of syntax. It is short because the language knows what an order, an amount, a state and a history are, so it builds the rest from the model, the same way every time.
Less code also means less for an AI assistant to write, and less for you to check after it.
| Framework + ORM + SQL | TypeRule | |
|---|---|---|
| Schema | migrations, ORM classes, API serializers, forms, kept in sync by hand | one model: tables, API and screens are derived |
| Derived values | computed in code, cached, sometimes stale | formulas, always current |
| Money and units | decimals, currency in another column | Money<EUR>, Qty<kg>, checked by the compiler |
| Validation | in the controller, the form or a trigger, often only one of them | check, where: on every write, from any entry point |
| Status changes | if order.status == … scattered in the code | flow + action: only the declared transitions exist |
| Audit | a table someone remembers to write to | every value has a history and a cause |
| Permissions | middleware and filters per endpoint | role rules, applied everywhere |
These mistakes are shown in the editor as you type, on every save in typerule dev, by typerule check and before every deploy. Nothing runs until they are fixed.
In a framework a price is a decimal: nothing stops you from adding euros to dollars, or kilos to pieces, and the mistake surfaces in a report weeks later.
In TypeRule, Money<EUR>, Qty<kg> and Price<EUR, kg> are types. Adding two currencies, comparing an amount with a plain number or forgetting to round is an error at its line.
entity Product:
price: Money<EUR>
list_usd: Money<USD>
total_price = price + list_usderror: cannot add Money<EUR> and Money<USD> │ │ total_price = price + list_usd │ ^^^^^^^^^^^^^^^^
ERP state machines grow one status at a time. A status gets added, nothing ever leads to it, and it sits in every dropdown and every report for years.
In TypeRule a flow is declared, not coded, so the compiler can see all of it: a state that no transition can reach is flagged.
entity Order:
state: enum(Draft, Confirmed, Shipped, Cancelled) default Draft
flow state:
Draft -> Confirmed by confirm
Confirmed -> Shipped by shipwarning: state `Cancelled` of `Order.state` can never be reached
In most systems the status is just a column, and any piece of code can write status = 'shipped', skipping the checks that shipping should run.
In TypeRule a state changes only through the actions of its flow. Writing the field directly is an error, wherever it is written.
action ship:
for l in lines:
l.product.stock = l.product.stock - l.qty
state = Drafterror: `Order.state` changes only through its flow: run one of its actions (confirm, ship)
Add a state to an order, and somewhere a label, a total or a permission still only knows the old ones.
A match on a state must cover every state. Add one, and every place that forgot it is listed.
label: Text = match state:
Draft => "to confirm"
Confirmed => "to ship"error: non-exhaustive match: missing Shipped
The real trouble in an ERP is often not one rule, but rules that set off other rules: a stock change triggers a reorder, which changes the stock again, and so on.
TypeRule knows what every automation writes and what its condition reads. One that can trigger itself again is refused, until you declare that it converges. At run time, automations that keep changing each other stop the transaction after 20 rounds, and nothing is saved.
on Product becomes stock < 5 as p:
p.stock = p.stock + 1error: `on Product becomes stock < 5` can trigger itself again: it writes `Product.stock`, which its condition reads. If each run brings the condition back to false, declare it `converges` (`as p converges:`)
A discount that depends on the total, which depends on the discount: in a spreadsheet it is a circular reference warning that people learn to ignore.
TypeRule finds the cycle, names every step of it and says how to break it.
revenue = lines.sum(l => l.amount) + discount
discount = revenue * 0.1error: formula cycle: Order.discount → Order.revenue → Order.discount (break it with a `default` snapshot, or make one value stored)
Rules live in the model, not in a form or a controller. So they hold no matter where a change comes from.
An order can't be shipped before it is confirmed: not from the app, not from the API, not from an automation. Each action runs only in the states its flow allows.
let o = Order(customer=anna, lines=[OrderLine(product=pump, qty=2)])
o.ship()Order.ship is not allowed in state DraftEvery action runs in one transaction, together with everything it sets off. If one rule fails, all of it is undone: no half-confirmed orders, no stock moved for a shipment that didn't happen.
test "an order below cost is not confirmed":
let pump = Product(name="Pump", cost=20.00 EUR, price=15.00 EUR, stock=10)
let o = Order(customer=anna, lines=[OrderLine(product=pump, qty=2)])
expect_error "Below cost":
o.confirm()
expect o.state is Draft$ typerule test ✓ an order below cost is not confirmed 1 passed, 0 failed
Once an order is confirmed, it is a fact. frozen when makes it read-only, and its formulas keep seeing the world as it was that day: tomorrow's price list doesn't change yesterday's order. Corrections go through actions, so they leave a trace.
entity Order:
state: enum(Draft, Confirmed, Shipped) default Draft
frozen when state is not DraftOrder is frozen (state is not Draft): `date` cannot change
Nothing in the history is ever overwritten. So any number can be explained, and any change can be checked or taken back.
Every write records its cause: the user, the action, the automation, the API request or the migration, and the chain that led to it. why() tells the story of any record.
why(pump)Product Pump created because Product.stock changed by Order.ship (anna, 2026-11-25 09:00)
Before you change a field, see everything a number is made of, and who writes each piece underneath. typerule trace answers it for any value.
$ typerule trace Order.margin Order.margin formula · main.tr:18 = lines.sum(l => l.margin) Depends on Order.lines stored OrderLine.margin = (product.price - product.cost) * qty OrderLine.product stored OrderLine.qty stored · default 1 Product.cost stored Product.price stored Stored values underneath, and who writes them Product.cost user, through forms and API
Every value written to every field is kept, in order, in a log chained by hashes. Editing a table by hand, or altering the history, is detected.
$ typerule db verify ✓ hash chain intact, tables match the history (26 records)
A change to many records at once is written in TypeRule, with a reason and an approval. It runs first as a preview on the real data, checking every rule, and it can be reverted with one command.
$ typerule change preview raise_prices raise_prices: Price list 2027: +10% approval: a Manager ~ Product#24.list_price: 1.00 EUR → 1.10 EUR ~ Product#25.list_price: 2.50 EUR → 2.75 EUR ✓ preview: constraints and expectations hold; nothing written $ typerule change revert raise_prices --approved-by lucia
Break a rule on purpose in the sandbox, and watch TypeRule catch it.
Open the Sandbox runs in your browser