Warm-Flow Workflow Engine

repository·master·Indexed 20 days ago

https://github.com/dromara/warm-flow

A lightweight, open-source workflow engine for Java applications featuring a minimal 7-table database schema. It supports comprehensive approval operations (pass, return, recall, arbitrary jump, etc.), dual designer modes (Classic and DingTalk-style), and SpEL expressions. Compatible with Java 8, 17, and 21, and supports frameworks like Spring and Solon, ORMs including MyBatis-Plus and JPA, and databases such as MySQL, Oracle, PostgreSQL, and SQL Server. Includes a UI-agnostic Vue 3 designer library (@dromara/warm-flow-designer) with adapters for Element Plus, Ant Design Vue 4, and Naive UI.

Tokens
25.8K
Snippets
75
Records
105
Agent score
68%

What's inside Warm-Flow

  1. Overview of Warm-Flow workflow engine features

    master

    Warm-Flow is a lightweight, domestic (Chinese) workflow engine designed for easy integration. Key features include:

    • Simplicity: Uses only 7 database tables, making it easy to integrate and learn.
    • Approval Capabilities: Supports pass, return, arbitrary jump, transfer, termination, sign-off (会签), ticket sign-off (票签), delegation, add/remove sign-off, mutual exclusion, and parallel gateways.
    • Extensibility: Supports 5 types of listeners, custom condition expressions (including SpEL), and custom handler expressions (including SpEL).
    • Database & ORM Support: Supports MySQL, Oracle, and PostgreSQL. Compatible with MyBatis, MyBatis-Plus, MyBatis-Flex, and JPA.
    • Runtime Support: Compatible with Spring and Solon frameworks; supports Java 8, 17, and potentially 11.
    • Core Features: Built-in multi-tenancy, soft deletes, and permission configurations for roles, departments, and users.
  2. Overview of Warm-Flow Workflow Engine

    master

    Warm-Flow is a lightweight, high-performance, and extensible workflow engine developed by the Dromara community. It is designed for rapid integration and is particularly suitable for small to medium-sized projects requiring flexible approval processes.

    Key Features

    • Lightweight: Uses only 7 database tables, minimizing maintenance overhead.
    • Comprehensive Approval Operations: Supports pass, return, cancel, recall, arbitrary jump, terminate, transfer, sign, delegate, add/subtract sign, mutual exclusion, parallel, auto-approval, remote access, and script execution.
    • Dual Designer Modes: Supports both 'Classic' and 'DingTalk-style' (仿钉钉) workflow designer modes via JAR package integration.
    • Flexible Expressions: Built-in support for SpEL (Spring Expression Language) and custom condition/handler expressions.
    • Extensible Listeners: Four types of listeners with support for dynamic permissions and parameter passing.
    • Broad Compatibility:
      • Frameworks: Spring and Solon.
      • Runtimes: Java 8, Java 17, and Java 21.
      • ORM: MyBatis, MyBatis-Plus, JPA, Easy-Query, and BeetlSql.
      • Databases: MySQL, Oracle, PostgreSQL, and SQL Server.
  3. Compare SPA vs NPM mode performance

    master

    The transition from the legacy SPA (Single Page Application) mode to the NPM Library mode significantly improves performance and reduces bundle size through tree-shaking and removing unnecessary overhead (like routing and App shells).

    MetricSPA Mode (Legacy)NPM Mode (New)Improvement
    First Load Size~800KB (gzipped ~200KB)~250-400KB (gzipped)↓ Smaller
    JS Main Bundle~500KB (gzipped ~130KB)~150-250KB (gzipped)↓ Significant
    Initialization Speed~1.5s (includes iframe overhead)~0.3-0.8s (direct component render)↑ 2-5x faster
    Runtime Memory~30MB~20-25MB↓ Slightly lower

    Note: Values are estimates based on typical usage and tree-shaking effectiveness. LogicFlow and Element Plus styles are shared if multiple components are used.

  4. Implement a custom UiAdapter

    master

    If you are using a UI library not natively supported (like Arco or TDesign), you can implement the UiAdapter interface and register it via setUiAdapter(yourAdapter).

    An adapter must provide:

    1. Command Feedback: message, notify, alert, confirm, prompt, and loading.
    2. Optional Directives: clickOutside and loadingDirective.
    3. Component Mapping: A components object mapping semantic names (e.g., button, input) to your UI library's components.

    Best Practices:

    • Decoupled Context: Use your UI library's global/standalone APIs (e.g., Naive UI's createDiscreteApi) for message and notify so they work outside the component tree.
    • Error Handling: For confirm, ensure you .catch() the rejection when a user cancels to avoid unhandled rejections.
    import { setUiAdapter } from '@dromara/warm-flow-designer'
    import type { UiAdapter } from '@dromara/warm-flow-designer'
    
    const myAdapter: UiAdapter = {
      name: 'your-ui-lib',
      message: (type, content) => MyMessage[type](typeof content === 'string' ? content : content.message ?? ''),
      notify:  (type, content) => MyNotification[type](typeof content === 'string' ? { message: content } : content),
      alert:   (content, options) => MyModal.alert({ content, ...options }),
      confirm: (content, options) => MyModal.confirm({ content, ...options }),
      prompt:  (content, options) => MyModal.prompt({ content, ...options }).then((value) => ({ value })),
      loading: (options) => { const inst = MyLoading.open(options); return { close: () => inst.close() } },
      components: { button: MyButton, input: MyInput }
    }
    setUiAdapter(myAdapter)
  5. Understand the Warm-Flow UI Refactoring Roadmap

    master

    The Warm-Flow UI is evolving from a standalone 'SPA + iframe' model to an NPM component package distribution model. This allows the designer to be used as a library in both Vue 2 and Vue 3 projects, while maintaining backward compatibility for existing iframe-based users.

    The Three-Phase Roadmap:

    1. Phase 0 (Core Decoupling): Extracting core abstractions (config, request, auth, store) into a src/core directory to prepare for library mode without changing existing SPA behavior.
    2. Phase 1 (Vue 3 NPM Package): Releasing @warm-flow/vue-designer (v1.9) specifically for Vue 3 users using a dual-mode build.
    3. Phase 2 (Vue 2 Compatibility): Providing a Vue 2 compatibility layer via @warm-flow/vue-designer-vue2 or Web Components for universal framework support (React, Angular, etc.).
  6. Compare Vue 2 compatibility strategies for WarmFlow Designer

    master

    When integrating WarmFlow Designer into projects using Vue 2, there are three primary architectural approaches:

    1. Web Component (Recommended): Wraps the designer as a Custom Element. This provides universal compatibility (Vue 2/3, React, Angular) with a single codebase and low maintenance cost.
    2. Vue 2 Sub-package: Provides a dedicated @warm-flow/vue2-designer package. This requires maintaining two separate UI codebases (one for Vue 2 + Element UI, one for Vue 3 + Element Plus), though the core business logic (core/config, core/request, core/auth) can be shared.
    3. iframe: The simplest method with zero development effort, but lacks deep integration capabilities. Use this if Vue 2 users are few and integration depth is not a priority.
  7. Compare WarmFlow Designer compatibility strategies

    master

    When integrating WarmFlow into your project, choose a compatibility strategy based on your framework requirements:

    StrategyBest ForEffortMaintenanceRecommendation
    Web ComponentVue 2/React/Angular/Vanilla JSHighLow (Single codebase)⭐⭐⭐ Long-term best
    Vue 2 Sub-packageOnly Vue 2 + Vue 3 needsMediumHigh (Two codebases)⭐⭐ Fast availability
    iframeLow urgency for Vue 2 usersZeroZero⭐ Easiest
  8. Integration and Extension Features in Designer Demos

    master

    The designer demos demonstrate three main categories of functionality for integrating @dromara/warm-flow-designer into your application:

    1. 3-Step Integration: Standard workflow for adding the designer to a project.
    2. Integration Cases:
      • useFlowJson: Provides real-time JSON output, event logs, and command-line toolbars via useFlowDesigner.
    3. Extension Capabilities:
      • initialJson: Loading initial state.
      • customNodes: Implementing custom node types.
      • Various extension points, events, and slots for deep customization.

    Each demo also includes a full CRUD lifecycle: Create, Save, Modify, Read-only Preview, Export, and Delete.

  9. Preview: Web Component Support (Phase 2)

    master

    While the current implementation focuses on Vue 3 NPM and SPA modes, a future Phase 2 will introduce Web Component (WC) support. This will allow the designer to be used in any framework (Vue 2, React, Angular, or Vanilla JS) via the <warm-flow-designer> custom element.

    Planned Package Structure:

    • @warm-flow/designer/dist/index.js: Automatically detects environment and registers the Web Component.
    • @warm-flow/designer/dist/vue3.js: Explicit Vue 3 component exports.
    • @warm-flow/designer/dist/web-components.js: Pure Web Components with a bundled Vue runtime.
    • @warm-flow/designer/dist/style.css: Independent styles for use within Shadow DOM.
  10. Understand the Warm-Flow UI Dual-Mode Architecture

    master

    Warm-Flow UI is transitioning to a dual-mode architecture that supports both a legacy SPA (Single Page Application) mode and a modern NPM Library mode. This allows developers to choose between embedding the designer via an iframe or integrating it directly into a Vue 3 application as a component.

    1. SPA Mode (Legacy/Backward Compatible)

    • Integration: Uses an <iframe> to embed the designer.
    • Deployment: The Vue project is built into static files (dist/) and served via Spring Boot's ResourceHandler (typically mapped to /warm-flow-ui/**).
    • Communication: Relies on URL parameters and postMessage for interaction.

    2. NPM Library Mode (Modern/Recommended)

    • Integration: Install via npm install @warm-flow/vue-designer and use as a standard Vue component.
    • Deployment: Distributed as ES/UMD modules via NPM.
    • Communication: Uses standard Vue props and events (e.g., @save, @close).

    3. Core Architecture Layers

    • Core Layer (src/core/): Handles configuration (singleton/injection), Axios instance factory, authentication (TokenProvider), and parameter retrieval from both URL and Props.
    • Component Layer (views/ + components/): Contains the actual UI logic, decoupled from specific entry points.
    /* SPA Integration Example */
    <iframe :src="`${VUE_APP_FLOW_API}/warm-flow-ui/index.html?id=${insId}&type=FlowChart&Authorization=Bearer ${getToken()}`" />
    
    /* NPM Integration Example (Vue 3) */
    import { WarmFlowDesigner } from '@warm-flow/vue-designer';
    <WarmFlowDesigner :id="defId" @save="onSave" />
  11. Use Warm Flow Designer as an npm component library

    master

    The designer can be used as a Vue 3 component library, allowing you to decouple the data layer from your specific backend.

    Important: The main entry point is UI-agnostic. You must call setUiAdapter(...) before rendering FlowDesigner to map neutral components (wf-*) to a specific UI library (Element Plus, Ant Design Vue, or Naive UI). Otherwise, the canvas will not render.

    To build the library for local use:

    yarn build:lib
    import { createApp } from 'vue'
    import ElementPlus from 'element-plus'
    import 'element-plus/dist/index.css'
    
    import { WarmFlowDesigner, setUiAdapter, setDataProvider, createMockProvider } from '@dromara/warm-flow-designer'
    import { elementPlusAdapter } from '@dromara/warm-flow-designer/element-plus'
    import '@dromara/warm-flow-designer/style'
    
    const app = createApp(App)
    
    // 1. Select UI Adapter (Must be called before rendering FlowDesigner)
    setUiAdapter(elementPlusAdapter)
    
    // 2. Register plugins
    app.use(ElementPlus)
    app.use(WarmFlowDesigner)
    app.mount('#app')
    
    // 3. Optional: Inject custom data provider or mock
    setDataProvider(createMockProvider())
  12. Use Warm-Flow UI as an NPM Library

    master

    When using @dromara/warm-flow-designer as an NPM package (Library mode) rather than a standalone SPA, you should use the exported components and composables from the library entry point (src/index.js). This allows you to embed the designer or flow chart into your own Vue application without conflicting with your existing global configurations (like Pinia or Router).

    // Import components from the library entry
    import { WarmFlowDesigner, WarmFlowChart, WarmFormDesigner, WarmFormCreate } from '@dromara/warm-flow-designer';
    
    // Import composables for advanced usage
    import { useWarmFlowConfig } from '@dromara/warm-flow-designer/core/config';
    import { useDark } from '@dromara/warm-flow-designer/composables/useDark';
    import { useCache } from '@dromara/warm-flow-designer/plugins/cache';
    import { useModal } from '@dromara/warm-flow-designer/plugins/modal';
    
    // Import default configuration types
    import { WarmFlowDefaultConfig } from '@dromara/warm-flow-designer/core/config';