LeanUI Docs
← Open LeanUI Studio GitHub

Tutorial 1 · Build Your First Verified App (7 Visual Steps)#

In this visual, step-by-step walkthrough, you will build a complete Server Load Monitor (ServerMonitor) app from scratch in LeanUI Studio — watching the graph evolve at every single step with live annotated snapshots, proving its safety rules mathematically in Lean 4, resizing an embedded Live App Preview, stepping through execution with the Debugger & Timeline, inspecting it in 3D CAD Explode, and exporting clean HTML, React TSX, Lean 4, SVG, PNG, and Multi-Page PDF artifacts.

Follow along live in your browser (zero install): https://wieslawsoltes.github.io/LeanUI/ Every diagram below is auto-generated directly from the live LeanUI engine on every deployment — click any figure to enlarge (⤢ Zoom) or toggle Light/Dark mode in the top-right bar.


Before You Start: Create a Clean Module (Step 0)#

  1. Open LeanUI Studio and open the ⊞ Solution tab in the left dock (or click Export ▾ → + New Solution from Template…).
  2. Click + Module, name it ServerMonitor (or type ServerMonitor in the topbar title box), and confirm the center bar is on ◈ Graph.
  3. Keep the Node Palette on the left, Property Inspector split below it, Live Preview + Timeline on the right, and Console at the bottom.
LIVE GENERATED SVG · AUTO-UPDATED ON BUILD
Open SVG ↗
Step 0 Full Workspace Snapshot — Entire LeanUI Studio Setup, Topbar Rename, Palette Drag & Split Inspector Step 0 Full Workspace Snapshot — Entire LeanUI Studio Setup, Topbar Rename, Palette Drag & Split Inspector
Step 0 Full Workspace Snapshot — Entire LeanUI Studio Setup, Topbar Rename, Palette Drag & Split Inspector

Step 1 · Add Typed State Fields (cpuLoad & maxLoad)#

Every LeanUI app starts with strongly typed State nodes that become the fields of your Lean 4 structure ViewModel.

How to Do This in LeanUI Studio#

  1. Drag a State node from the left Node Palette (under ViewModel, Complex Logic & Proof Rules) onto the canvas — or click + Node ▾ → State.
  2. Click the new node to select it, then edit its properties in the Node Inspector:
    • Name: cpuLoad
    • Lean 4 Type: Nat
    • Initial Value: 0
  3. Drag a second State node right below it and configure:
    • Name: maxLoad
    • Lean 4 Type: Nat
    • Initial Value: 100
LIVE GENERATED SVG · AUTO-UPDATED ON BUILD
Open SVG ↗
Step 1 Snapshot — Two typed State nodes (cpuLoad := 0, maxLoad := 100) placed on the Graph Canvas Step 1 Snapshot — Two typed State nodes (cpuLoad := 0, maxLoad := 100) placed on the Graph Canvas
Step 1 Snapshot — Two typed State nodes (cpuLoad := 0, maxLoad := 100) placed on the Graph Canvas

Checkpoint: The topbar status pill shows ● Verified (0 err), and the Lean 4 code panel already displays structure ViewModel where cpuLoad : Nat; maxLoad : Nat.


Step 2 · Wire a Computed Guard & Lean 4 Safety Invariant#

Next, derive a boolean guard (overloaded) so the UI knows when capacity is full, and declare a mathematical Invariant (loadSafe) that Lean 4 will prove can never be violated.

How to Do This in LeanUI Studio#

  1. Drag a Computed node to the right of your State nodes:
    • Name: overloaded · Lean 4 Type: Bool · Expression: cpuLoad >= maxLoad
    • (Tip: Double-click any Computed, Action, or Invariant node — or click ƒ on its header — to build expressions visually with zero syntax typos!)
  2. Drag an Invariant node below overloaded:
    • Name: loadSafe · Expression: cpuLoad <= maxLoad
  3. Wire the typed ports by dragging from an output dot on the right edge of a node to an input dot on the left edge:
    • cpuLoad.val → overloaded.in and loadSafe.check
    • maxLoad.val → overloaded.in and loadSafe.check
LIVE GENERATED SVG · AUTO-UPDATED ON BUILD
Open SVG ↗
Step 2 Snapshot — Derived Computed guard (overloaded) and formal Lean 4 Invariant (loadSafe) wired to State Step 2 Snapshot — Derived Computed guard (overloaded) and formal Lean 4 Invariant (loadSafe) wired to State
Step 2 Snapshot — Derived Computed guard (overloaded) and formal Lean 4 Invariant (loadSafe) wired to State

Checkpoint: Notice how port dots highlight green when compatible and reject type mismatches automatically!


Step 3 · Add Pure Bounded Action Reducers (SpikeLoad & CoolDown)#

Actions define the only way state can change. By clamping inside pure expressions, Lean 4 can prove your invariant holds across every reachable state.

How to Do This in LeanUI Studio#

  1. Add an Action node named SpikeLoad:
    • Expression: cpuLoad = Math.min(maxLoad, cpuLoad + 25)
    • Wire SpikeLoad.effect → cpuLoad.mutate.
  2. Add a second Action node named CoolDown:
    • Expression: cpuLoad = Math.max(0, cpuLoad - 25)
    • Wire CoolDown.effect → cpuLoad.mutate.
LIVE GENERATED SVG · AUTO-UPDATED ON BUILD
Open SVG ↗
Step 3 Snapshot — Pure bounded Action reducers wired to cpuLoad.mutate so Lean 4 can prove step_preserves_inv Step 3 Snapshot — Pure bounded Action reducers wired to cpuLoad.mutate so Lean 4 can prove step_preserves_inv
Step 3 Snapshot — Pure bounded Action reducers wired to cpuLoad.mutate so Lean 4 can prove step_preserves_inv

Verify Your Logic Immediately with λ Prove & Proofs Panel#

  1. Click the dark λ Prove button in the top-right toolbar (or press Cmd/Ctrl+Shift+P).
  2. Open the ✓ Proofs tab in the right dock to inspect every proved obligation (init_preserves_inv, SpikeLoad_preserves_inv, CoolDown_preserves_inv) and switch across Matrix, Dep Graph, Tactic Tree, Counterexample, and AST views.
LIVE GENERATED SVG · AUTO-UPDATED ON BUILD
Open SVG ↗
Step 3b Focused Panel Snapshot — Formal Proof Matrix Confirming Zero-Sorry QED Proofs After Clicking λ Prove Step 3b Focused Panel Snapshot — Formal Proof Matrix Confirming Zero-Sorry QED Proofs After Clicking λ Prove
Step 3b Focused Panel Snapshot — Formal Proof Matrix Confirming Zero-Sorry QED Proofs After Clicking λ Prove

Try breaking a proof on purpose! Temporarily change SpikeLoad to cpuLoad = cpuLoad + 25 (without Math.min). LeanUI's instant verifier immediately highlights loadSafe in red with a concrete counterexample (cpuLoad = 125), then restores green as soon as you put Math.min back.


Step 4 · Build & Wire the Reactive View Hierarchy#

Now connect your verified ViewModel to real interactive UI controls (Card, Stat, Progress, and Button).

How to Do This in LeanUI Studio#

  1. Drag a Card (MonitorCard, Title: "Server Load Monitor") to the right of your ViewModel.
  2. Add four View children and wire MonitorCard.children → each child's parent port:
    • Stat (LoadStat, Label: "CPU Load", Unit: "%")
    • Progress (LoadBar, Label: "Utilization", Max: 100)
    • Button (SpikeBtn, Label: "+25% Spike", Variant: Primary)
    • Button (CoolBtn, Label: "-25% Cool Down", Variant: Secondary)
  3. Bind data & events:
    • cpuLoad.val → LoadStat.value and LoadBar.value
    • overloaded.out → SpikeBtn.disabled (automatically disables +25% Spike at 100%!)
    • SpikeBtn.onClick → SpikeLoad.trigger
    • CoolBtn.onClick → CoolDown.trigger
  4. Click Layout in the topbar (DAG Layered) to arrange every node and obstacle-avoiding wire neatly.
LIVE GENERATED SVG · AUTO-UPDATED ON BUILD
Open SVG ↗
Step 4 Snapshot — Complete MVU graph connecting State, Computed, Invariant, Actions & Reactive View controls Step 4 Snapshot — Complete MVU graph connecting State, Computed, Invariant, Actions & Reactive View controls
Step 4 Snapshot — Complete MVU graph connecting State, Computed, Invariant, Actions & Reactive View controls

Checkpoint: Look at the right-hand Live Preview dock — your Server Load Monitor card is already live and interactive!


Step 5 · Embed a Resizable Live Preview, Auto-Size & Run λ Prove#

You can also place a live interactive preview directly on the Graph Canvas, resize any node with 8 handles, auto-size the whole graph, and formally prove all theorems in the real Lean 4 kernel.

How to Do This in LeanUI Studio#

  1. Click + Node ▾ → Live App View Preview (Node) to drop LiveMonitorPreview (app_preview) right onto the canvas.
  2. Resize & test responsive layouts:
    • Drag any of the 8 resize handles (corners or edges) — hold Shift to lock aspect ratio, Alt to resize from center, or double-click any handle to auto-fit to live UI content.
    • Click Mob / Tab / Desk / Wide inside the preview header to snap to device viewports, or toggle Reflow ↔ Scale.
    • Click ⊡ Size in the bottom Canvas HUD to auto-size all nodes cleanly without overlap.
  3. Click the black λ Prove hero button in the topbar:
    • Runs the real Lean 4 WASM kernel in your browser (or local Native lake if running locally) and verifies init_preserves_inv, step_preserves_inv, and view_well_formed.
LIVE GENERATED SVG · AUTO-UPDATED ON BUILD
Open SVG ↗
Step 5 Snapshot — Live embedded app_preview card with 8 resize handles, evaluated runtime values (= 50) & Lean 4 proof verified Step 5 Snapshot — Live embedded app_preview card with 8 resize handles, evaluated runtime values (= 50) & Lean 4 proof verified
Step 5 Snapshot — Live embedded app_preview card with 8 resize handles, evaluated runtime values (= 50) & Lean 4 proof verified

Step 6 · Debug Execution Step Order & Time-Travel Timeline#

Click +25% Spike twice in Live Preview (or inside LiveMonitorPreview) to record live state transitions and watch LeanUI's omnidirectional debugger in action.

How to Do This in LeanUI Studio#

  1. Execution Path Step-Order Pills (#1..#5):
    • After dispatching SpikeLoad, every touched node displays an amber #1, #2, #3… step-order pill docked cleanly along its top edge (completely clear of all 8 resize handles across Normal, Compact, Touch, and High-Contrast AAA modes!).
    • Click the small circle on SpikeLoad's header (or press F9) to set a breakpoint, then step node-by-node with F10 in the ⌖ Debug panel.
LIVE GENERATED SVG · AUTO-UPDATED ON BUILD
Open SVG ↗
Step 6a Snapshot — Live debug execution path showing top-edge #1 → #5 step-order pills and evaluated state badges Step 6a Snapshot — Live debug execution path showing top-edge #1 → #5 step-order pills and evaluated state badges
Step 6a Snapshot — Live debug execution path showing top-edge #1 → #5 step-order pills and evaluated state badges
  1. Time-Travel in ⏱ Timeline:
    • Open the ⏱ Timeline dock on the right to see every recorded frame (#0 initState → #1 SpikeLoad (0 → 25) → #2 SpikeLoad (25 → 50) → #3 SpikeLoad (50 → 75)).
    • Drag the scrubber backward to rewind Live Preview & Canvas state, or click 🧪 Test to export a runnable Playwright / Node regression test!
LIVE GENERATED SVG · AUTO-UPDATED ON BUILD
Open SVG ↗
Step 6b Snapshot — Recorded State & Invariant Timeline Storyboard with before → after diffs Step 6b Snapshot — Recorded State & Invariant Timeline Storyboard with before → after diffs
Step 6b Snapshot — Recorded State & Invariant Timeline Storyboard with before → after diffs

Step 7 · Inspect in 3D CAD Explode & Export Code or Multi-Page PDF#

Now explore your verified app in 3D and ship production artifacts in one click.

How to Do This in LeanUI Studio#

  1. Click ❖ Explode in the center stage bar to separate your app into 4 architectural depth planes (L0–L3) — drag to orbit 360° or click any face/corner on the AutoCAD 3D ViewCube.
  2. Click 🧊 3D Orbit to inspect your recorded state frames stacked in 3D space with animated flow arcs.
  3. Export Production Code: Open Export ▾ in the topbar to download:
    • Standalone HTML (ServerMonitor.html) — single zero-dependency interactive web app
    • React Component (ServerMonitor.tsx) — typed TypeScript React component
    • Lean 4 Spec (ServerMonitor.lean) — full machine-checkable Lean 4 module
  4. Export Visual Diagrams (SVG / PNG / Multi-Page PDF):
    • Click ⤓ Export in the bottom Canvas HUD (or Export ▾ → 🖼 Export Diagram…) to export Clean State, Current Live State, Timeline History Book, or a 6-Page Complete Architecture Deck PDF!
LIVE GENERATED SVG · AUTO-UPDATED ON BUILD
Open SVG ↗
Step 7a Snapshot — Completed ServerMonitor in 3D CAD Explode View ready to inspect across L0–L3 planes Step 7a Snapshot — Completed ServerMonitor in 3D CAD Explode View ready to inspect across L0–L3 planes
Step 7a Snapshot — Completed ServerMonitor in 3D CAD Explode View ready to inspect across L0–L3 planes
LIVE GENERATED SVG · AUTO-UPDATED ON BUILD
Open SVG ↗
Step 7b Focused Dialog Snapshot — Exporting ServerMonitor as SVG, Retina PNG, Multi-Page PDF, Entire App, or Selected Panel Step 7b Focused Dialog Snapshot — Exporting ServerMonitor as SVG, Retina PNG, Multi-Page PDF, Entire App, or Selected Panel
Step 7b Focused Dialog Snapshot — Exporting ServerMonitor as SVG, Retina PNG, Multi-Page PDF, Entire App, or Selected Panel

Continue Learning#

Diagram Preview
Enlarged diagram