Appearance
Next steps
Open the finished shop runs in your browserYou've built a small but complete business application: a catalog with prices per unit, customers with credit limits, orders with a life cycle, invoices and payments that follow them, stock and receivables in ledgers, permissions for each role, a database with a verified history, an API, the tools to evolve all of it safely, and the connections to the web shop, the carrier, the till, the bank and the accountant, the invoices and labels it prints, and the data of people it keeps only as long as it should.
Here is where to go from here.
Read a bigger model
The repository's examples/extended folder is a full ERP written in TypeRule — partners, products and price lists, multi-currency sales and purchasing, deliveries and receipts with lots, manufacturing with multi-level bills of materials, double-entry accounting with a general ledger, exchange differences, reorder planning, certified metrics and audit controls. You can open it in the Sandbox. Things to look for, now that you know the basics:
- Multi-currency:
Money<order.currency>andMoney<company.currency>,convert(…),exchange_rate(…), and how the compiler proves that two amounts are in the same currency (filters likewhere(g => g.company == company)count as proofs). per companyfields: a value per company, in that company's currency (list_price: Price<company.currency, uom> per company).- Traits:
trait Documentshared by orders, invoices and payments, and references to "any document" (origin: Document?). - Enums with data:
enum PriceTarget: AllProducts, OneProduct(product: Product), …andmatchwith bindings. - Reactions:
on SalesOrder enters Confirmed as o:creates the delivery;on ReorderRule becomes to_order > 0 as r converges:reorders automatically;before SalesOrder.confirm as o:adds a credit check from another module. allocate: splitting an amount over items so that the shares add up to the cent (VAT per line, landed costs, payment terms).- Recursion on data: category paths and bills of materials with
closure(…), made safe by acheckthat the tree has no cycles. - Metrics and controls:
metric revenue(company, period) -> Money<…>with fingerprints recorded bytyperule certifyinmetrics.lock, so a changed definition doesn't go unnoticed. - Views and reports:
view SalesOrderForm(o: SalesOrder)andreport SalesAnalysis.
Go deeper in the reference
- Reference — every construct of the language, the standard library, the CLI, the HTTP API and how storage works.
typerule trace Entity.fieldon any value you don't understand.- The editor extension's hover shows the unified view of an entity, with every
extendfrom every module.
Things to try on your shop
- Multi-company: extend
Companywith an address and a VAT number, addcompany: Company default current.companyto orders and invoices, and number documents per company. - A reaction: when an order enters
Confirmed, create aShipmentdocument with one line per order line (on Order enters Confirmed as o:). - Purchasing: a
PurchaseOrderto aSupplier, whose receipt createsRestocks — and aReorderRulethat proposes a purchase whenavailablefalls below a minimum. - A general ledger: a
GLledger withcheck per (source): g => g.sum(r => r.amount) == 0(double entry), posted by invoices and payments. - PostgreSQL:
typerule test --db postgres://…andtyperule db init --url postgres://…— the same model, the same history, the same hashes.
Happy modelling — and may your books always balance.