Files
rose-ash/sx/sx/geography/index.sx
giles 7628659854 Fix geography index: restore default content and add page gutters
The geography page function returned nil instead of the index-content
component, and the index layout was missing the standard doc page wrapper.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-22 23:34:51 +00:00

149 lines
9.3 KiB
Plaintext

;; Geography index — architecture overview
;; Describes the rendering pipeline: OCaml evaluator → wire formats → client
(defcomp ~geography/index-content () :affinity :server
(div :class "max-w-4xl mx-auto px-6 pb-8 pt-4"
(h2 :class "text-3xl font-bold text-stone-800 mb-4" "Geography")
(p :class "text-lg text-stone-600 mb-8"
"Where code runs and how it gets there. Geography maps the rendering pipeline from server-side evaluation through wire formats to client-side hydration.")
;; Architecture diagram
(div :class "bg-stone-50 border border-stone-200 rounded-lg p-6 mb-8"
(h3 :class "text-xl font-semibold text-stone-700 mb-4" "Rendering Pipeline")
(div :class "space-y-4"
;; Server
(div :class "flex items-start gap-4"
(div :class "w-28 shrink-0 font-mono text-sm font-semibold text-sky-700 bg-sky-50 rounded px-2 py-1 text-center" "OCaml kernel")
(div
(p :class "text-stone-700"
"The evaluator is a CEK machine written in SX and bootstrapped to OCaml. It evaluates page definitions, expands components, resolves IO (helpers, queries), and serializes the result as SX wire format.")
(p :class "text-sm text-stone-500 mt-1"
"spec/evaluator.sx → hosts/ocaml/ → aser-slot with batch IO")))
;; Wire format
(div :class "flex items-start gap-4"
(div :class "w-28 shrink-0 font-mono text-sm font-semibold text-amber-700 bg-amber-50 rounded px-2 py-1 text-center" "Wire format")
(div
(p :class "text-stone-700"
"The aser (async-serialize) mode produces SX text — HTML tags and component calls serialized as s-expressions. Components with server affinity are expanded; client components stay as calls. The wire format is placed in a "
(code :class "text-sm" "<script type=\"text/sx\">")
" tag inside the HTML shell.")
(p :class "text-sm text-stone-500 mt-1"
"web/adapter-sx.sx → SxExpr values pass through serialize unquoted")))
;; Client
(div :class "flex items-start gap-4"
(div :class "w-28 shrink-0 font-mono text-sm font-semibold text-emerald-700 bg-emerald-50 rounded px-2 py-1 text-center" "sx-browser.js")
(div
(p :class "text-stone-700"
"The client engine parses the SX wire format, evaluates component definitions, renders the DOM, and hydrates reactive islands. It includes the same CEK evaluator (transpiled from the spec), the parser, all web adapters, and the orchestration layer for fetch/swap/polling.")
(p :class "text-sm text-stone-500 mt-1"
"spec/ + web/ → hosts/javascript/cli.py → sx-browser.js (~400KB)")))))
;; What lives where
(h3 :class "text-xl font-semibold text-stone-700 mb-4 mt-8" "What lives where")
(div :class "grid md:grid-cols-2 gap-4 mb-8"
;; Spec
(div :class "border border-stone-200 rounded-lg p-4"
(h4 :class "font-semibold text-stone-700 mb-2" "Spec (shared)")
(p :class "text-sm text-stone-600 mb-2" "The canonical SX language, bootstrapped identically to OCaml, JavaScript, and Python:")
(ul :class "text-sm text-stone-600 space-y-1 list-disc ml-4"
(li "CEK evaluator — frames, step function, call dispatch")
(li "Parser — tokenizer, s-expression reader, serializer")
(li "Primitives — ~80 built-in pure functions")
(li "Render modes — HTML, SX wire, DOM")))
;; Web adapters
(div :class "border border-stone-200 rounded-lg p-4"
(h4 :class "font-semibold text-stone-700 mb-2" "Web Adapters")
(p :class "text-sm text-stone-600 mb-2" "SX-defined modules that run on both server and client:")
(ul :class "text-sm text-stone-600 space-y-1 list-disc ml-4"
(li "adapter-sx.sx — aser wire format (server component expansion)")
(li "adapter-html.sx — server HTML rendering")
(li "adapter-dom.sx — client DOM rendering")
(li "orchestration.sx — fetch, swap, polling, navigation")
(li "engine.sx — trigger parsing, request building")))
;; OCaml kernel
(div :class "border border-stone-200 rounded-lg p-4"
(h4 :class "font-semibold text-stone-700 mb-2" "OCaml Kernel (server)")
(p :class "text-sm text-stone-600 mb-2" "Persistent process connected via a binary pipe protocol:")
(ul :class "text-sm text-stone-600 space-y-1 list-disc ml-4"
(li "CEK evaluator + VM bytecode compiler")
(li "Batch IO bridge — defers helper/query calls to Python")
(li "Length-prefixed blob protocol — no string escaping")
(li "Component hot-reload on .sx file changes")))
;; sx-browser.js
(div :class "border border-stone-200 rounded-lg p-4"
(h4 :class "font-semibold text-stone-700 mb-2" "sx-browser.js (client)")
(p :class "text-sm text-stone-600 mb-2" "Single JS bundle transpiled from spec + web adapters:")
(ul :class "text-sm text-stone-600 space-y-1 list-disc ml-4"
(li "Parses SX wire format from script tags")
(li "Renders component trees to DOM")
(li "Hydrates reactive islands (signals, effects)")
(li "Client-side routing with defpage")
(li "HTMX-like fetch/swap orchestration"))))
;; Rendering modes
(h3 :class "text-xl font-semibold text-stone-700 mb-4 mt-8" "Rendering Modes")
(div :class "overflow-x-auto mb-8"
(table :class "w-full text-sm"
(thead
(tr :class "border-b border-stone-200"
(th :class "px-3 py-2 text-left font-medium text-stone-600" "Mode")
(th :class "px-3 py-2 text-left font-medium text-stone-600" "Runs on")
(th :class "px-3 py-2 text-left font-medium text-stone-600" "Components")
(th :class "px-3 py-2 text-left font-medium text-stone-600" "Output")))
(tbody
(tr :class "border-b border-stone-100"
(td :class "px-3 py-2 font-mono" "render-to-html")
(td :class "px-3 py-2" "Server (OCaml)")
(td :class "px-3 py-2" "Expanded recursively")
(td :class "px-3 py-2" "HTML string"))
(tr :class "border-b border-stone-100"
(td :class "px-3 py-2 font-mono" "aser / aser-slot")
(td :class "px-3 py-2" "Server (OCaml)")
(td :class "px-3 py-2" "Server-affinity expanded; client preserved")
(td :class "px-3 py-2" "SX wire format"))
(tr :class "border-b border-stone-100"
(td :class "px-3 py-2 font-mono" "render-to-dom")
(td :class "px-3 py-2" "Client (sx-browser.js)")
(td :class "px-3 py-2" "Expanded recursively")
(td :class "px-3 py-2" "DOM nodes"))
(tr :class "border-b border-stone-100"
(td :class "px-3 py-2 font-mono" "client routing")
(td :class "px-3 py-2" "Client (sx-browser.js)")
(td :class "px-3 py-2" "defpage content evaluated locally")
(td :class "px-3 py-2" "DOM swap")))))
;; Topics
(h3 :class "text-xl font-semibold text-stone-700 mb-4 mt-8" "Topics")
(div :class "grid md:grid-cols-2 gap-4"
(a :href "/sx/(geography.(hypermedia))" :class "block border border-stone-200 rounded-lg p-4 hover:border-sky-300 hover:bg-sky-50 transition-colors"
(h4 :class "font-semibold text-stone-700" "Hypermedia Lakes")
(p :class "text-sm text-stone-500" "Server-driven UI with sx-get/post/put/delete — fetch, swap, and the request lifecycle."))
(a :href "/sx/(geography.(reactive))" :class "block border border-stone-200 rounded-lg p-4 hover:border-sky-300 hover:bg-sky-50 transition-colors"
(h4 :class "font-semibold text-stone-700" "Reactive Islands")
(p :class "text-sm text-stone-500" "Client-side signals and effects hydrated from server-rendered HTML. defisland, deref, lakes."))
(a :href "/sx/(geography.(marshes))" :class "block border border-stone-200 rounded-lg p-4 hover:border-sky-300 hover:bg-sky-50 transition-colors"
(h4 :class "font-semibold text-stone-700" "Marshes")
(p :class "text-sm text-stone-500" "Where reactivity and hypermedia interpenetrate — server writes to signals, reactive views reshape server content."))
(a :href "/sx/(geography.(scopes))" :class "block border border-stone-200 rounded-lg p-4 hover:border-sky-300 hover:bg-sky-50 transition-colors"
(h4 :class "font-semibold text-stone-700" "Scopes")
(p :class "text-sm text-stone-500" "Render-time dynamic scope — the primitive beneath provide, collect!, spreads, and islands."))
(a :href "/sx/(geography.(cek))" :class "block border border-stone-200 rounded-lg p-4 hover:border-sky-300 hover:bg-sky-50 transition-colors"
(h4 :class "font-semibold text-stone-700" "CEK Machine")
(p :class "text-sm text-stone-500" "The evaluator internals — frames, continuations, tail-call optimization, and the VM bytecode compiler."))
(a :href "/sx/(geography.(isomorphism))" :class "block border border-stone-200 rounded-lg p-4 hover:border-sky-300 hover:bg-sky-50 transition-colors"
(h4 :class "font-semibold text-stone-700" "Isomorphism")
(p :class "text-sm text-stone-500" "One spec, multiple hosts — how the same SX code runs on OCaml, JavaScript, and Python.")))))