Skip to content

Architecture

Tesserae is a Python framework for desktop interfaces. You write screens in TDL and logic in Python; Tesserae builds the interface and keeps it up to date. It draws nothing itself: the engine, tess_re, owns the window, layout, painting, text, input and the event loop. Tesserae is everything above that.

The layers

 your code      app.py (App)   *_View.tdl   *_ViewModel.py   tess_ui.widgets
                    |               |               |               |
 Tesserae       registry,  ---> parse -> compose -> lower     controls, composed
                routing,        (nodes)  (instances) (spec)   widgets, overlays,
                bindings            |        |      |         docking
                    |               |        +------+---> View: nodes, reconciler
                    |               |      Signal / Computed / Effect (reactive)
                    |          tokens + Theme (colour, shape, type, motion) + rule sheets
                    v               v
 tess_re            Window: create / set / get / animate / on / show_layer
                (node tree, flex layout, paint, text, input, accessibility)

App code. App owns one window and a registry of named screens. A *_ViewModel.py holds state in Signals and Computeds (tess_ui.reactive: Signal, Computed, Effect, batch, untrack, ViewModel) and the methods a view's handlers call. A ViewModel serves the views that name it: views = "Counter" in the class, Name: Counter on the root node of the view, app.bind(CounterViewModel) and app.open_view("Counter") to join and open them. One instance serves every view that names it. See Apps and screens, the naming convention and Reactivity.

The spec pipeline (tess_ui.spec) turns a view file into live nodes in four steps:

  1. Parse (spec/nodes.py, with the TDL front end in spec/tdl.py). A *_View.tdl is read by tess_dl and handed on with its line and column kept; the If and For wrappers are removed there, so everything after parsing sees one node mapping. Every key of every node is checked against the node's widget, every property against its declaration, and every <| |> expression and handler is compiled by tess_ui.tel (TEL, tess_el). The first mistake is an error that names the file, line and column. A widget is a built-in (spec/builtin_widgets.py), or a view: one with Params is declared from them, and found by name in the project or among the views Tesserae ships (tess_ui/views, with a *_Stylesheet.tdl of rules beside each).
  2. Compose (spec/compose.py). The parsed views become a tree of instances: a view call is replaced by the called view's root with the call's keys as its params, slots are filled, For and If make or drop instances, and State makes a Signal for each name. An expression written at a call is read where it is written, and a name is looked up in the loop variables, local state, params, the ViewModel, then the app.
  3. Lower (spec/lower.py). The instances become the node mappings the builder has always taken, with each property's current value.
  4. Build (spec/build.py, with the cascade). The builder creates tess_re nodes: Rect/Container become a box, Text and Link a text, Icon a path, Image an image, a text input a text_input. The stateful kinds (Checkbox, RadioButton, Switch, Slider, RangeSlider, SpinBox, CircularProgress, LinearProgress, LoadingIndicator, TimePickerDial) become Tesserae's own controls. Image src: files are decoded to pixels (tess_utils.decode_image_file). Every property is set explicitly, defaults included, so a later patch can reset it.

Styles. A node's style is built from layers, lowest first: the rules Tesserae ships with each view, the app's stylesheet (a Styles block of Rules that name a Widget, and may narrow it by Variant, Size, Shape, Classes, Name, Part and State), then the node's inline Style. The most specific rule in a layer wins, and a later rule wins a tie; a value in a rule may be an expression over the widget's properties. See Themes and Stylesheets.

Tokens and Theme. tess_ui.tokens holds the MD3 values: the 49 colour roles from a seed (light and dark, via materialyoucolor) with colors: overrides, the shape scale, elevation (as key and ambient shadows), the 15 type roles, and colour-string parsing (tess_utils.parse_color). tess_ui.Theme is one resolved theme, which style values like primary, extra_large, level_3 or typography_role resolve through. Widgets and views follow their app's theme: App.set_dark, the OS light/dark switch and App.set_theme_specs re-colour them in place. See Themes and Stylesheets.

Widgets. tess_ui.controls are the stateful MD3 controls (Checkbox, Switch, Slider, SpinBox, progress indicators, the time dial); each keeps its state in Signals and fires on_change for the user's edits only. tess_ui.widgets has one function per MD3 widget, for code that makes nodes at run time, each returning a control, a Widget (with .node and its parts) or an overlay. tess_ui.interaction draws what the engine does not: state layers, the ripple and focus rings. tess_ui.a11y sets roles and states. tess_ui.overlays (Dialog, Menu, Snackbar, Tooltip, Popover, SearchView, NavigationDrawer) show nodes with window.show_layer. A Window view frames the screens with a title bar, a rail and docked panels, and Dock manages the panels in its zones. See the widget catalog, controls, overlays, windows and docks and the component gallery.

The engine, tess_re. It provides the node tree (create, set, get, animate, on, add_child, insert_child, remove, destroy), layout, painting, text, input, accessibility, layers and the render loop. It has no widgets, theme, stylesheets or reactivity of its own.

What Tesserae hands tess_re: specs and bytes, never files. Tesserae reads, parses, decodes and watches every file. tess_re receives nodes built through its API, colours as RGBA tuples, image pixels as rgba on an image node, and font files as bytes (register_font). It is never given a path.

A screen load

app.bind(CounterViewModel) and app.open_view("Counter"):

  1. bind records that CounterViewModel serves the view named Counter. Nothing is made yet.
  2. open_view finds Counter_View.tdl (a path, or a name in the project), and parses it together with the views it calls.
  3. The ViewModel is made, once, with no arguments, and composed with the view into instances. Each expression is static (worked out once) or reactive (a binding that follows the Signals it reads).
  4. ComposedView lowers the instances and builds them with the app's theme and rules into nodes in the app's window, then wires each handler to its node. The view is registered as "Counter".
  5. app.show("Counter") attaches the view's root to window.root and detaches the previous screen's root. A detached screen keeps its state and bindings. Nothing is parsed again. navigate, route and back add a history of named screens on top of show.

A signal change

A binding such as Text: <| count |> is an expression in a restricted subset of Python (tess_ui.tel: arithmetic, comparisons, comprehensions, a short list of functions; never eval). While it is evaluated, tess_ui.reactive notes every Signal or Computed it reads. When one changes (vm.count.set(5)), ComposedView lowers its instances again and View.reconcile patches the live nodes: a node whose id is unchanged keeps its identity, focus and running animations, and only the fields that differ are set. batch defers notifications so each subscriber runs once. Going the other way, a handler (On_Click: increment) is a listener on the node that runs the ViewModel method, or the statements written there, in the names where they were written; a model property given a bare reference (Checked: <| done |>) writes the user's edit back to that Signal. See Bindings.

Reconciling and hot reload

View.reconcile matches children by id, which is the node's path from the root: its Name, or its place, with the key added under a For. An unchanged node keeps its identity, focus and running animations, a changed one is patched in place, a changed kind is rebuilt, a missing one is destroyed, and children follow the new spec's order. Bindings and handlers are wired again after each update, without doubling listeners. A node that keeps its Name or key keeps its State.

App.run(hot_reload=True) uses the same machinery. It watches the theme files and the app's stylesheet file given to the app, a ComposedWatcher per view opened with open_view or open_window (the file and every view, stylesheet and theme it was built from) (watchfiles, on a background thread). On a change it reruns the pipeline off the main thread and hands the result to the event loop through tess_re's thread-safe loop handle, which reconciles the live view. A failed reload is logged and the app keeps running. See Hot reload for what is watched.

Design rules

  • Specs and bytes, never files. See above; it keeps all file handling and watching in one place.
  • TDL is data. No eval: expressions are a small checked grammar and handlers name ViewModel methods or are short statements. Mistakes (an unknown property, a name no ViewModel has, a mismatched naming pair) fail at load with a message that names the spot.
  • One source of truth per state. State lives in Signals; the UI is a function of them. A programmatic set never fires on_change, so reloads and bindings do not echo back.
  • Everything is built from the engine's primitives (create, set, on, show_layer), so the engine stays small and each widget's look sits in a stylesheet you can override.
  • Themes are data. Seed colour, Colors, Components shape and elevation, and Typography overrides in a theme file re-resolve the colours and re-colour live views.
  • Screens are long-lived. Switching screens detaches, never rebuilds.
  • Proven against recorded answers. Binding, cascade, colour and tree-building tests replay reference results recorded from tess_re (tests/reference/*.json), so a regression in those parts fails a test.

For the full list of names and signatures see the Python API and the TDL reference.