Home Docs Developer guide Architecture and core concepts
Chapter 3
Architecture and core concepts
┌──────────────── Browser ────────────────────────────────────────────────┐
│ │
│ keyboard / IME / clipboard │
│ │ │
│ ▼ │
│ KeyboardProxy (one hidden <input>, reset after every keystroke) │
│ │ trusted events only │
│ ▼ │
│ FocusManager ──► focused Control ──► SecureBuffer (Uint32Array) │
│ │ │ │
│ ▼ ▼ │
│ Canvas 2D Form.submit() │
│ (what you see) │ validate (shared rules) │
│ │ bot guard, rate limit │
│ │ sealSecret(): PFE1 encrypt │
│ ▼ │
│ secureSubmit(): fetch + CSRF │
└───────────────────────────────────────────┼─────────────────────────────┘
▼ HTTPS
┌──────────────── Server ──────────────────────────────────────────────────┐
│ Host/Origin checks → session + CSRF → rate limit → JSON ≤16 KB │
│ → decrypt PFE1 (single-use challenge) → validatePayload(shared rules) │
│ → pepper + scrypt → store → zero plaintext │
└──────────────────────────────────────────────────────────────────────────┘
The four building blocks#
Concept
Role
FormUI
Shared runtime for one canvas: theme, focus, keyboard proxy, overlay layer (dropdowns, toasts), screen-reader announcer. Create one per Application.
Controls
Subclasses of Control<V>. Each owns its value, renders itself, handles keys/pointer, validates, and reports V from getValue().
Form
Groups controls by name, validates them together, applies anti-abuse checks, and calls your onSubmit. It isn't a visual element.
Rules
Declarative field definitions in shared/rules.ts. fromRule() configures controls; the server enforces the same rules.
Lifecycle of a keystroke#
The user presses a key. The hidden proxy <input> (focused while a control is focused) receives it.
Events with isTrusted === false (synthetic dispatchEvent) are ignored.
Navigation and editing keys go to FocusManager.handleKeyDown (Tab, modal interceptors), then to the
control's handleKeyDown. Printable text arrives via input/compositionend and goes to handleText.
The proxy is immediately reset to a zero-width placeholder, so it never holds field content.
The text field runs formatters → sanitiser → length cap, then writes code points into its SecureBuffer.
The control redraws and emits input and change.
Values#
Control
getValue() returns
TextInput, TextArea
string
PasswordInput
Secret (opaque handle; see §16 )
OtpInput
string of digits (wiped by the form after submit)
DatePicker
'YYYY-MM-DD', or 'YYYY-MM-DDTHH:mm' with time (plain local values), or null
PhoneInput
E.164 string, e.g. '+447911123456' ('' when empty)
Checkbox, Switch
boolean
RadioGroup, Select
T | null (one of the declared option values)
Slider
number (clamped and snapped to step)
Button
null (not included in form.values())