A TypeScript widget system built on Handlebars that provides reusable components for generating Markdown documentation. The framework allows you to create custom widgets.
Renders data as Markdown tables with support for nested objects and column filtering.
Options:
oritentation(vertical | horizontal): table layout (default: horizontal)headers(boolean): Show/hide table headers (default: true)columns(string): Comma-separated list of columns to includekey(string): Property to use as unique identifier (default: "unique-id")
Renders arrays as Markdown lists (ordered or unordered).
Options:
ordered(boolean): Create numbered list (default: false)property(string): Extract specific property from objects
Renders data as formatted JSON blocks.
Renders flows (sequence of transitions) as Mermaid sequence diagrams. Use this widget to visualise ordered interactions and connections between nodes defined in a CALM architecture context.
Options:
flow-id(string, required): The unique-id of the flow to render from the provided architecture context.
Context requirements:
- The context passed to the widget must be a valid CALM core canonical model (or a nested details object containing
nodes,relationships, andflows). flowsmust include a flow object with the specifiedunique-idand atransitionsarray.- Each transition must reference an existing relationship by
relationship-unique-idand include asequence-number(order) and optionaldescription.
Renders relationships as Mermaid graph diagrams, showing connections between nodes in a CALM architecture. This widget provides contextual filtering to display either all relationships for a specific node or details about a specific relationship.
Options:
node-id(string): Show all relationships involving this node. The node will be highlighted and all its connections (incoming, outgoing, and deployment relationships) will be displayed.relationship-id(string): Show details about a specific relationship by its unique-id.
Context requirements:
- The context must be a valid CALM core canonical model containing
nodesandrelationshipsarrays. - For
node-id: The specified node must exist in thenodesarray. - For
relationship-id: The specified relationship must exist in therelationshipsarray.
Supported relationship types:
- Interacts: Actor-to-node interactions (e.g., "User -- Interacts --> Frontend")
- Connects: Direct connections between services (e.g., "API -- Connects --> Database")
- Composed-of: Container composition relationships (e.g., "System -- Composed Of --> Service")
- Deployed-in: Deployment relationships (e.g., "Cluster -- Deployed In --> Service")
Output behavior:
- Node perspective: When using
node-id, shows the node highlighted with all its related connections - Relationship perspective: When using
relationship-id, shows just that specific relationship - Container filtering: Automatically filters relationships based on the focus node (container vs. service perspective)
Example outputs:
Node view (node-id="load-balancer") - Shows the load balancer and all its connections:
graph TD;
load-balancer[load-balancer]:::highlight;
conference-website -- Connects --> load-balancer;
load-balancer -- Connects --> attendees;
k8s-cluster -- Deployed In --> load-balancer;
classDef highlight fill:#f2bbae;
Renders a system architecture as a Mermaid flowchart with optional containers (systems), interfaces, highlights, and flow-focused slices.
What it shows
- Containers (systems) as Mermaid subgraphs, with contained nodes (services, dbs, etc.) inside.
- Optional interfaces as dotted attachments to their parent node.
- Edges for
connects/interactsrelationships, using the relationshipdescriptionas the label when present. - Highlights for any nodes listed in
highlight-nodes. - Optional clickable links per node/interface (via
link-prefixorlink-map).
Options
| Option | Type | Default | Description |
|---|---|---|---|
focus-nodes |
string (CSV) | — | Restrict the view to these node IDs (and, if containers are shown, their parent/child context per other options). |
focus-relationships |
string (CSV) | — | Restrict view to the specified relationship unique-ids. Only those relationships and the nodes they connect are included (plus containers per settings). |
focus-flows |
string (CSV) | — | Restrict edges to transitions that belong to the given flow unique-ids or names (case-insensitive). Only nodes touching those edges are included (plus containers per settings). |
focus-controls |
string (CSV) | — | Restrict view to nodes and relationships linked to the specified control IDs. Only nodes touching those controls are included (plus containers per settings). |
focus-interfaces |
string (CSV) | — | Restrict view to nodes and relationships linked to the specified interface IDs. Only nodes touching those interfaces are included (plus containers per settings). |
highlight-nodes |
string (CSV) | — | Nodes to visually highlight. |
render-node-type-shapes |
boolean | false |
If true, render nodes with different Mermaid shapes based on their node-type. Supports built-in CALM types: actor, database, webclient, service, system, messagebus. |
node-type-map |
stringified JSON map | — | Custom mapping of node types to built-in shapes, e.g. {"cache": "database", "queue": "messagebus"}. Only used when render-node-type-shapes is true. |
render-interfaces |
boolean | false |
If true, render each node’s interfaces as small interface boxes connected by dotted lines. |
include-containers |
'none' | 'parents' | 'all' |
'all' |
Which containers (systems) to draw. |
include-children |
'none' | 'direct' | 'all' |
'all' |
When focusing container nodes, include their direct/all descendants. |
edges |
'connected' | 'seeded' | 'all' | 'none' |
'connected' |
For non-flow views, expand visible set with directly connected neighbors. When flows are focused, only flow edges are shown. |
node-types |
string (CSV) | — | Only include nodes whose node-type is in this list. |
direction |
'both' | 'in' | 'out' |
'both' |
Reserved (currently not used by the renderer). |
edge-labels |
'description' | 'none' |
'description' |
Use the relationship description for edge labels; or hide labels entirely. |
collapse-relationships |
boolean | false |
If true, multiple relationships between same source and destination are collapsed into single edge with combined labels. |
link-prefix |
string | — | Prefix for clickable click links in Mermaid (e.g., /docs/ makes /docs/<node-id>). |
link-map |
stringified JSON map | — | Explicit per-id links, e.g. {"trade-svc": "/svc/trade"}. Map entries override link-prefix. |
Built-in Node Type Shapes
When render-node-type-shapes is enabled, the following CALM node types are rendered with distinctive Mermaid shapes:
actor→ Circle with person icon 👤database→ Cylinder shape with database icon 🗄️webclient→ Rectangle with web icon 💻service→ Rounded rectangle with gear icon ⚙️system→ Rectangle with system icon 🏢messagebus→ horizontal cylinder with web icon 📨 - this isn't in schema but think we need it
Sorting: Containers and nodes are always sorted alphabetically by label for stable layouts.
Context requirements
- The context must be a CALM core canonical model, e.g.
{ nodes, relationships, flows? }. - To use
focus-flows,context.flowsmust include the target flows. Each flow’stransitions[*].relationship-unique-idmust point to a relationship incontext.relationships.
Example Visual
For more examples, see the test fixtures:
- Basic structures
- Enterprise trading system
- Interface variations
- Focus flows
- Domain interaction
- Node type shapes
- Custom node type mapping
%%{init: {"flowchart": {"htmlLabels": false}}}%%
flowchart TB
classDef boundary fill:#f8fafc,stroke:#64748b,stroke-dasharray: 5 4,stroke-width:2px,color:#000;
classDef node fill:#ffffff,stroke:#1f2937,stroke-width:1px,color:#000;
classDef iface fill:#f1f5f9,stroke:#64748b,stroke-width:1px,font-size:10px,color:#000;
classDef highlight fill:#fef3c7,stroke:#f59e0b,stroke-width:2px,color:#000;
subgraph enterprise-bank["Enterprise Bank"]
direction TB
subgraph messaging-system["Messaging System"]
direction TB
message-bus["Message Bus"]:::node
message-bus__iface__trade-events-topic["◻ Trade Events Topic"]:::iface
end
class messaging-system boundary
subgraph trading-system["Trading System"]
direction TB
trade-svc["Trade Service"]:::node
trade-svc__iface__api["◻ API: /trades"]:::iface
trade-svc__iface__jdbc["◻ JDBC: trading-db"]:::iface
trade-svc__iface__events["◻ Topic: trade.events"]:::iface
trading-db["Trading DB"]:::node
trading-db__iface__sql["◻ SQL Interface"]:::iface
trading-ui["Trading UI"]:::node
trading-ui__iface__web-ui["◻ Web Interface"]:::iface
end
class trading-system boundary
end
class enterprise-bank boundary
trading-ui__iface__web-ui -->|Place Trade| trade-svc__iface__api
trade-svc__iface__jdbc -->|Persist| trading-db__iface__sql
trade-svc__iface__events -->|Publish Events| message-bus__iface__trade-events-topic
trading-ui -.- trading-ui__iface__web-ui
trade-svc -.- trade-svc__iface__api
trade-svc -.- trade-svc__iface__jdbc
trade-svc -.- trade-svc__iface__events
trading-db -.- trading-db__iface__sql
message-bus -.- message-bus__iface__trade-events-topic
class trade-svc highlight
class trading-ui highlight
class trading-db highlight
class message-bus highlight
click message-bus "#message-bus" "Jump to Message Bus"
click message-bus__iface__trade-events-topic "#message-bus__iface__trade-events-topic" "Jump to ◻ Trade Events Topic"
click trade-svc "#trade-service" "Jump to Trade Service"
click trade-svc__iface__api "#trade-service-api" "Jump to ◻ API: /trades"
click trade-svc__iface__jdbc "#trade-service-storage" "Jump to ◻ JDBC: trading-db"
click trade-svc__iface__events "#trade-service-events" "Jump to ◻ Topic: trade.events"
click trading-db "#trading-db" "Jump to Trading DB"
click trading-db__iface__sql "#trading-db__iface__sql" "Jump to ◻ SQL Interface"
click trading-ui "#trading-ui" "Jump to Trading UI"
click trading-ui__iface__web-ui "#trading-ui__iface__web-ui" "Jump to ◻ Web Interface"
%%{init: {"flowchart": {"htmlLabels": false}}}%%
flowchart TB
classDef boundary fill:#f8fafc,stroke:#64748b,stroke-dasharray: 5 4,stroke-width:2px,color:#000;
classDef node fill:#ffffff,stroke:#1f2937,stroke-width:1px,color:#000;
classDef iface fill:#f1f5f9,stroke:#64748b,stroke-width:1px,font-size:10px,color:#000;
classDef highlight fill:#fef3c7,stroke:#f59e0b,stroke-width:2px,color:#000;
subgraph enterprise-bank["Enterprise Bank"]
direction TB
subgraph messaging-system["Messaging System"]
direction TB
message-bus["Message Bus"]:::node
end
class messaging-system boundary
subgraph trading-system["Trading System"]
direction TB
trade-svc["Trade Service"]:::node
trading-db["Trading DB"]:::node
trading-ui["Trading UI"]:::node
end
class trading-system boundary
end
class enterprise-bank boundary
trading-ui -->|Place Trade| trade-svc
trade-svc -->|Persist| trading-db
trade-svc -->|Publish Events| message-bus
class trade-svc highlight
class trading-ui highlight
class trading-db highlight
class message-bus highlight
click message-bus "#message-bus" "Jump to Message Bus"
click trade-svc "#trade-service" "Jump to Trade Service"
click trading-db "#trading-db" "Jump to Trading DB"
click trading-ui "#trading-ui" "Jump to Trading UI"
Create a widget by implementing the CalmWidget interface:
// src/widgets/my-widget/index.ts
import { CalmWidget } from '@finos/calm-widgets';
export interface MyWidgetContext {
title: string;
items: string[];
}
export interface MyWidgetOptions {
showCount?: boolean;
prefix?: string;
}
export interface MyWidgetViewModel {
title: string;
items: string[];
count?: number;
prefix: string;
}
export const MyWidget: CalmWidget<
MyWidgetContext,
MyWidgetOptions,
MyWidgetViewModel
> = {
id: 'my-widget',
templatePartial: 'my-widget-template.html',
// Optional: additional template partials
partials: ['item-template.html'],
// Transform input data to view model
transformToViewModel: (context, options) => {
const showCount = options?.hash?.showCount ?? false;
const prefix = options?.hash?.prefix ?? '•';
return {
title: context.title,
items: context.items,
count: showCount ? context.items.length : undefined,
prefix
};
},
// Validate input context
validateContext: (context): context is MyWidgetContext => {
return (
typeof context === 'object' &&
context !== null &&
typeof (context as any).title === 'string' &&
Array.isArray((context as any).items) &&
(context as any).items.every((item: any) => typeof item === 'string')
);
},
// Optional: register custom helpers
registerHelpers: () => ({
upperCase: (str: string) => str.toUpperCase(),
repeat: (str: string, count: number) => str.repeat(count)
})
};Create Handlebars templates for your widget:
Create comprehensive tests for your widget:
// src/widgets/my-widget/index.spec.ts
import { describe, it, expect } from 'vitest';
import { MyWidget } from './index';
describe('MyWidget', () => {
describe('validateContext', () => {
it('accepts valid context', () => {
const context = {
title: 'Test Title',
items: ['item1', 'item2']
};
expect(MyWidget.validateContext(context)).toBe(true);
});
it('rejects invalid context', () => {
expect(MyWidget.validateContext(null)).toBe(false);
expect(MyWidget.validateContext({ title: 123 })).toBe(false);
});
});
describe('transformToViewModel', () => {
it('transforms context correctly', () => {
const context = { title: 'Test', items: ['a', 'b'] };
const options = { hash: { showCount: true, prefix: '-' } };
const result = MyWidget.transformToViewModel!(context, options);
expect(result).toEqual({
title: 'Test',
items: ['a', 'b'],
count: 2,
prefix: '-'
});
});
});
});Create test fixtures to verify widget output:
// test-fixtures/my-widget/basic-example/context.json
{
"title": "My Items",
"items": ["First Item", "Second Item", "Third Item"]
}<!-- test-fixtures/my-widget/basic-example/expected.md -->
## My Items
*Total items: 3*
→ FIRST ITEM
→ SECOND ITEM
→ THIRD ITEMThe framework includes comprehensive testing utilities:
# Run all tests
npm test
# Run specific widget tests
npm test -- my-widget
# Run with coverage
npm run test:coverageUse the fixture system for consistent testing:
import { FixtureLoader } from './test-utils/fixture-loader';
const fixtures = new FixtureLoader();
const { context, template, expected } = fixtures.loadFixture('my-widget', 'basic-example');
const compiledTemplate = handlebars.compile(template);
const result = compiledTemplate(context);
expect(result.trim()).toBe(expected);Use the fixture update script to regenerate expected outputs:
npx tsx src/scripts/update-fixtures.ts- WidgetEngine: Orchestrates widget registration and setup
- WidgetRegistry: Manages widget storage and Handlebars partial registration
- WidgetRenderer: Handles widget rendering with context validation
- Widget Helpers: Global Handlebars helpers available to all widgets
The framework provides built-in helpers:
eq,ne: Equality comparisonslookup: Property accessjson: JSON stringificationkebabToTitleCase: Convert "api-service" → "Api Service"kebabCase: Convert "API Service" → "api-service"isObject,isArray: Type checkingnotEmpty: Check for non-empty valuesor: Logical OR operationscurrentTimestamp,currentDate: Date utilitiesinstanceOf: Constructor name checkingeachInMap: Object iteration
The framework uses TypeScript generics for type-safe widgets:
CalmWidget<TContext, TOptions, TViewModel>TContext: Input data typeTOptions: Handlebars options/parametersTViewModel: Transformed data for template
- Keep widgets focused: Each widget should have a single responsibility
- Validate inputs: Always implement robust
validateContext - Transform data: Use
transformToViewModelto prepare data for templates - Handle errors gracefully: Provide meaningful error messages
- Test thoroughly: Include unit tests and integration fixtures
- Use semantic markup: Generate clean, readable Markdown
- Handle empty data: Gracefully handle missing or empty inputs
- Be consistent: Follow established patterns from built-in widgets
- Optimize performance: Avoid complex logic in templates
- Unit test widget logic: Test
validateContextandtransformToViewModel - Integration test output: Use fixtures to verify rendered output
- Test edge cases: Handle null, undefined, and malformed data
- Maintain fixtures: Keep expected outputs up to date
- Create your widget following the structure above
- Add comprehensive tests including fixtures
- Update documentation if adding new concepts
- Follow code style using the project's ESLint configuration
- Test thoroughly with
npm test