hn.today

I built the RealWorld app in Lean 4

leangineer.com4 points1 comments
Screenshot of I built the RealWorld app in Lean 4

A complete RealWorld reference application (API and website) was implemented entirely in Lean 4 and passes the official API and browser test suites. The implementation uses Lean’s Std.Http server and lean-routing for typed routes, leanpostgres for Postgres access with sql! parameterization, lean-html for server-side rendering, datastar-lean for frontend interactivity, and libraries such as lean-json, lean-libcrypto, lean-jose, lean-middleware and lean-markdown. Handlers call a shared service layer, SQL rows map to Lean structures, and Datastar sends small client-side requests so no frontend build step is needed. The Lean backend is compact (≈1,033 lines), shorter than comparable TypeScript, Go and C# versions, and the codebase and libraries are on GitHub.

The writeup evaluates production readiness and correctness-by-construction. Performance currently tops out at a few thousand requests/sec/process due to a runtime bug pending release; ecosystem churn and many small contributors mean real-world hardening is needed. Full correctness-by-construction wasn’t achieved because the OpenAPI spec and tests are formal about shapes but informal about behavior, so the app was written then tested rather than derived from a formal spec. The author did prove and rely on several properties the typechecker enforces (for example, route/handler type mismatches fail at compile time) and recommends pinning the toolchain and carefully auditing handlers, SQL and C bindings before serving real users.

Read on leangineer.com1 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

My C23 Conventions

My C23 Conventions

Abner Coimbre discusses modern C conventions in C23, emphasizing the use of maybe_unused to handle unused return values and improve code clarity. He also highlights issues with designated initializers not zero-initializing structs, leading to more careful struct initialization practices. (abner.page)

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.