Guide: Work on the Web App
How the web app is built, how to run it with a scripted agent, its conventions, and how to add a page with its tests.
On this page
Guide: Work on the Web App
This guide is for people who change the web app itself, in this repository. To use the app in an agent you need none of it: bxAgents build installs it, already built.
The app is a ColdBox module, bxagentsui, built the cbGenesis way: handlers, views and partials in BoxLang, and the scripts and styles (Alpine.js and Sass) built by Vite. It is a client of the agent API: a handler picks a view, and the page's Alpine component reads its data from /__bxagents.
The rules and the full tables of building blocks are in ui/AGENTS.md. Read it before you change the app. This guide is the tour.
Where things are
| Part | Path |
|---|---|
The module: ModuleConfig.bx, config/Router.bx, handlers/, layouts/, views/, models/ | src/main/bx/bxagentsui/ |
| Partials | src/main/bx/bxagentsui/views/_components/{app,ui}/ |
| Sass: tokens, base, layouts, components, views, in that order | ui/resources/assets/scss/ |
Alpine: App.js, stores/, components/<domain>/, utils/ | ui/resources/assets/js/ |
The Vite build, not committed (made by ./gradlew uiBuild) | src/main/bx/bxagentsui/includes/build/ |
| The dev agent and its scripted model | ui/dev/agent/, ui/dev/model.json |
| Project shapes (other paths, a password, no accounts) | ui/dev/shapes/ |
| Browser tests | ui/tests/e2e/, ui/tests/shapes/ |
| Tours for screenshots and video | ui/tests/media/ |
How an agent gets it
For each gateways/*.bx entry with exposes: "webui", the build (WebAppModule) copies the module to .build/app/modules/bxagentsui, puts the built scripts and styles (includes/build/assets) where the browser fetches them, in .build/public/includes/bxagentsui/build/assets (the module's own folders are not under the web root), and writes config/bxagentsui.json: where the app is mounted (basePath, the entry's path), where the agent API is (apiBase), the branding, the theme, and the files of the project's extensions. ModuleConfig.bx reads that file when ColdBox registers the module, so the module answers at the entry's path.
The build of the scripts and styles is not committed: ./gradlew shadowJar (through uiBuild) writes it to includes/build and the module carries it, so an agent build never runs Node. Building this repository needs Java and Node 24 (ui/.nvmrc); there is no way to skip it, and the build fails with what to install when Node is missing or another major.
With BXAGENTS_UI_LINK=true the build links the module instead of copying it (and links public/includes/bxagentsui to the module's includes folder), so a change to a view shows on the next request. npm run stack sets it. Only a linked module serves <path>/_kit, a page with every partial and magic working; a built agent answers 404 there.
Set it up once
From the repository root:
./gradlew downloadBoxLang shadowJar
cd ui && npm install # Node 24 (nvm use) and Java are both required
npx playwright install chromium # if you have no Playwright browser yet
Run it
npm run dev # the dev agent, its model and the Vite dev server
npm run stack # the dev agent and its model only, with the build of the scripts and styles (run `npm run build` first)
The app is at http://127.0.0.1:8780/chat. Sign in as ada (an admin) or bob (a member), password demo-pass.
In npm run dev a change to a view or a layout shows on reload, and a change to the Sass or a script reloads the page by itself. A change to a handler, a model or ModuleConfig.bx needs the stack restarted (Ctrl+C, then npm run dev again). npm run dev -- --no-build starts without building the agent again.
The dev agent and its scripted model
The dev agent is ui/dev/agent, built and served by this repository's own bxAgents. Its model is scripted: ui/dev/model.json, served by tools/demo/fakellm.bxs. Nothing needs a key or the network.
| Ask | You get |
|---|---|
| "what time is it" | a call to the now tool, then the answer |
| "give me a list" | Markdown: a numbered list and a code block |
| anything else | a plain answer that names the model |
The agent has two profiles (fast, planner), notes, a vault, routines and one folder extension, panel (see extensions). It keeps its data in ui/.stack/home: delete that folder to start fresh. UI_AGENT_PORT and UI_LLM_PORT move the ports (8780 and 8080).
Build
npm run build # builds only the web app, into src/main/bx/bxagentsui/includes/build
The output is ignored by git. ./gradlew shadowJar builds it too (./gradlew uiBuild alone), so a module build always carries a fresh one.
Conventions
The full list is in ui/AGENTS.md. In short:
- Handlers are thin. They pick the layout and the view and check who may see the page. The data comes from the agent API through the page's Alpine component. No business logic in a handler.
- Partials document their args in a header comment and declare each one with
<bx:param name="args.x" default="..."/>. Call one withview( view = "_components/ui/name", module = "bxagentsui", args = { ... } ). - Escape what the server writes with
encodeForHTML(). Data for the scripts goes throughPageData.json()into a<script type="application/json">block, never into a script. - No server value inside
x-,:or@attributes. They run as code. Put the value in adata-attribute and read it in the expression ($el.dataset.x) or ininit(). - Every colour is a token in
abstracts/_tokens.scss, so the dark theme and the gateway'sthemeblock work. - One Alpine factory per file, registered in
App.jswithAlpine.data( "name", factory ), with JSDoc on every function, getter and store member. - Bind boolean attributes to a real boolean (
:disabled="!!t.locked"), never to a value that can beundefinedornull. - Accessible by default: a skip link, a visible focus ring, dialogs that hold and give back the focus, and an
aria-labelon an icon-only button that starts with its visible text, if it has any. - A change needs a test: a browser test for what a person sees, a TestBox spec for BoxLang code.
The building blocks
Use these before you write markup or logic of your own. ui/AGENTS.md has each one with its args.
Partial (views/_components/ui/) | What it is |
|---|---|
page-head | A page's title, a line under it and its actions |
tabs | A row of tabs (an ARIA tablist) bound to a component variable |
search | A search box with a debounce |
chip | A state or a count (ok, warn, bad) |
card | A box that holds another view |
field | Label, control, help line and error line |
switch | An on and off toggle, a real checkbox |
modal, drawer | A native <dialog>, centred or at the side, that holds another view |
table | A table that scrolls on a phone, rows from Alpine |
empty | What a list shows when it has nothing |
icon | One icon of the set |
toasts, confirm | In the layout once: the message region and the question dialog |
| Magic or store | What it does |
|---|---|
$api.get( path )`, `$api.post( path, body ) | Calls the agent API. Answers { ok, status, data, error }, never throws |
$sse( path, { body, onEvent, signal } ) | A stream of the agent API |
$confirm( { title, body, danger } )`, `$prompt( { title, label, value } ) | The app's own dialogs; never window.confirm or window.prompt |
$toast.success( text )`, `$toast.error( text ) | A short message |
$md( text ) | Markdown as safe HTML, the only input x-html takes |
$fmt | Dates, sizes and counts, the same everywhere |
$tabKeys( $event ) | The arrow, Home and End keys of a tab row |
$store.session | What this person may use: can( capability ), agentName, agents; await loaded() first in init() |
$store.theme`, `$store.appearance, $store.nav | Light or dark; accent, text size and density; the folded menu and the phone drawer |
$store.password | The password of an agent without accounts, sent with every call |
window.bxagents is the extensions' contract, see extensions.
Add a page
A page is a route, a menu entry, a handler, a view and an Alpine component. Say the page is reports.
-
The route. In
config/Router.bx, addroute( "/reports" ).to( "Reports.index" )above the last route. The last route sends every other address toMain.missing, which answers 404. -
The menu. In
models/Menu.bx, add the page toPAGES:{ id : "reports", title : "Reports", icon : "chart-line", group : "main", capability : "" }. The left menu draws itself from that list.capabilityis the capability ofGET /agentthe page needs (""for everybody,"a|b"for either,"~a"for "unlessais false"). A page in theadmingroup answers 403 to a member who is signed in. -
The handler.
handlers/Reports.bxextendsBaseHandlerand has oneindex():class extends="BaseHandler" { function index( event, rc, prc ) { showPage( event, prc, "reports", "reports/index" ) } }showPage()answers 404 for a page that is not in the menu and 403 for an admin page to anybody else, so every page follows the same rule. -
The view.
views/reports/index.bxmstarts with<div class="pg" x-data="reportsPage">and thepage-headpartial. A value the component needs from the server goes in adata-attribute, escaped withencodeForHTML(). -
The component.
ui/resources/assets/js/components/reports/ReportsPage.jsexports one factory,reportsPage(), registered inApp.jswithAlpine.data( "reportsPage", reportsPage ). It reads its data with$apiininit(). A tab or a filter the address should keep goes throughkeepInAddress()(utils/address.js). -
The styles, if the partials are not enough: a file under
scss/views/, used inapp.scss, with tokens for every colour. -
The tests. Add
"reports"toPAGESinui/tests/e2e/a11y.spec.js(and toMEMBER_PAGESwhen a member sees it), and write a browser test inui/tests/e2efor what a person does on the page. Runnpm run e2e:shapestoo: a change to routes, paths or the frame must work under every project shape. -
The build.
npm run buildto see it innpm run stack; the build is not committed, and./gradlew shadowJarmakes it for the module.
A change to the router, the menu or a handler needs the stack restarted.
Lint
npm run lint # ESLint, the scripts (lint:fix fixes what it can)
npm run lint:scss # Stylelint, the Sass (lint:scss:fix)
npm run lint:md # markdownlint: docs/, changelog.md, readme.md and the notes in ui/
The rules are cbGenesis': eslint.config.mjs, .stylelintrc.json, and .markdownlint.json and .bxlint.json at the repository root. CI fails on any finding.
Test
npm test # the unit tests of the scripts (Vitest)
npm run e2e # every browser test, against a stack it starts (or the one already running)
npm run e2e:headed # the same, with the browser on screen
npm run e2e:shapes # every page under other project shapes
The browser tests sign in once as each account, start every chat test on a new conversation, and fail on any error the page throws. Two of them check the whole app:
a11y.spec.jsruns axe-core (WCAG 2.2 AA) on every page, as an admin and a member, light and dark, desktop and phone, and with the dialogs open. A serious or critical finding fails.keyboard.spec.jschecks the skip link, a visible focus ring on every Tab stop, dialogs that hold and give back the focus, and reduced motion.
npm run e2e:shapes builds the dev agent again for each folder of ui/dev/shapes, serves them side by side on ports 8791 and up, and checks that every page answers, draws its frame, links its files and extensions under its path, and talks to its API:
| Shape | Path | Sign in |
|---|---|---|
open-support | /support | none, an open API, a Phosphor icon and a theme accent |
password | /chat | the API's shared secret, with the password dialog |
nested-api | /team/assistant | none, with the agent API at /team/api |
Add a folder to ui/dev/shapes (a gateways/chat.bx and a shape.json) to test another shape.
Proof on a pull request
Each pull request that changes the app carries screenshots and a short video of the change. Write a tour in ui/tests/media/<name>.tour.js that walks the flow and calls shot( "what-it-shows" ) at each step. Then, with the stack running:
npm run media -- <name> # .stack/media/<name>/: NN-*.png, tour.mp4, tour.gif
Publish the folder on the pr-media branch, never on a code branch, under <pr-number>/, and link the files in the pull request: the GIF and the screenshots show inline, the MP4 is a link.