Appearance
Installation
TypeRule is a single command-line program, typerule, written in Rust. It contains the compiler, the test runner, the database tools, the HTTP server and the language server for your editor. The standard library (currencies, units, companies, users, numbering) is built into the binary.
Just want to look around?
You don't need to install anything to try the language: the Sandbox runs the compiler and the tests in your browser.
Install
On macOS and Linux:
bash
curl -fsSL https://typerule.com/install.sh | shOn Windows (PowerShell):
powershell
irm https://typerule.com/install.ps1 | iexThe installer picks the binary for your machine (macOS on Apple chips and Intel, Linux on x64 and ARM, Windows x64), checks its SHA-256, puts it in ~/.typerule/bin and adds that folder to your PATH. Open a new terminal and check:
bash
typerule --versionTo update, run typerule upgrade. A specific version: TYPERULE_VERSION=0.5.0 before the command ($env:TYPERULE_VERSION = "0.5.0" on Windows). To leave your shell's configuration alone, set TYPERULE_NO_MODIFY_PATH=1 and add ~/.typerule/bin to the PATH yourself.
What the installer changes
It writes ~/.typerule/bin/typerule and one line in the configuration of your shell: ~/.zshrc (zsh), ~/.bashrc and ~/.bash_profile (bash), ~/.config/fish/conf.d/typerule.fish (fish) or ~/.profile. On Windows it adds the folder to your user PATH. To uninstall, remove ~/.typerule and that line.
Build from source
TypeRule is open source (github.com/typerule/typerule, Apache License 2.0). You need a recent stable Rust toolchain (rustup.rs):
bash
git clone https://github.com/typerule/typerule.git
cd typerule
cargo build --release -p typerule-cli # target/release/typeruleA build from the sources has everything except TypeRule Studio, the web interface of typerule dev and typerule serve (the spreadsheet-like app and the code editor): it is in the official binaries, under its own license (free to use, not to resell). Without it, the API answers as usual at /v1.
Run typerule without arguments to see every command:
text
usage:
typerule init [path] [--name n] [--db sqlite|postgres://…] [--yes] a new project
typerule dev [path] [--port 8080] [--fixture name] [--reset] app + code editor, applying every saved change
typerule check [path] check a project (default: current directory)
typerule trace <Entity.field> [path] what a value depends on and who writes it
typerule certify [name…] [path] record metric fingerprints in metrics.lock
typerule fmt [--check] [path] format sources
typerule test [path] [--filter text] [--db sqlite|postgres://…] run the tests
typerule db init|status|migrate [--dry-run]|verify|provisional|sweep|fixture <name> [path] [--url URL]
typerule change list | preview <name> | apply <name> [--approved-by login] | revert <name> [--approved-by login]
typerule serve [path] [--url URL] [--port 8080] [--web dir] [--dev-login] [--cache-mb 256] [--prewarm-days N] [--sweep-every secs] [--editors login,…]
typerule token create <login> [--name n] [--read-only] [--days 90] | revoke <name> [path] [--url URL]
typerule parse <file> print the syntax tree of a file
typerule lsp start the language serverThe studio
The studio (the app your users work in, and the code editor) is built into the official binary: typerule dev and typerule serve serve it on the same origin as the API, with nothing else to install. --web dir serves another build of it instead.
Editor support: VS Code and Cursor
The extension in editors/vscode gives you:
- syntax highlighting for
.trfiles; - the language server (
typerule lsp): errors while you type, go to definition, hover with types and units (and the unified view of an entity spread over severalextends), outline, semantic colouring of entities, stored fields, formulas, actions and units, and hints on how queries, row rules and formulas run on the database (typerule lsp); - indentation after
:and folding by indentation.
Build and install it from the sources (github.com/typerule/typerule):
bash
cd editors/vscode
npm install
npx @vscode/vsce package --skip-license --allow-missing-repositorybash
code --install-extension typerule-*.vsix --force # VS Code
cursor --install-extension typerule-*.vsix --force # CursorThe extension looks for the typerule binary in this order:
- the
typerule.serverPathsetting; target/release/typeruleortarget/debug/typerulein the open folder or up to three folders above it;typeruleon yourPATH.
After rebuilding typerule, run Developer: Reload Window to restart the language server.
Project layout
A TypeRule project is a folder with a typerule.toml file. Every .tr file inside it is a module, named after its path: catalog.tr is catalog, core/base.tr is core.base.
text
shop/
├── typerule.toml the project file
├── customers.tr modules: entities, formulas, rules, flows…
├── catalog.tr
├── orders.tr
├── security.tr roles and permissions
├── tests/
│ ├── fixtures.tr shared test data (`fixture` blocks)
│ └── orders.test.tr `test` blocks
├── migrations/
│ ├── 2026-12-01_sku.tr `migration` blocks that go with a schema change
│ └── origins.csv data a migration loads
└── .typerule/data.db the development database (created by `typerule db init`)The smallest typerule.toml:
toml
[project]
name = "shop"Add the project's time zone (an IANA name) if it is not UTC: today(), the hours and the dates of instants are read there (Dates, times and time zones):
toml
[project]
name = "shop"
timezone = "Europe/Rome"By default the database is SQLite in .typerule/data.db. To use another one, pass --url to the db, serve and token commands, or set it in typerule.toml:
toml
[database]
url = "postgres://typerule@localhost:5432/shop"URLs look like sqlite:path/to/file.db or postgres://user@host:port/db (add #schema=name to use a PostgreSQL schema). A relative SQLite path in typerule.toml is relative to the project folder.
Modules and imports
A module sees the standard library (EUR, kg, Currency, Uom, Company, User…) and what it imports:
typerule
from customers import Customer, Address
from catalog import Product, CategoryImports cannot form a cycle. When a lower module needs a field that belongs to a higher one (customers do not know about orders, but a customer has orders), the higher module adds it with extend:
typerule
extend Customer:
orders: [Order]Test files (*.test.tr and the other files in tests/) and migrations/ see every module of the project without imports; tests import only the fixtures they use.
Next
Head to the Quick start to create your first project.