Understanding LiteFlow: A Lightweight Component‑Based Flow Engine for Decoupling Complex Business Logic
This article introduces LiteFlow, a lightweight Java workflow engine that decouples complex business logic by modeling each step as a reusable component, explains its workbench design, demonstrates usage in both non‑Spring and Spring Boot environments, and walks through its core architecture and execution flow.
Many enterprise systems contain tangled business logic that becomes hard to maintain as projects evolve; LiteFlow is presented as a lightweight, fast component‑based flow engine designed to split such logic into independent nodes and orchestrate them through a configurable rule file, enabling hot‑reloading and flexible process changes.
The framework follows a "workbench" model: workers (components) pick up resources from a shared workbench (context) and produce parts that are later assembled, allowing each worker to operate without knowledge of others, which brings decoupling, stability, reusability, and real‑time reconfiguration.
In a non‑Spring environment you add the core dependency:
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>liteflow-core</artifactId>
<version>2.6.13</version>
</dependency>Then you implement custom nodes by extending NodeComponent and overriding process , define an XML flow file under resources , build a LiteflowConfig with the XML path, create a FlowExecutor , and invoke execute2Resp("chain1") to run the defined chain.
When using Spring Boot you add the starter dependency:
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>liteflow-spring-boot-starter</artifactId>
<version>2.6.13</version>
</dependency>Custom nodes are annotated with @LiteflowComponent , the XML file path is set in application.properties , and the framework automatically registers the nodes, so no explicit XML <component> tags are required.
The core components include:
Parser : parses rule files (XML/JSON/YAML) into Java objects.
FlowBus : stores parsed Node and Chain objects.
FlowExecutor : drives execution by retrieving a Chain from FlowBus and invoking its conditions.
Slot : shared context for a flow execution.
DataBus : manages Slot instances.
During FlowExecutor construction the framework loads rule files, creates Document objects, and through FlowParser builds Node , Condition (Pre, Then, When, Finally) and Chain objects, registering them in FlowBus .
Execution proceeds in the order PreCondition → ThenCondition (serial) → WhenCondition (parallel) → FinallyCondition. Each Condition contains Executable objects, which are either Node or nested Chain . Nodes are executed via a NodeExecutor that supports retries and invokes the node’s process method.
Overall, LiteFlow provides a clear separation between business code and orchestration, allowing developers to modify process flows by editing rule files without changing Java code, thus reducing coupling and improving maintainability.
Code Ape Tech Column
Former Ant Group P8 engineer, pure technologist, sharing full‑stack Java, job interview and career advice through a column. Site: java-family.cn
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.