A MATLAB utility for BPMN (Business Process Model and Notation) file generation from database data.
This repository contains MATLAB scripts and functions for creating, editing, and managing BPMN 2.0 files. The utility connects to databases to extract process information and generates standard-compliant BPMN XML files that can be imported into any BPMN-compatible tool.
src/- Core source code for BPMN generationtests/- Test scripts to validate functionalityexamples/- Example scripts demonstrating usagedoc/- Documentation
- Clone this repository to your local machine
- Add the repository folder to your MATLAB path:
addpath(genpath('/path/to/bpmnMATLAB')); - Configure your API access by creating a
.envfile in the project root with your API keys:# API Configuration OPENROUTER_API_KEY=your_openrouter_api_key_here - Run the examples to understand the functionality:
cd /path/to/bpmnMATLAB/examples SimpleProcessExample % Generate a simple BPMN diagram ComplexBPMNExample % Generate a complex BPMN diagram
- Check the documentation in the
doc/folder for detailed guides:DatabaseSchema.md- Detailed database schema descriptionDatabaseCompatibilityGuide.md- Comprehensive guide for database compatibilityAPIIntegration.md- Guide for API integration with OpenRouter
- MATLAB R2019b or newer
- Database Toolbox (for database connections)
- XML Toolbox (for XML handling)
- Internet connection (for API access)
To create a database-to-BPMN generator capable of handling any complexity, we need to implement the following functionalities:
-
Event Types
- Start Events (normal, message, timer, signal, conditional, error, escalation)
- End Events (normal, message, error, terminate, signal, compensation)
- Intermediate Events (catching/throwing for message, timer, error, compensation, signal)
- Boundary Events (interrupting/non-interrupting for message, timer, error, etc.)
-
Activity Types
- Tasks (user, service, script, business rule, manual, receive, send)
- Sub-processes (embedded, event, transaction, ad-hoc, call activity)
- Multi-instance activities (parallel/sequential)
- Loop activities
-
Gateway Types
- Exclusive (XOR)
- Inclusive (OR)
- Parallel (AND)
- Event-based
- Complex
- Parallel Event-based
-
Connecting Objects
- Sequence Flows (with conditions)
- Message Flows
- Associations
- Data Associations
-
Artifacts
- Data Objects
- Data Stores
- Text Annotations
- Groups
-
Swimlanes
- Pools (participants)
- Lanes (roles/responsibilities)
- Nested lanes
-
Correlation
- Correlation keys and properties
-
Conversations
- Conversation links
- Conversation elements
-
Choreographies
- Choreography tasks
- Sub-choreographies
-
Process Execution
- Transaction boundaries
- Compensation handling
- Error handling
-
Schema Design
- Process definition tables
- Element tables with element-specific attributes
- Relationship/flow tables
- Position/layout information tables
-
Data Mapping Capabilities
- Flexible mapping between database fields and BPMN elements
- Support for custom attributes and extensions
- Default positioning algorithms when coordinates not specified
-
Validation
- BPMN structural validation (correct connections, etc.)
- Semantic validation (process makes sense)
-
Automatic Layout
- Smart positioning of elements when not defined
- Avoiding element overlaps
- Optimizing flow paths
-
Style Management
- Colors, fonts, sizes
- Custom icons and markers
-
File Formats
- BPMN 2.0 XML
- SVG/PNG visualization export
- Import from existing BPMN files
-
Tool Integration
- Compatibility with Camunda, Activiti, jBPM
- Compatibility with modeling tools (Visio, draw.io)
For a database to properly represent BPMN processes and detailed product compositions, it should include the following tables and fields:
-
Process Tables
- Store process definitions and metadata (process ID, name, version, description, related product ID)
-
Element Tables
- Events: event ID, type (start, intermediate, end), kind (message, timer, error, etc.), catching/throwing flag, interrupting flag
- Activities: activity ID, type (task, sub-process, transaction, event sub-process, call activity), marker flags (loop, parallel MI, sequential MI, ad-hoc, compensation), callable reference
- Gateways: gateway ID, type (exclusive, inclusive, parallel, complex, event-based, parallel event-based), merging/branching semantics
- Flows: flow ID, type (sequence, conditional, default, message), source element ID, target element ID, condition expression
- Data: data object ID, type (data object, data store, input, output, collection), persistence, associations (input/output references)
- Pools & Lanes: pool ID, name, type (black/white box), lane ID, hierarchical parent reference
- Conversations & Collaboration: conversation ID, sub-conversation reference, conversation links (source, target)
- Choreographies: choreography ID, type (task, sub-choreography, call choreography), participants, multiple markers
-
Relationship/Flow Tables
- Map connections between elements: sequenceFlow, messageFlow, association, dataAssociation
-
Position/Layout Tables
- Coordinates, dimensions (width/height), docking information for diagram rendering
-
Property Tables
- Custom attributes and extension elements associated with any BPMN element
-
Product Composition Tables
- Products: product ID, name, description, version
- Parts: part ID, name, description, parent product ID
- Assembly Processes: process ID, part ID, sequence order, dependency references (sub-process IDs)
-
Example Configuration Tables
- Templates or sample configurations to drive example-driven BPMN generation (e.g., product assembly workflow, part-specific subprocess flows)
This project now uses the OpenRouter API with the microsoft/mai-ds-r1:free model for AI-assisted BPMN generation. To use this feature:
- Sign up for an account at OpenRouter
- Create an API key and add it to your
.envfile - Run the initialization script to set up your environment:
initAPIEnvironment();
For more details on API integration, see doc/APIIntegration.md.
This project includes a utility script generate_bpmn_data.m that leverages an AI model (via OpenRouter) to iteratively generate BPMN process data based on a textual description of a product or process.
You can run the script from the MATLAB command window:
generate_bpmn_data(productDescription, batchSize, outputFile, options)Arguments:
productDescription(string): A brief description of the product or process you want to model (e.g., 'Assembly process for a bicycle').batchSize(integer): The number of data rows to generate per table in each iteration. Controls the granularity of the generation process.outputFile(string): The path where the generated BPMN XML data should be saved (e.g., 'output/generated_bicycle_process.xml').options(struct, optional): A structure to provide additional configuration:options.model(string): Specify the LLM model to use (default: 'microsoft/mai-ds-r1:free').options.temperature(double): Controls the creativity/randomness of the LLM output (default: 0.7).options.debug(logical): Set totrueto enable verbose debug output (default:false).
Example:
% Simple generation
generate_bpmn_data('Manufacturing process for a smartphone', 10, 'output/smartphone_process.xml')
% Generation with custom options
options = struct('model', 'anthropic/claude-3-haiku-20240307', 'temperature', 0.5);
generate_bpmn_data('Order fulfillment workflow', 5, 'output/order_fulfillment.xml', options)Prerequisites:
- Ensure your API environment is configured correctly as described in the "API Integration" section above.
- Make sure the necessary source directories (
src/,src/api/,src/util/) are added to your MATLAB path. The script attempts to do this automatically, but manual path management might be needed in some environments.
- Generate comprehensive BPMN for a single product with subparts: automated creation of hierarchical subprocesses to represent product assembly, quality checks, packaging, and validation flows.
- Visualization export (SVG/PNG) for example product BPMN models, with style customization for parts and processes.
- Enhanced validation: structural and semantic checks tailored to product-specific workflows and subpart interactions.
- Style management: custom icons, color schemes, and layout optimizations for clear representation of complex product assemblies.
- One‑shot data generation mode: full-schema, one‑call generation via LLM will be implemented in a future release.
For detailed database schema guidance, refer to doc/DatabaseSchema.md.
To complete today’s session and get the full test suite passing, we will:
-
Fix TestBPMNGenerator setup:
- Introduce and initialize
repoPathin TestBPMNGenerator or switch to a reliableprojectRootvariable. - Update file paths to use
projectRootto locatedoc/temporaryoutput.
- Introduce and initialize
-
Repair BPMNDatabaseConnector syntax:
- Close missing
endstatements insrc/BPMNDatabaseConnector.mto resolve the syntax error.
- Close missing
-
Implement missing BPMNGenerator methods exercised by TestBPMNSuite:
- addStartEvent, addExclusiveGateway, addParticipant
- Expose boundary-event helper that delegates to XML node attributes
- Update data-object and association methods to match test signatures
-
Add an intermediary bridge between DataGenerator and BPMNGenerator:
- Create a new class (e.g.
DataToBPMNBridge) undersrc/bridges/ - Bridge responsibilities:
- Consume raw table data from
DataGenerator - Invoke
BPMNGeneratormethods to translate rows into BPMN elements - Provide batch and error-handling support
- Consume raw table data from
- Create a new class (e.g.
-
Update tests and examples to use the bridge:
- Modify relevant tests (TestBPMNGeneration, TestProductDataGeneration) to route through
DataToBPMNBridge.
- Modify relevant tests (TestBPMNGeneration, TestProductDataGeneration) to route through
-
Re-run
runAllTests.mand iterate on any remaining failures.
BPMN2_0_Poster_EN.pdf
compile_bpmn_tools.m
generate_bpmn_data.m
generate_bpmn_export.m
generate_bpmn_main.m
README.md
doc/
APIIntegration.md
DatabaseCompatibilityGuide.md
DatabaseSchema.md
temporary/
examples/
AdvancedBPMNFeatures.m
ComplexBPMNExample.m
DatabaseBPMNExample.m
OptimizedLayoutExample.m
SimpleProcessExample.m
output/
src/
BPMNDatabaseConnector.m
BPMNDiagramExporter.m
BPMNElements.m
BPMNGenerator.m
BPMNLayoutOptimizer.m
BPMNStyleManager.m
BPMNToSimulink.m
BPMNValidator.m
api/
APICaller.m
APIConfig.m
DataGenerator.m
GeneratorController.m
initAPIEnvironment.m
PromptBuilder.m
SchemaLoader.m
ValidationLayer.m
util/
loadEnvironment.m
setEnvironmentVariables.m
tests/
runAllTests.m
SimpleOpenRouterTest.m
TestAPIConnection.m
TestBPMNGeneration.m
TestBPMNGenerator.m
TestBPMNSuite.m
TestOpenRouterAPI.m
TestSchemaValidation.m