Architecture

Core Principle

bitwrench.js is the frontend. webwrench does not have its own JavaScript or CSS — it sends instructions that bitwrench renders.

Data Flow

Python Code ww.title() etc. Element TACO dict JSON over SSE bitwrench renders DOM Browser DOM

TACO Format

Every UI element is represented as a TACO dict:

{
    "t": "div",            # Tag
    "a": {"class": "..."},  # Attributes
    "c": "Hello",           # Content
    "o": {"id": "el-1"}     # Options (bwserve metadata)
}

TACO stands for Tag, Attributes, Content, Options. This is the wire format between Python and bitwrench.

bwserve Protocol

Server → Browser (SSE)

The server sends JSON messages over Server-Sent Events. Message types:

TypePurpose
initInitial page load — full element tree
patchUpdate a specific element by ID
callInvoke a bitwrench function (e.g. bw.loadStyles)
removeRemove an element from the DOM

Browser → Server (POST)

User interactions (button clicks, slider changes) are sent as POST requests with a JSON payload containing the widget ID, event type, and new value. The server dispatches these to registered callbacks.

Session Management

Each browser tab gets a unique session (via client ID). Sessions hold:

Python Server SessionMgr Page Callbacks Elements Context Vars Browser bitwrench Chart.js DOM (rendered UI) SSE POST

Module Structure

ModulePurpose
taco.pyTACO dict creation and element building
_context.pyPage, Element, WidgetHandle, default page management
display.pyDisplay element functions (title, text, table, etc.)
widgets.pyInput widget functions (slider, button, select, etc.)
charts.pyChart.js integration (chart, plot)
layout.pyLayout containers (columns, tabs, grid, etc.)
theme.pyTheme presets and CSS generation
export.pyStatic HTML export
state.pySession, SessionState, SessionManager
server.pyHTTP server with SSE + POST handling
app.pyMulti-page App, PageContext, routing
options.pyGlobal configuration options
_shell.pyHTML shell template for served pages
_assets/Bundled bitwrench.js and Chart.js

Design Principles