# process-analytics/bpmn-visualization-js architecture

> Architecture diagram of the GitHub repository process-analytics/bpmn-visualization-js, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/process-analytics/bpmn-visualization-js
- Repository: https://github.com/process-analytics/bpmn-visualization-js

## Overview

##### Project Type and Purpose
- It is intended both for direct integration into applications and for use via a demo (as seen in the “dev” directory) and extensive documentation.

##### Analysis of the File Structure
- Source Code (src directory):
- The core library is defined in src, with the main entry point in src/bpmn-visualization.ts.
▸ Parsing (under src/component/parser), which includes separate BPMN parsers for XML (BpmnXmlParser.ts) and JSON (BpmnJsonParser.ts) along with related converters and error/warning management.
▸ UI behaviors (navigation, options, and overlays) and registry modules to keep track of BPMN elements and styles.
- Development and Examples (dev directory):
- Contains demo HTML pages and TypeScript files that illustrate how the library is used. This gives insight into the usage flow.
- Testing (test directory):
- Highly structured tests (unit, integration, e2e, performance) ensure each module (parsing, rendering, registry, etc.) is thoroughly verified.
- Documentation (docs folder) and configuration files (e.g., rollup.config.mjs, tsconfig.json, and various GitHub workflow scripts) indicate a mature build and deployment setup.

##### Key Components
a. Core Library Interface
- The central BpmnVisualization class (src/bpmn-visualization.ts) serves as the public API entry point.

b. Parsing Layer
- BPMN XML Parser (src/component/parser/xml/BpmnXmlParser.ts)
- BPMN JSON Parser (src/component/parser/json/BpmnJsonParser.ts)
- Associated converter modules for transforming raw BPMN data into an internal model.

c. Rendering and Visualization
- MxGraph Integration: The set of modules under src/component/mxgraph (e.g., BpmnGraph, BpmnRenderer, GraphConfigurator, and their configuration helpers) that handle low-level rendering and interaction with the underlying graphics library.

d. BPMN Model and Registry
- Internal BPMN Models: Located in src/model/bpmn/internal with entities like Bounds, Label, and various BPMN types.
- Registries: Components that keep track of BPMN elements, styles, overlays, and query selectors (bytes in src/component/registry).

e. Utility and Shared Components
- Shared utilities for DOM manipulation, validation, and helper functions across parsing, rendering, and interaction.

f. Demo/Development and Testing
- The “dev” directory shows how the library is integrated into a sample web-based demo.
- Testing modules (unit, integration, performance) ensure robustness and can be represented as a side module verifying every major layer.

##### Relationships and Interaction Flow
- A client application instantiates the BpmnVisualization class (public API) which acts as the orchestrator.
- The parsers convert the raw data into an internal BPMN model.
- The model is then sent to the renderer, where:
- Layout and style components compute positioning and graphical updates.
- Registries work in parallel to manage BPMN elements’ metadata and ensure that, as users interact (e.g., mouse hover, clicks), the corresponding overlays, highlighting, or navigation events are triggered.
- Utility and helper layers support error handling, internal state management, and provide feedback loops between the parser, renderer, and end-user interactions.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Clear modular division between parsing, rendering, and model management.
- Extensibility: Registries and overlays allow for customization and extension points (e.g., adding new BPMN elements or custom behaviors).
- Test Driven: High test coverage across unit, integration, and performance tests enforces modularity and reliability.
- TypeScript and ES Module Usage: Clear type definitions and modern JavaScript module systems streamline integration and development.

## Diagram (Mermaid)

```mermaid
graph TD
    C["Client Application"]:::client
    API["BpmnVisualization (API)"]:::api
    C -->|"instantiates"| API

    subgraph "Parsing Layer"
        XML["BPMN XML Parser"]:::parsing
        JSON["BPMN JSON Parser"]:::parsing
    end
    API -->|"loadData"| XML
    API -->|"loadData"| JSON

    subgraph "Model & Registry"
        Model["Internal BPMN Model"]:::model
        Registry["Registries"]:::model
    end
    XML -->|"convert"| Model
    JSON -->|"convert"| Model
    Model -->|"register"| Registry

    subgraph "Rendering & Visualization"
        subgraph "MxGraph Integration"
            BpmnGraph["BpmnGraph"]:::renderer
            BpmnRenderer["BpmnRenderer"]:::renderer
            BpmnCell["BpmnCellRenderer"]:::renderer
            GraphConf["GraphConfigurator"]:::renderer
        end
        Ovl["Overlay"]:::renderer
        Shape["Shape Renderer"]:::renderer
    end
    Model -->|"renderModel"| BpmnGraph
    Registry -->|"updateView"| BpmnRenderer
    API -->|"triggerRender"| BpmnRenderer
    BpmnGraph -->|"callsRender"| BpmnRenderer
    BpmnRenderer -->|"callsCellRender"| BpmnCell
    BpmnRenderer -->|"configures"| GraphConf
    BpmnRenderer -->|"applies"| Ovl
    BpmnRenderer -->|"applies"| Shape

    Utilities["Utilities"]:::utility
    XML ---|"supports"| Utilities
    JSON ---|"supports"| Utilities
    Model ---|"utilizes"| Utilities
    BpmnRenderer ---|"utilizes"| Utilities

    Dev["Demo/Development"]:::devtest
    Testing["Testing"]:::devtest
    API ---|"integratedBy"| Dev
    API ---|"testedBy"| Testing

    click API "https://github.com/process-analytics/bpmn-visualization-js/blob/master/src/bpmn-visualization.ts"
    click XML "https://github.com/process-analytics/bpmn-visualization-js/blob/master/src/component/parser/xml/BpmnXmlParser.ts"
    click JSON "https://github.com/process-analytics/bpmn-visualization-js/blob/master/src/component/parser/json/BpmnJsonParser.ts"
    click BpmnGraph "https://github.com/process-analytics/bpmn-visualization-js/blob/master/src/component/mxgraph/BpmnGraph.ts"
    click BpmnRenderer "https://github.com/process-analytics/bpmn-visualization-js/blob/master/src/component/mxgraph/BpmnRenderer.ts"
    click BpmnCell "https://github.com/process-analytics/bpmn-visualization-js/blob/master/src/component/mxgraph/BpmnCellRenderer.ts"
    click GraphConf "https://github.com/process-analytics/bpmn-visualization-js/blob/master/src/component/mxgraph/GraphConfigurator.ts"
    click Ovl "https://github.com/process-analytics/bpmn-visualization-js/tree/master/src/component/mxgraph/overlay"
    click Shape "https://github.com/process-analytics/bpmn-visualization-js/tree/master/src/component/mxgraph/shape/render"
    click Model "https://github.com/process-analytics/bpmn-visualization-js/tree/master/src/model/bpmn/internal"
    click Registry "https://github.com/process-analytics/bpmn-visualization-js/tree/master/src/component/registry"
    click Utilities "https://github.com/process-analytics/bpmn-visualization-js/tree/master/src/component/helpers"
    click Dev "https://github.com/process-analytics/bpmn-visualization-js/tree/master/dev"
    click Testing "https://github.com/process-analytics/bpmn-visualization-js/tree/master/test"

    classDef client fill:#fff2cc,stroke:#e6b800,stroke-width:2px;
    classDef api fill:#FFD700,stroke:#b8860b,stroke-width:2px;
    classDef parsing fill:#90EE90,stroke:#006400,stroke-width:2px;
    classDef model fill:#FFA07A,stroke:#CD5C5C,stroke-width:2px;
    classDef renderer fill:#87CEFA,stroke:#4682B4,stroke-width:2px;
    classDef utility fill:#D3D3D3,stroke:#696969,stroke-width:2px;
    classDef devtest fill:#dda0dd,stroke:#800080,stroke-width:2px;
```
