How processmaker/nayra works
Main Components
• BPMN Definition Loader/Repository: Represented by the BpmnDocument class (found in src/ProcessMaker/Nayra/Storage) which is responsible for loading BPMN definition files and instantiating process models.
• Process Engine: The engine (in src/ProcessMaker/Nayra/Engine) that creates execution instances, runs tokens to the next state, and coordinates the process execution.
• BPMN Models and Domain Objects: A large portion of the project resides in the BPMN subdirectory (e.g., Models, Traits, and individual BPMN elements like activities, gateways, events, transitions). These classes encapsulate the definition and behavior of BPMN elements (activities, start/end events, gateways, etc.).
• Contracts and Interfaces: The project defines a set of interfaces (in src/ProcessMaker/Nayra/Contracts) that enforce architectural boundaries and allow for dependency injection and abstraction (e.g., for BPMN elements, engine behaviors, repositories, and storage).
• Data Storage and Repository: Components to create and manage process data (e.g., DataStore from the repository and ExecutionInstance classes).
• Event and Token Management: Classes and traits that handle token passing, event propagation, and transitions (as seen in directories like src/ProcessMaker/Nayra/Bpmn/Events and the many traits for transitions and states).
Relationships and Interactions
• The BPMN Document Loader reads a BPMN file (e.g., “ParallelGateway.bpmn”) and creates a BPMN model. This model includes various BPMN elements (activities, gateways, events) that are defined using the Models and Traits.
• Once loaded, the BPMN Document is used to retrieve a specific process by its identifier, and then the Engine (using methods like createExecutionInstance() and runToNextState()) creates and manages the state of the process.
• The Engine interacts with other components (such as data storage/repository and token management modules) as it propagates tokens through the process based on BPMN semantics.
• All these components are aligned through the use of defined interfaces in the Contracts directories, ensuring that the implementation stays modular, replaceable, and testable.
• There is also an event bus and error handling layer (shown by the existence of Exceptions and Event-related classes) that enable robust process control and logging of discrete events.
Architectural Patterns and Design Principles
• Modularity and Abstraction: The system is divided using interfaces (contracts) and separate namespaces for BPMN definitions, engine logic, and storage.
• Separation of Concerns: The design clearly distinguishes the responsibilities of loading process definitions (BpmnDocument), executing processes (Engine), and modeling BPMN components (Models/Traits under BPMN).
• Extensibility: By relying on interfaces and traits, the engine is designed for adaptability, making it easier to add new BPMN elements and behavior without impacting the core execution logic.
• Testability: The comprehensive tests directory indicates the importance of unit and feature tests for each component, which is an important consideration in design documentation.