Best practice for creating process programmatically

i need to create elements in my bpmn process programmatically
i want the user to create a simple tree which will hide a bpmn sub-process, i don’t want the user to be aware of the bpmn-elements (for example sub-process), thus he will see simple tasks.

what are the best practices to create elements programmatically, and where i can find examples ?

example of my flow:

  1. user will click on add node
  2. a popup will open to the user to enter some applicaiton data
  3. i will need to create the connetions, gateway including expression, and a new sub-process which hide few tasks in it


What have you done already to achieve this? You can programmatically model diagrams using the modeling API only.

There exists two community projects that allow you to create diagrams using higher level APIs:

Both use the core modeling facilities @philippfromme mentioned under the hood.

You can use the Modeling API without abstractions, too:

var bpmnModeler = new BpmnModeler(...);

var modeling = bpmnModeler.get('modeling');
var elementRegistry = bpmnModeler.get('elementRegistry');

// remove shape with ID 'some
modeling.removeElements([ elementRegistry.get('someTask') ]);

according to the source code, i found different ways of creating the process
1.use ElementFactory to create shapes, then use the modeling api to append it to the viewer, in my case i found that AutoPlace class is better, since it provides simple layouting
2. use modeling.createShape for creating shapes, and modeling.connect for connecting between elements

and according to this example -
i see usage for moddle api.

so for me its unclear what is what, moddle, modeling, elementFactory ?

i already found the bpmn-js-cli, but wan’t sure if i can use it for creating my process. so i can use both the * bpmn-js-cli and the * bpmn-js-cli-modeling-dsl as a simpler API ?