# bpmn-io/bpmn-js architecture

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

- Interactive diagram: https://gitdiagram.com/bpmn-io/bpmn-js
- Repository: https://github.com/bpmn-io/bpmn-js

## Overview

##### Main Components

a) Core Components:
- BaseViewer/BaseModeler as the foundation
- BPMN Moddle (for XML parsing/serialization)

b) Feature Modules:
- Modeling features
- Import/Export handling
- Viewer/Editor components
- Interactive features (palette, context pad, popup menu)

##### Business Logic Layer
- Modeling operations
- Rules engine
- Command handling
- Event system

##### Data Layer
- BPMN model (moddle)
- XML import/export
- Canvas and element registry

##### Component Relationships

Following interactions:
- Modeling features → Command Stack
- Import/Export → BPMN Moddle
- Features → Core services

##### Specific Elements

a) Core Services (lib/core):
- Command Stack
- Event Bus
- Element Registry
- Canvas

b) Feature Modules (lib/features):
- Modeling
- Palette
- Context Pad
- Rules
- Snapping
- Space Tool

- BpmnRenderer
- PathMap
- TextRenderer

##### Implementation Details

Implementation aspects:
- Extension points
- Plugin architecture
- Event system
- Command pattern implementation

##### External Dependencies

Connections to:
- bpmn-moddle
- Browser DOM
- External BPMN services

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Presentation Layer"
        direction TB
        UI["User Interface"]
        VP["Viewer/Modeler UI"]
        click VP "https://github.com/bpmn-io/bpmn-js/blob/develop/lib/Viewer.js"
        NV["Navigation"]
        click NV "https://github.com/bpmn-io/bpmn-js/blob/develop/lib/NavigatedViewer.js"
        
        subgraph "Interactive Elements"
            direction TB
            PAL["Palette"]
            click PAL "https://github.com/bpmn-io/bpmn-js/blob/develop/lib/features/palette/PaletteProvider.js"
            CP["Context Pad"]
            click CP "https://github.com/bpmn-io/bpmn-js/blob/develop/lib/features/context-pad/ContextPadProvider.js"
            PM["Popup Menu"]
            click PM "https://github.com/bpmn-io/bpmn-js/blob/develop/lib/features/popup-menu/ReplaceMenuProvider.js"
            SP["Search Provider"]
            click SP "https://github.com/bpmn-io/bpmn-js/blob/develop/lib/features/search/BpmnSearchProvider.js"
        end
    end

    subgraph "Business Logic Layer"
        direction TB
        BV["Base Viewer"]
        click BV "https://github.com/bpmn-io/bpmn-js/blob/develop/lib/BaseViewer.js"
        BM["Base Modeler"]
        click BM "https://github.com/bpmn-io/bpmn-js/blob/develop/lib/BaseModeler.js"
        
        subgraph "Modeling Core"
            direction TB
            MOD["Modeling"]
            click MOD "https://github.com/bpmn-io/bpmn-js/blob/develop/lib/features/modeling/Modeling.js"
            EF["Element Factory"]
            click EF "https://github.com/bpmn-io/bpmn-js/blob/develop/lib/features/modeling/ElementFactory.js"
            BF["BPMN Factory"]
            click BF "https://github.com/bpmn-io/bpmn-js/blob/develop/lib/features/modeling/BpmnFactory.js"
            BL["BPMN Layouter"]
            click BL "https://github.com/bpmn-io/bpmn-js/blob/develop/lib/features/modeling/BpmnLayouter.js"
        end
        
        subgraph "Tools & Rules"
            direction TB
            ST["Space Tool"]
            click ST "https://github.com/bpmn-io/bpmn-js/blob/develop/lib/features/space-tool/BpmnSpaceTool.js"
            AP["Auto Place"]
            click AP "https://github.com/bpmn-io/bpmn-js/blob/develop/lib/features/auto-place/BpmnAutoPlace.js"
            SN["Snapping"]
            click SN "https://github.com/bpmn-io/bpmn-js/blob/develop/lib/features/snapping/BpmnCreateMoveSnapping.js"
            BR["BPMN Rules"]
            click BR "https://github.com/bpmn-io/bpmn-js/blob/develop/lib/features/rules/BpmnRules.js"
        end
    end

    subgraph "Data Layer"
        direction TB
        subgraph "Drawing System"
            direction TB
            BREN["BPMN Renderer"]
            click BREN "https://github.com/bpmn-io/bpmn-js/blob/develop/lib/draw/BpmnRenderer.js"
            TREN["Text Renderer"]
            click TREN "https://github.com/bpmn-io/bpmn-js/blob/develop/lib/draw/TextRenderer.js"
            PM2["Path Map"]
            click PM2 "https://github.com/bpmn-io/bpmn-js/blob/develop/lib/draw/PathMap.js"
        end
        
        subgraph "Model Management"
            direction TB
            MT["Model Types"]
            click MT "https://github.com/bpmn-io/bpmn-js/blob/develop/lib/model/Types.ts"
            MU["Model Utilities"]
            click MU "https://github.com/bpmn-io/bpmn-js/blob/develop/lib/util/ModelUtil.js"
            IMP["Importer"]
            click IMP "https://github.com/bpmn-io/bpmn-js/blob/develop/lib/import/Importer.js"
            BTW["BPMN Tree Walker"]
            click BTW "https://github.com/bpmn-io/bpmn-js/blob/develop/lib/import/BpmnTreeWalker.js"
        end
    end

    %% External Dependencies
    DIJS["diagram-js"]
    BMOD["bpmn-moddle"]
    DOM["Browser DOM"]

    %% Relationships
    UI --> VP
    VP --> BV
    VP --> BM
    BV --> DIJS
    BM --> DIJS
    MOD --> DIJS
    BREN --> DIJS
    BMOD --> MT
    DOM --> UI

    %% Interactive Elements Connections
    PAL --> MOD
    CP --> MOD
    PM --> MOD
    SP --> MU

    %% Tool Connections
    ST --> MOD
    AP --> MOD
    SN --> MOD
    BR --> MOD

    %% Drawing System Connections
    BREN --> PM2
    BREN --> TREN

    %% Model Management Connections
    IMP --> BTW
    BTW --> MT
    MT --> MU

    classDef default fill:#f9f9f9,stroke:#333,stroke-width:1px
    classDef core fill:#b3d1ff,stroke:#333,stroke-width:1px
    classDef feature fill:#90EE90,stroke:#333,stroke-width:1px
    classDef ui fill:#FFB366,stroke:#333,stroke-width:1px
    classDef external fill:#d3d3d3,stroke:#333,stroke-width:1px

    class BV,BM,DIJS,BMOD core
    class MOD,EF,BF,BL,ST,AP,SN,BR feature
    class UI,VP,PAL,CP,PM,SP ui
    class DOM,DIJS,BMOD external
```
