Skip to content

matlab/matlab-agentic-toolkit / skills-catalog/matlab-app-building/matlab-build-app

matlab-build-app

Unverified

Build MATLAB apps from requirements to working code. Asks discovery questions (or skips them when the path is known), recommends UIFigure or UIHTML architecture, identifies layout archetype (Dashboard, Explorer, Tabbed, Wizard, Canvas), produces an implementation plan, and executes the build. For UIFigure apps, optionally serializes as App Designer (.mlapp or plain-text .m + .xml). Use when a user wants to build a MATLAB app, create a GUI, make an interactive tool, build a uifigure app, build a uihtml app, build an App Designer app, build a .mlapp app, build a plain-text App Designer app, or asks which approach to use. Also use when user describes spatial layout needs: dashboard, control panel, sidebar, tabs, wizard, stepper, canvas, workspace.

FileKindSize
SKILL.mdskill md20.9 KB
assets/colors_and_type.cssother12.8 KB
assets/minimal-bridge.htmlother1.3 KB
assets/minimal-bridge.mother1.2 KB
assets/standalone-chart-template.htmlother11.5 KB
manifest.yamlconfig672 B
references/app-designer/agent-guide-mlapp.mdmarkdown15.7 KB
references/app-designer/agent-guide-plaintext.mdmarkdown14.7 KB
references/app-designer/agent-guide-shared.mdmarkdown27.1 KB
references/app-designer/background-tasks.mdmarkdown4.8 KB
references/app-designer/plaintext/classdef-template.mdmarkdown11.3 KB
references/app-designer/plaintext/matlabAppSchema.xsdother16.8 KB
references/app-designer/plaintext/property-reference.mdmarkdown45.1 KB
references/app-designer/plaintext/xml-template.mdmarkdown12.3 KB
references/archetypes/canvas.mdmarkdown8.0 KB
references/archetypes/dashboard.mdmarkdown6.4 KB
references/archetypes/explorer.mdmarkdown5.7 KB
references/archetypes/tabbed.mdmarkdown6.6 KB
references/archetypes/wizard.mdmarkdown9.7 KB
references/background-tasks.mdmarkdown6.9 KB
references/editing-guide.mdmarkdown3.3 KB
references/timers.mdmarkdown2.1 KB
references/uifigure/callbacks.mdmarkdown3.0 KB
references/uifigure/components.mdmarkdown1.7 KB
references/uifigure/containers.mdmarkdown1.3 KB
references/uifigure/grid-layout.mdmarkdown4.9 KB
references/uifigure/guide.mdmarkdown5.3 KB
references/uifigure/layout-patterns.mdmarkdown1.5 KB
references/uifigure/mvvm-background-tasks.mdmarkdown3.9 KB
references/uifigure/mvvm-guide.mdmarkdown11.1 KB
references/uifigure/mvvm-testing.mdmarkdown2.8 KB
references/uifigure/mvvm-view-binding.mdmarkdown5.4 KB
references/uihtml/brand-design-tokens.mdmarkdown5.6 KB
references/uihtml/bridge-guide.mdmarkdown7.0 KB
references/uihtml/chart-bridge-integration.mdmarkdown7.5 KB
references/uihtml/chart-performance.mdmarkdown5.0 KB
references/uihtml/chart-type-selection.mdmarkdown3.1 KB
references/uihtml/chart-updates.mdmarkdown4.7 KB
references/uihtml/charting-guide.mdmarkdown3.9 KB
references/uihtml/chartjs-setup.mdmarkdown4.0 KB
references/uihtml/communication-patterns.mdmarkdown4.2 KB
references/uihtml/component-styles.mdmarkdown4.3 KB
references/uihtml/css-layout-patterns.mdmarkdown5.0 KB
references/uihtml/dark-mode.mdmarkdown3.8 KB
references/uihtml/data-types.mdmarkdown2.7 KB
references/uihtml/doughnut-scatter-charts.mdmarkdown6.0 KB
references/uihtml/error-handling.mdmarkdown4.6 KB
references/uihtml/external-color-schemes.mdmarkdown2.6 KB
references/uihtml/js-coding-guide.mdmarkdown11.2 KB
references/uihtml/js-testing-debugging.mdmarkdown2.9 KB
references/uihtml/line-bar-charts.mdmarkdown5.2 KB
references/uihtml/mvvm-guide.mdmarkdown11.0 KB
references/uihtml/mvvm-observable-classes.mdmarkdown2.9 KB
references/uihtml/mvvm-view-binding.mdmarkdown5.3 KB
references/uihtml/platform-limitations.mdmarkdown2.5 KB
references/uihtml/setup.mdmarkdown3.9 KB
references/uihtml/styling-guide.mdmarkdown8.1 KB
scripts/+module/+backgroundtask/BackgroundTaskModule.pbinary2.5 KB
scripts/+module/+backgroundtask/templates/cancelBackground.mother357 B
scripts/+module/+backgroundtask/templates/handleBackgroundComplete.mother1.4 KB
scripts/+module/+backgroundtask/templates/safeProgress.mother734 B
scripts/+module/+backgroundtask/templates/startBackground.mother1.2 KB
scripts/+module/AppBuilderModule.pbinary242 B
scripts/AppDesignerAgentInterface.pbinary12.6 KB
scripts/MlappBackend.pbinary9.4 KB
scripts/PlainTextBackend.pbinary10.2 KB

references/uihtml/mvvm-guide.md

View on GitHub
# UIHTML MVVM

Structure JavaScript web frontends using the Model-View-ViewModel pattern. This skill provides the architectural layer — observable state, ViewModels, View binding, and separation of concerns.

See `references/uifigure/mvvm-guide.md` for the MATLAB-side MVVM equivalent.

## Critical Rules

- MUST separate Model, ViewModel, and View into distinct modules or clearly separated code sections
- MUST use the Observable class for any ViewModel state that the View needs to react to
- MUST clean up subscriptions when Views are destroyed (prevent memory leaks)
- NEVER put DOM manipulation code in the ViewModel
- NEVER put business logic or data transformation in the View
- NEVER have the Model reference the ViewModel or View

## Architecture Overview

```
+------------------+     +-----------------------+     +------------------+
|      View        |     |      ViewModel        |     |      Model       |
|                  |     |                       |     |                  |
| DOM elements     |     | Observable properties |     | Data storage     |
| Event listeners -+---->| Commands (methods)    +---->| Business logic   |
| UI updates    <--+-----+ Presentation logic    |<----+ Validation       |
|                  |     |                       |     | Persistence      |
+------------------+     +-----------------------+     +------------------+
     subscribes to              updates
     ViewModel props            Model data
```

**Data flow:**
1. User interacts with View (click, type, slide)
2. View calls ViewModel command
3. ViewModel updates Model or its own state
4. Observable notifies subscribers
5. View updates DOM automatically

## Observable Classes

### Observable

A reactive value wrapper. When the value changes, all subscribers are notified. Supports `get value()`, `set value(newValue)`, and `subscribe(callback)` which returns an unsubscribe function.

### Computed

A derived observable that recalculates when its dependencies change. Created with `new Computed(computeFn, dependencies)`. Read-only value, subscribable.

See `mvvm-observable-classes.md` for the complete implementations of both classes.

Place both classes in `viewmodels/observable.js`.

## Model

The Model holds data and business logic. It has no knowledge of the UI.

```javascript
// models/data-model.js
export class DataModel {
    constructor() {
        this._data = {};
        this._listeners = new Set();
    }

    get data() {
        return this._data;
    }

    set data(value) {
        this._data = value;
        this._notifyListeners();
    }

    subscribe(callback) {
        this._listeners.add(callback);
        return () => this._listeners.delete(callback);
    }

    _notifyListeners() {
        this._listeners.forEach(cb => cb(this._data));
    }

    // Business logic methods
    processInput(input) {
        return { ...input, processed: true, timestamp: Date.now() };
    }

    // Persistence
    toJSON() {
        return structuredClone(this._data);
    }

    fromJSON(json) {
        this._data = json;
        this._notifyListeners();
    }
}
```

### Model Design Guidelines

- Keep Models pure — no DOM references, no ViewModel references
- Models can be tested independently of any UI
- For uihtml apps, the Model is often a thin wrapper around data received from MATLAB via the bridge
- Multiple ViewModels can share one Model (useful for split-pane UIs)

## ViewModel

The ViewModel exposes Model data as Observable properties and provides commands the View can invoke.

```javascript
// viewmodels/main-viewmodel.js
import { Observable, Computed } from './observable.js';

export class MainViewModel {
    constructor(model) {
        this.model = model;

        // Observable properties — View subscribes to these
        this.displayValue = new Observable('');
        this.isProcessing = new Observable(false);
        this.statusMessage = new Observable('Ready');
        this.errorMessage = new Observable('');

        // Computed property — derived from other observables
        this.canSubmit = new Computed(
            () => !this.isProcessing.value && this.displayValue.value !== '',
            [this.isProcessing, this.displayValue]
        );

        // React to Model changes
        model.subscribe(() => this._syncFromModel());
        this._syncFromModel();
    }

    // Commands — called by View in response to user actions

    processCommand(inputValue) {
        this.isProcessing.value = true;
        this.statusMessage.value = 'Processing...';
        this.errorMessage.value = '';

        try {
            const result = this.model.processInput(inputValue);
            this.model.data = result;
            this.statusMessage.value = 'Complete';
        } catch (error) {
            this.errorMessage.value = error.message;
            this.statusMessage.value = 'Error';
        }

        this.isProcessing.value = false;
    }

    resetCommand() {
        this.model.data = {};
        this.statusMessage.value = 'Reset';
        this.errorMessage.value = '';
    }

    // Private — sync ViewModel state from Model

    _syncFromModel() {
        const data = this.model.data;
        this.displayValue.value = data.processed
            ? JSON.stringify(data)
            : '';
    }
}
```

### ViewModel Design Guidelines

- Every piece of UI state should be an Observable on the ViewModel
- Commands are plain methods — the View calls them, the ViewModel does the work
- The ViewModel never references DOM elements or View methods
- Put presentation logic here (formatting, display strings, enabled/disabled state)
- For uihtml apps: the ViewModel typically sends events to MATLAB via the bridge and updates Observables when results come back

## View

The View creates DOM elements and binds them to ViewModel observables. See `mvvm-view-binding.md` for the complete MainView class pattern.

Key principles:
- All DOM creation and manipulation happens in the View only
- Use `subscribe()` to bind ViewModel observables to DOM updates
- Store unsubscribe functions and call them in `destroy()` to prevent leaks
- Wire user events (click, input) to ViewModel commands
- The View never talks to the Model directly

## Wiring It Together

### Entry Point (index.html)

```html
<script type="module">
    import { DataModel } from './models/data-model.js';
    import { MainViewModel } from './viewmodels/main-viewmodel.js';
    import { MainView } from './views/main-view.js';

    const model = new DataModel();
    const viewModel = new MainViewModel(model);
    const view = new MainView(viewModel, document.getElementById('app'));

    // Expose for console debugging
    window.app = { model, viewModel, view };
</script>

<div id="app"></div>
```

### With uihtml Bridge

When used in a uihtml app, the bridge feeds data into the Model and sends commands from the ViewModel:

```html
<script type="module">
    import { DataModel } from './models/data-model.js';
    import { MainViewModel } from './viewmodels/main-viewmodel.js';
    import { MainView } from './views/main-view.js';

    let model, viewModel, view;

    window.setup = function(htmlComponent) {
        window.htmlComponent = htmlComponent;

        model = new DataModel();
        viewModel = new MainViewModel(model);
        view = new MainView(viewModel, document.getElementById('app'));

        // MATLAB -> JS: update Model from bridge
        htmlComponent.addEventListener("DataChanged", function(event) {
            model.data = htmlComponent.Data;
        });

        htmlComponent.addEventListener("ResultReady", function(event) {
            model.data = event.Data;
            viewModel.statusMessage.value = 'Result received';
            viewModel.isProcessing.value = false;
        });

        htmlComponent.addEventListener("Error", function(event) {
            viewModel.errorMessage.value = event.Data;
            viewModel.isProcessing.value = false;
        });

        // Expose for debugging
        window.app = { model, viewModel, view };
    };
</script>
```

For the ViewModel to send data to MATLAB, add bridge-aware commands:

```javascript
// In MainViewModel
submitToMATLAB(data) {
    this.isProcessing.value = true;
    this.statusMessage.value = 'Sending to MATLAB...';
    window.htmlComponent.sendEventToMATLAB("ProcessData", data);
    // Response handled by bridge listeners that update Model
}
```

## When MVVM is Overkill

Skip MVVM and use direct event handlers when:
- The app has 2-3 controls with no shared state
- There is no two-way data flow (display-only or input-only)
- The app is ephemeral and maximum simplicity is preferred

In these cases, wire events directly in `setup()`:

```javascript
function setup(htmlComponent) {
    window.htmlComponent = htmlComponent;

    document.getElementById("btn").addEventListener("click", function() {
        htmlComponent.sendEventToMATLAB("DoThing", { value: 42 });
    });

    htmlComponent.addEventListener("Result", function(event) {
        document.getElementById("output").textContent = event.Data;
    });
}
```

## Directory Structure

```
my-app/
+-- index.html                  % Entry point
+-- models/
|   +-- data-model.js           % Data + business logic
+-- viewmodels/
|   +-- observable.js           % Observable + Computed classes
|   +-- main-viewmodel.js       % Bindable state + commands
+-- views/
|   +-- main-view.js            % DOM creation + binding
+-- utils/                      % Optional shared utilities
    +-- formatting.js
```

## Implementation Checklist

- [ ] Observable and Computed classes implemented in `viewmodels/observable.js`
- [ ] Model contains data and business logic only (no UI code)
- [ ] ViewModel exposes all UI state as Observables
- [ ] ViewModel commands handle user actions (no DOM references)
- [ ] View creates DOM and subscribes to ViewModel observables
- [ ] View stores unsubscribe functions and calls them in `destroy()`
- [ ] Entry point wires Model -> ViewModel -> View in dependency order
- [ ] For uihtml: bridge events feed into Model; ViewModel commands send to MATLAB
- [ ] Key objects exposed on `window.app` for console debugging

## Troubleshooting

| Issue | Cause | Solution |
|-------|-------|----------|
| View not updating when data changes | Not using Observable | Wrap ViewModel state in `new Observable(value)` |
| Stale data displayed | Subscribe missed initial value | `subscribe()` calls callback immediately with current value |
| Memory leak on view switch | Subscriptions not cleaned up | Call `destroy()` which runs all unsubscribe functions |
| ViewModel has DOM references | Incorrect separation | Move all DOM code to View; ViewModel only has Observables and commands |
| Circular updates | Observable triggers itself | `set value()` checks `!==` before notifying |
| Computed not updating | Missing dependency | Pass all source Observables in the dependencies array |

## References

| Topic | File | Description |
|-------|------|-------------|
| Observable classes | `mvvm-observable-classes.md` | Complete Observable and Computed class implementations |
| View binding | `mvvm-view-binding.md` | Complete MainView class, DOM binding, View design guidelines |

----

Copyright 2026 The MathWorks, Inc.

----
brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).Stars: 322kUpdated Claude CodeCodexVerifiedInstall
brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.Stars: 197kUpdated Claude CodeCodexVerifiedInstall
frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.Stars: 197kUpdated Claude CodeCodexVerifiedInstall
mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).Stars: 197kUpdated Claude CodeCodexVerifiedInstall