Lanes: formally verified web applications in Lean 4

A framework for full-stack web applications whose invariants are proved by Lean's kernel.

Agents now write code faster than anyone can review it. For a web application, the parts that matter most are the business rules: who can see what, which balances can’t go negative, which migrations keep old data valid. Lanes makes those rules something a machine checks, alongside the code that runs.

Lanes is a web framework, database layer and runtime for Lean 4. You write your application’s tables, transactions, HTML views and routes as ordinary Lean code. Lanes runs them on a native server backed by PostgreSQL or SQLite, with background jobs, live-updating pages, auth and WebSockets built in.

The code you deploy is the code you check#

Application logic in Lanes is pure: a transaction is a function from the database to a result, with no hidden IO. That means the exact code you deploy can be checked in increasingly strong ways:

  • The type checker refuses IO inside transactions and catches broken links between pages and routes.
  • A counterexample finder searches databases and transactions for a run that breaks a rule you state, and prints the failing trace.
  • A model checker explores interleavings of transactions, migrations and background jobs, including lost commits, retries and restarts.
  • Proofs, checked by Lean’s kernel, show that a rule holds for every input, every database size and every concurrent run.

The framework itself carries proofs too. HTML escaping prevents markup injection, background jobs are delivered at least once, and two workers never hold the same job lease at the same time. What isn’t proved, such as the IO adapters and the C bindings, is listed file by file in the repository.

Fast enough to run#

On a 32-core Linux machine, one Lanes process served 151,778 database reads per second on 13.6 cores. A Go server (net/http with pgxpool) served 127,810 on 25.1 cores.

Status#

Lanes is an early preview, at version 0.0.4. A more in-depth writeup is coming once v0.1.0 is ready. Until then, the code, examples and documentation are on GitHub.