Creating MTK Components Graphically
Applies to: CoModel cloud modeling & simulation platform (v1.8+)
1. Overview
Creating MTK components graphically (composite components) lets you combine multiple standard library components, custom components, FMU or AI components into one higher-level reusable component. Composite components correspond to the subsystems, modules, and similar abstractions of an application scenario — an RC filter, a motor drive unit, a thermal management loop.
Modular encapsulation within models is done uniformly through composite components, which:
- are saved independently as library files;
- can be reused across multiple models / composite components;
- are, in essence,
@component functiondefinition files; - can be nested inside other composite components.
2. Entering the editor
2.1 Creating a new composite component
- Click Components in the left navigation bar, then MTK Components, to open the My MTK Components page.
- Click the Graphical Component button at the top right.
- You enter
/mtks/graph/new.
2.2 Editing an existing composite component
- In the My MTK Components list, find a file whose source is
Graphical. - Click the Graphical Editor icon in the Actions column.
- You enter
/mtks/graph/edit?id={file ID}.
3. Page layout
From top to bottom:
| Area | Position | Description |
|---|---|---|
| Breadcrumb bar | Top | Shows My Component Libraries / New Graphical Component or My Component Libraries / Edit Graphical Component: {name}; click it to return to the list |
| Toolbar | Below the breadcrumb | Name input, panel tabs, Save / Finish / Cancel |
| Editor body | Middle | Two panels switched by the Graph Definition / Code View tabs |

Toolbar layout (left to right):
| Control | Description |
|---|---|
| Composite component name input | Sets the display name; required on save; saving with an empty name is blocked and the field is highlighted red and focused |
| Graph Definition / Code View tabs | Switch between the two panels |
| Unsaved-changes indicator | Shows an amber dot with Unsaved changes when there are unsaved edits |
| Save button | Ctrl+S; enabled when there are changes; after saving you stay on the page |
| Finish button | Saves and returns to the My MTK Components list |
| Cancel button | Discards changes and returns (with a second confirmation when there are unsaved changes) |
The composite component's icon is not set here: after saving, return to the My MTK Components list and assign or change the icon through Meta Info in the Actions column (see Component Icon System Overview).
The Graph Definition panel has three columns:
| Area | Position | Purpose |
|---|---|---|
| Available component tree | Left | MTK standard library (two-level grouping by module), user components (including FMU / AI components), and Official Components; searchable |
| Canvas | Middle | Drag components, draw connections, adjust layout |
| Properties panel | Right | Editable properties of the selected member, connection, or endpoint; when nothing is selected, shows the composite component's own properties |
4. Graph Definition panel
4.1 Dragging in member components
Drag a standard library or custom component from the tree on the left onto the canvas and it becomes a member of the composite component. FMU and AI components can be dragged in as members too, mixed with physical components. Member instantiation follows the same rules as system modeling; parameter overrides are written into the generated code as inline literals.
With a member selected, the top of the properties panel shows its instance name, component name, and description, plus a Delete Member button; member parameters can be edited directly in the panel.
4.2 Exposing ports
A composite component must expose endpoints so other models / components can connect to it. Steps:
- Select a member component on the canvas.
- Find the target port in the properties panel on the right.
- Click Expose as Endpoint.
- The system generates an endpoint name automatically (e.g.
p1,p2) and shows the endpoint node on the canvas edge. - Double-click the endpoint node on the canvas to rename it (duplicate names are rejected).

The system infers the Connector type of the external endpoint from the type of the port being exposed:
| Exposed port port_type / domain | Generated Connector type |
|---|---|
acausal + electrical |
Pin |
acausal + thermal |
HeatPort |
acausal + mechanical |
Flange |
input + signal / control |
RealInput |
output + signal / control |
RealOutput |
When inference is unreliable, no default type is forced: the endpoint shows a warning marker in the properties panel along with a connector type dropdown (Pin / HeatPort / Flange / RealInput / RealOutput). You must select the correct type manually, otherwise the save is blocked.
Select an exposed endpoint in the member's port list and click Unexpose to remove it from the composite component's external endpoints.
4.3 Connecting members
Connections between members follow the same rules as system modeling:
| Source port | Target port | Allowed |
|---|---|---|
acausal same domain |
acausal same domain |
✅ |
output |
input |
✅ |
input |
input |
❌ |
output |
output |
❌ |
acausal |
input / output |
❌ |
Each connection generates the corresponding connect(...) equation, placed in the composite component's eqs array. With a connection selected, the properties panel lets you set its label, color, and bend points.
5. Parameter promotion
A composite component can promote a member component's parameters to its own, so they can be configured from outside when the composite component is used.
5.1 Promoting a parameter
- Select a member component on the canvas.
- Find the target parameter in the properties panel on the right.
- Click the Promote Parameter button next to the parameter.
- The parameter is:
- added to the
@componentfunction signature'skwargs(e.g.R1=1.0) - added to the
@parametersblock - referenced in the member instantiation code as the composite component parameter (e.g.
Resistor(R=R1))
- added to the

5.2 Unpromoting
A promoted parameter shows an Unpromote button next to it. After clicking:
- the parameter is removed from the composite component signature and the
@parametersblock - the member instantiation reverts to an inline literal with the default value
5.3 Editing promoted parameters
With no member selected, the properties panel shows the composite component's own properties in two groups:
- Endpoint Name: lists all exposed endpoints and their connector types; endpoints whose type could not be inferred can be set here;
- Promoted Parameters: lists all promoted parameters, where you can edit:
- the parameter name (duplicate names get a red border)
- the default value
6. Code View panel
The Code View panel shows the @component function code generated from the graph definition in a full-width Monaco editor (read-only, dark theme, titled Code Preview). Any graphical change — dragging, connecting, promoting parameters, exposing endpoints — refreshes the code preview automatically after an 800 ms debounce; when code generation fails, the error details are shown in the panel.
Example: composite component code generated from two series resistors
using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
using ModelingToolkitStandardLibrary.Electrical: Pin, Resistor
@component function two_resistors(; name, resistor1_R=1.0, resistor2_R=1.0)
pars = @parameters begin
resistor1_R = resistor1_R, [description = "Reference resistance"]
resistor2_R = resistor2_R, [description = "Reference resistance"]
end
@named resistor1 = Resistor(R=resistor1_R, T_ref=300.15, alpha=0)
@named resistor2 = Resistor(R=resistor2_R, T_ref=300.15, alpha=0)
@named p1 = Pin()
@named p2 = Pin()
eqs = [
connect(resistor1.n, resistor2.p),
connect(p1, resistor2.n),
connect(p2, resistor1.p),
]
return System(eqs, t, [], pars; systems=[resistor1, resistor2, p1, p2], name=name)
end
7. Saving and finishing
7.1 Save button
Click Save or press Ctrl+S (when there are unsaved changes):
- Validates that the composite component name is not empty
- Validates member integrity and endpoint / parameter naming (see §8)
- Calls the code generator to produce
@componentcode from the graph definition - Runs syntax validation, detecting naming conflicts and circular references
- Persists to the library file
On success it shows Saved successfully and you stay on the page to continue editing. On failure (validation error or network error), a red error banner appears at the top of the page.
7.2 Finish button
Click Finish:
- the save flow runs first
- on success, the editor closes and returns to the My MTK Components list
7.3 Cancel button
Click Cancel:
- if there are unsaved changes, it asks "You have unsaved changes. Leave anyway?"
- choosing Cancel keeps you on the page
- otherwise it returns to the list
In addition, closing or refreshing the browser tab with unsaved changes triggers the browser's leave confirmation.
7.4 Naming conflicts
If a component name collides with one of your other libraries, the back end returns 409 Conflict on save and an amber banner appears at the top of the page listing the conflicting names. Rename the component and save again (the banner itself offers no overwrite action).
8. Validation rules
The following validations run on save:
| Check | Pass condition | Failure behavior |
|---|---|---|
| Name not empty | Display name is not empty | Input is highlighted red and focused; nothing is submitted |
| At least one member | At least one component has been dragged onto the canvas | Warning shown; nothing is saved |
| Member integrity | Every member has a connection or an exposed endpoint | Isolated member names are reported; nothing is saved |
| Endpoint names unique | No two exposed endpoints share a name | Duplicate names are reported; nothing is saved |
| Connector type | Endpoints with failed or missing inference have a manually selected type | Endpoints needing a selection are reported; nothing is saved |
| Promoted parameter names unique | Promoted parameter names are all distinct (red border warning while editing) | Duplicate names are reported; nothing is saved |
| Icon endpoint consistency | Exposed endpoint names match the icon's data-port anchors |
Mismatched endpoints are reported; change or remove the icon in Meta Info, or rename the endpoints |
| Syntax validation | Generated code passes syntax parsing | Error reported; nothing is saved |
| Naming conflicts | No name collides with your other libraries | 409 returned; conflict banner displayed |
| Circular reference | The composite component does not contain itself directly or indirectly | Circular reference path is reported; nothing is saved |
For the detailed icon endpoint consistency rules, see Component Icons & Port Anchors.
9. Using composite components
The saved composite component appears in the User Components group of the Component Browser, where you can:
- drag it onto a model canvas like a standard library component
- nest it inside other composite components
- use it in code generation and simulation
The composite component's .jl file reaches the simulation sandbox through the existing mechanism — no extra configuration needed.
10. FAQ
Q1: Why can't a saved composite component be deleted?
If the composite component is in use by other components or system models, deletion is refused and the referencing objects are listed, so existing models do not lose the ability to regenerate code.
Q2: Can a composite component contain itself?
No. Circular references are detected on save: if A contains B and B contains A, the save is blocked and the circular path is reported.
Q3: Why does the Code View panel sometimes not update immediately?
An 800 ms debounce avoids regenerating code on every interaction. Wait a moment after you stop and the preview refreshes; if an error persists, check the member or connection configuration against the error details.
11. Next steps
- For the component code conventions, read Julia Component Code Conventions.
- To upload existing
.jlfiles, read Uploading MTK Component Files.