# didi/logicflow architecture

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

- Interactive diagram: https://gitdiagram.com/didi/logicflow
- Repository: https://github.com/didi/logicflow

## Overview

##### Main Components
- Execution Engine: Found in the packages/engine directory, this component deals with the self-executing workflow / flow model, scheduling, event propagation, and processing logic.
- Extensions: In packages/extension (and related directories for BPMN, dynamic group, node resizing and labeling), these are the plug-in components that enrich the base functionality with custom elements, adapters, and integration with BPMN or other external data structures.
- Framework Integrations: The react-node-registry and vue-node-registry packages show built-in support for integration with React and Vue frameworks, respectively, to allow custom node renderings and portal integration.
- Examples & Documentation: The examples and sites/docs folders serve as practical usage demos (including demos for browser, Node usage, React/Vue and Next.js apps) and also host comprehensive documentation and tutorials on how the library should be used and extended.

##### Relationships and Interactions
- The Core component is the starting point – it provides the API (including event handling, rendering, and data management) that other components build upon.
- Extensions plug into the Core and Engine layers to provide additional node types, behaviors, and adapters (for example, to convert LogicFlow data into BPMN structures).
- The framework-specific registries (React/Vue) wrap or extend the Core’s capabilities for UI rendering in their respective ecosystems.
- The documentation and examples components are used to guide developers and also serve as integration tests for the overall system.

##### Architectural Patterns and Design Principles
- Component-based design: Core drawing and rendering are broken down into modular node, edge, and overlay view components.
- Event-driven architecture: There is an event emitter system that listens to and dictates user interactions, state changes, and propagation across modules.
- Plugin/Extension mechanism: The framework supports extensibility by allowing custom nodes and behaviors, which is emphasized in the extension directories.
- Separation of concerns: The project clearly divides responsibilities among packages (core logic, engine, UI views, tooling, adapter conversion).

##### Relevant Technologies and Frameworks
- TypeScript is used throughout, ensuring type safety across modules.
- Popular tools like ESLint, Prettier, and husky suggest a strong emphasis on code quality.
- The use of Rollup for bundling, and multiple configurations (babel, tsconfig, etc.), indicates a robust build and packaging system.
- Integration support for various front-end frameworks (React, Vue, Next.js) is evident from the examples and registry packages.
- Testing is rigorously set up with Jest and other testing configurations.

- Use clear, distinct labels for each major component. For example, label “Core Engine”, “Execution Engine”, “Extensions”, “React/Vue Integration”, and “Documentation/Examples”.
– From user interaction (in the browser container) to Core for input handling.
– Between Core and Engine for event and state updates.
– Between Core/Engine and Extensions for plug-in interactions.
– From Integration modules back into Core for rendering custom nodes.

##### Summary
- Internal architecture – Core modules handling visual model management, the Engine that drives execution, and the Extensions that allow for custom behaviors and adapter functionalities.
- Ecosystem integrations (React, Vue) and support for various documentation and examples.
The goal is to communicate both the high-level interactions and the detailed roles of each package.

## Diagram (Mermaid)

```mermaid
flowchart TD
    UI["Diagram Editor UI"]:::ui

    subgraph "Core Modules"
        CORE["Core Engine"]:::core
        ENGINE["Execution Engine"]:::engine
        EXT["Extensions"]:::extension
    end

    subgraph "Integrations"
        REACT["React Integration"]:::integration
        VUE["Vue Integration"]:::integration
    end

    subgraph "Examples & Documentation"
        EXAMPLES["Examples (Demos)"]:::example
        DOCS["Documentation"]:::docs
    end

    UI -->|"user_input"| CORE
    CORE -->|"event_propagation"| ENGINE
    ENGINE -->|"state_updates"| CORE
    CORE -->|"plugin_integration"| EXT
    EXT -->|"custom_elements"| CORE
    REACT -->|"custom_rendering"| CORE
    VUE -->|"custom_rendering"| CORE
    CORE -->|"usage_guide"| EXAMPLES
    CORE -->|"usage_guide"| DOCS

    click CORE "https://github.com/didi/logicflow/tree/master/packages/core"
    click ENGINE "https://github.com/didi/logicflow/tree/master/packages/engine"
    click EXT "https://github.com/didi/logicflow/tree/master/packages/extension"
    click REACT "https://github.com/didi/logicflow/tree/master/packages/react-node-registry"
    click VUE "https://github.com/didi/logicflow/tree/master/packages/vue-node-registry"
    click EXAMPLES "https://github.com/didi/logicflow/tree/master/examples"
    click DOCS "https://github.com/didi/logicflow/tree/master/sites/docs"

    classDef ui fill:#cce5ff,stroke:#000,stroke-width:1px;
    classDef core fill:#ffcccc,stroke:#000,stroke-width:1px;
    classDef engine fill:#ffe6cc,stroke:#000,stroke-width:1px;
    classDef extension fill:#d9ead3,stroke:#000,stroke-width:1px;
    classDef integration fill:#e6e6fa,stroke:#000,stroke-width:1px;
    classDef example fill:#fff2cc,stroke:#000,stroke-width:1px;
    classDef docs fill:#fce5cd,stroke:#000,stroke-width:1px;
```
