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)#
- Open LeanUI Studio and open the
⊞ Solutiontab in the left dock (or clickExport ▾ → + New Solution from Template…). - Click
+ Module, name itServerMonitor(or typeServerMonitorin the topbar title box), and confirm the center bar is on◈ Graph. - Keep the Node Palette on the left, Property Inspector split below it, Live Preview + Timeline on the right, and Console at the bottom.
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#
- Drag a
Statenode from the left Node Palette (under ViewModel, Complex Logic & Proof Rules) onto the canvas — or click+ Node ▾ → State. - Click the new node to select it, then edit its properties in the Node Inspector:
- Name:
cpuLoad - Lean 4 Type:
Nat - Initial Value:
0
- Name:
- Drag a second
Statenode right below it and configure:- Name:
maxLoad - Lean 4 Type:
Nat - Initial Value:
100
- Name:
Checkpoint: The topbar status pill shows
● Verified (0 err), and the Lean 4 code panel already displaysstructure 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#
- Drag a
Computednode 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!)
- Name:
- Drag an
Invariantnode belowoverloaded:- Name:
loadSafe· Expression:cpuLoad <= maxLoad
- Name:
- 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.inandloadSafe.checkmaxLoad.val→overloaded.inandloadSafe.check
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#
- Add an
Actionnode namedSpikeLoad:- Expression:
cpuLoad = Math.min(maxLoad, cpuLoad + 25) - Wire
SpikeLoad.effect→cpuLoad.mutate.
- Expression:
- Add a second
Actionnode namedCoolDown:- Expression:
cpuLoad = Math.max(0, cpuLoad - 25) - Wire
CoolDown.effect→cpuLoad.mutate.
- Expression:
Verify Your Logic Immediately with λ Prove & Proofs Panel#
- Click the dark
λ Provebutton in the top-right toolbar (or pressCmd/Ctrl+Shift+P). - Open the
✓ Proofstab 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.
Try breaking a proof on purpose! Temporarily change
SpikeLoadtocpuLoad = cpuLoad + 25(withoutMath.min). LeanUI's instant verifier immediately highlightsloadSafein red with a concrete counterexample (cpuLoad = 125), then restores green as soon as you putMath.minback.
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#
- Drag a
Card(MonitorCard, Title:"Server Load Monitor") to the right of your ViewModel. - Add four View children and wire
MonitorCard.children→ each child'sparentport: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)
- Bind data & events:
cpuLoad.val→LoadStat.valueandLoadBar.valueoverloaded.out→SpikeBtn.disabled(automatically disables+25% Spikeat 100%!)SpikeBtn.onClick→SpikeLoad.triggerCoolBtn.onClick→CoolDown.trigger
- Click
Layoutin the topbar (DAG Layered) to arrange every node and obstacle-avoiding wire neatly.
Checkpoint: Look at the right-hand Live Preview dock — your
Server Load Monitorcard 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#
- Click
+ Node ▾ → Live App View Preview (Node)to dropLiveMonitorPreview(app_preview) right onto the canvas. - Resize & test responsive layouts:
- Drag any of the 8 resize handles (corners or edges) — hold
Shiftto lock aspect ratio,Altto resize from center, or double-click any handle to auto-fit to live UI content. - Click
Mob/Tab/Desk/Wideinside the preview header to snap to device viewports, or toggleReflow↔Scale. - Click
⊡ Sizein the bottom Canvas HUD to auto-size all nodes cleanly without overlap.
- Drag any of the 8 resize handles (corners or edges) — hold
- Click the black
λ Provehero button in the topbar:- Runs the real Lean 4 WASM kernel in your browser (or local Native
lakeif running locally) and verifiesinit_preserves_inv,step_preserves_inv, andview_well_formed.
- Runs the real Lean 4 WASM kernel in your browser (or local Native
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#
- 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 pressF9) to set a breakpoint, then step node-by-node withF10in the⌖ Debugpanel.
- After dispatching
- Time-Travel in
⏱ Timeline:- Open the
⏱ Timelinedock 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
🧪 Testto export a runnable Playwright / Node regression test!
- Open the
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#
- Click
❖ Explodein 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. - Click
🧊 3D Orbitto inspect your recorded state frames stacked in 3D space with animated flow arcs. - 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
- Standalone HTML (
- Export Visual Diagrams (
SVG / PNG / Multi-Page PDF):- Click
⤓ Exportin the bottom Canvas HUD (orExport ▾ → 🖼 Export Diagram…) to export Clean State, Current Live State, Timeline History Book, or a 6-Page Complete Architecture Deck PDF!
- Click
Continue Learning#
- Explore every single panel & gesture in Every Studio Panel & Interactions (12) and All 7 Stage Modes.
- Ready to work with typed record lists (
Collection), WCAG AAA design tokens, multi-locale i18n, and sortable data tables? Continue to Tutorial 2 · Build a Styled Task Tracker!