Frontend: panels, widgets and outputs
A module page is either a layout.json card grid built in the Studio, or a TSX panel. TSX (panels and widgets) is TypeScript regardless of the backend language; the platform bundles it with esbuild into .dist/ at startup, the Next.js build never sees your sources, and it may only import the packages listed in apps/web/lib/runtime-externals.json.
Choosing a page#
| Use | When | What renders |
|---|---|---|
layout.json | Text, parameters, run buttons, charts, tables and tabs are enough. The default; no TSX. | The module page renders the grid, with the log filter bar. |
panel/index.tsx | The page needs custom interaction. make new ID=x PANEL=1 scaffolds one. | With a layout too, the layout's tabs come first and the panel is the last tab, Panel. |
widgets/*.tsx | One card the catalog cannot draw, reusable on the module page and on dashboards. | A widget card in the layout, or a dashboard card. |
The Studio#
/dev/studio/<id> (from Dev → Open Studio, only with ENV=dev and DEMO_MODE=true; make lite sets both) edits layout.json inside the real module page: a 12-column grid of cards, the same grid dashboards use. Edit shows the palette and inspector as overlays; Preview renders the unsaved draft exactly as the module page will. Save writes modules/<id>/layout.json, Reload reloads the module like a hot reload, and clicking an action card runs the real route on the selected log.
| Kind | Shows | Needs |
|---|---|---|
text | Markdown, frameless on the page. | config.markdown |
controls | A form over the page params (source: params, from outputs' params_schema) or the module config (source: config, with Save). | module_id; optional config.keys (omitted or [] = all) |
action | A button that POSTs a module route. A @job route shows progress, then refetches the page's cards. | module_id, config.route |
viz | A platform visualization of one of the module's outputs; chart and field mapping are set in the inspector. | viz_id, output_ref |
widget | One of the module's frontend.widgets. | widget_id (plus module_id) |
text, controls and action exist only in layout.json; dashboards never offer them. Param values live on the page, shared by all tabs, and each viz card sends only the params its own output declares. Tabs adds, renames and deletes tabs ("tabs": [{"id": "overview", "title": "Overview"}]); a card without tab belongs to the first.
The palette's Visualizations section is the catalog, in six groups: Charts, Process models & graphs, Matrices, KPIs, Tables & lists, Text & status. Each row shows → <output> when the module has an output of a shape it accepts, else needs data. Adding a row binds the first compatible output; pick another under Data in the inspector. Without one, the card is a Needs data placeholder that shows the manifest outputs: item and the @route.get to paste. The Studio saves a placeholder, but make validate fails until it is bound.
When nothing in the catalog fits, scaffold a TSX widget: it writes widgets/MyWidget.tsx (a bar chart over the first output's route) and adds the frontend.widgets entry to the manifest. It appears in the palette's module group within seconds.
make widget ID=my_module NAME=my-widget # = uv run mate-module widget my_module my-widget [--title T] [--output O]
Every layout.json rule — tabs, params, actions, validation, and the route shapes each output accepts — is in docs/DEV_LITE.md.
Panels#
import type { ModulePanelProps } from "@mate/module-sdk-ts";
import { CardShell, KpiGrid, KpiTile, seriesColor } from "@mate/module-sdk-ts";
export default function Panel({ logId, moduleId }: ModulePanelProps) {
const { data, isLoading, isError } = useModuleData(moduleId, logId);
return (
<CardShell loading={isLoading} error={isError} empty={!data}>
<KpiGrid>
{data?.kpis.map((kpi, i) => (
<KpiTile key={kpi.id} title={kpi.title} value={kpi.value} accent={seriesColor(i)} />
))}
</KpiGrid>
</CardShell>
);
}
| Import | Use it for |
|---|---|
CardShell, CardSection, CardEmpty, CardError, InfoHint | The frame: loading, empty, and error states, plus scrolling. Never add your own scroll container inside it. |
KpiTile, KpiGrid | Headline figures with consistent typography. |
seriesColor(i), sequentialScale(t), divergingScale, statusColor(role), CHART_CHROME | Colour by job, not by look. |
variantHref(logId, id), activityHref(logId, name), useDrillParams(), DRILL_PARAMS | Links into the process page, encoded once. |
api, ApiError, subscribeBus, subscribeJob | Fetching with the session attached, and live updates. |
useWidget(moduleId, widgetId) | Embed another module's widget, lazily. |
<Link href={variantHref(logId, variant.id)}>{variant.label}</Link>
const kpis = await api.get(`/api/v1/modules/${moduleId}/kpis?log_id=${logId}`);
subscribeBus(["my_module.analysis.completed"], () => refetch());
Widgets#
frontend:
widgets:
- id: bottlenecks
entry: ./widgets/Bottlenecks.tsx
title: Bottlenecks
description: Slowest activities by median duration. # palette blurb
icon: Timer
default_w: 4 # grid units on the 12-column board
default_h: 9
min_w: 3
min_h: 6
min_px_w: 320 # pixel floors – the real minimums
min_px_h: 240
resizable: true # false locks the card to default_w/default_h
log_models: [case_centric]
help: { what: …, read: …, computed: … }
config_schema: { properties: { top_n: { type: integer, default: 8 } } }
kpis: [{ id: median, title: Median duration }]
views: [{ id: bars, title: Bar chart, exposes: [top_n] }]
drill: { module_id: performance, params: { view: bottlenecks } }
Sizing is the field to get right. Grid units keep the layout tidy but are relative to the board's width; the pixel floors are what actually keep a card readable. Measure them in the browser at exactly that size.
export default function Bottlenecks({ logId, config, onDrill }: WidgetProps) {
const scope = useCardScope(); // board filters and time range
const { data, isLoading, isError } = useBottlenecks(logId, {
topN: config?.top_n ?? 8,
scope,
});
return (
<CardShell loading={isLoading} error={isError} empty={!data?.items.length}>
<BarChart
data={data?.items ?? []}
fill={seriesColor(0)}
onClick={(bar) => onDrill?.({ params: { activity: bar.activity } })}
/>
</CardShell>
);
}
onDrill is undefined when a panel embeds the widget, so always call it optionally. Colour rules: one series means one colour; never shade a bar by its own length; fold a long tail into "Other"; use solid hairline gridlines; never build a dual-axis chart.
Canvases#
Graphs, maps, and diagrams render through CanvasShell, which provides the dotted grid, the minimap, the initial fit, the drag guard, and pseudo-fullscreen. Every control belongs in its settings popover (built from the CanvasSetting* primitives), expensive settings commit on release (onCommit), and a busy canvas keeps its last result instead of unmounting to show a spinner.
Outputs#
When the result is data rather than pixels, declare an output and skip React entirely:
outputs:
- id: ranking
title: Activity ranking
shape: table # table | graph | kpi | tree | blob
route: /ranking # one of your @route paths
params_schema: { properties: { top_n: { type: integer, default: 10 } } }
@route.get("/ranking")
async def ranking(self, ctx: ModuleContext, top_n: int = 10) -> dict:
payload = {
"shape": "table",
"columns": [
{"key": "activity", "title": "Activity", "type": "string"},
{"key": "events", "title": "Events", "type": "number"},
],
"rows": [...],
}
await ctx.cache.set(f"ranking:{top_n}", payload)
return payload
| Use an output when | Use a widget when |
|---|---|
| The result is tabular, a graph, or figures | The visual is the point |
| You want the platform's table, pagination, and export | You need bespoke layout or interaction |
| The same data should be readable by MCP tools | You are embedding another module's widget |