1 unstable release
| new 0.1.0 | Feb 27, 2026 |
|---|
#2 in #bpm
58KB
1.5K
SLoC
rust-viewflow
A Rust business workflow package inspired by viewflow/viewflow, designed for loose coupling and production usage.
Documentation Languages
Language index: docs/README.md
Usage Docs (Multilingual)
- English Usage
- 简体中文使用文档
- 繁體中文使用文件
- Deutsch Nutzung
- Español Uso
- Français Utilisation
- Italiano Utilizzo
- 日本語 使い方
- 한국어 사용 가이드
- Português Uso
- Русский Использование
- Српски Употреба
- Қазақша Қолдану
Highlights
- Workflow core engine independent of web framework
- Optional web adapters for Axum and Actix-web
- Database abstraction trait (
WorkflowDatabase) with pluggable backends - Built-in SQLx backends: SQLite / MySQL / PostgreSQL
- In-memory backend for tests and lightweight deployments
- API abstraction layer (
WorkflowApi) separated from transport - Multi-language task labels in sample flow (
en,zh-CN,zh-TW)
Architecture
src/core: workflow domain model + engine + workflow definitionssrc/db: database trait and backend implementationssrc/api: API contract + Axum/Actix adaptersexamples: runnable demo apps
The coupling direction is one-way:
- Web layer depends on API trait
- API depends on workflow engine trait
- Engine depends on workflow/database traits
- Custom implementations can replace any layer
Install
cargo add rust-viewflow
Feature Flags
axum(default): enables Axum router integrationactix: enables Actix-web scope integration
Examples:
cargo check --all-features --examples
Quick Start (Axum + SQLite)
use std::sync::Arc;
use rust_viewflow::{
create_axum_router,
migrate_sqlite,
DefaultWorkflowApi,
DefaultWorkflowEngine,
LeaveRequestWorkflow,
SqliteDatabase,
};
use sqlx::SqlitePool;
# async fn run() -> Result<(), Box<dyn std::error::Error>> {
let pool = SqlitePool::connect("sqlite::memory:").await?;
migrate_sqlite(&pool).await?;
let db = Arc::new(SqliteDatabase::new(pool));
let engine = Arc::new(DefaultWorkflowEngine::new(db.clone()));
engine.register_workflow(Arc::new(LeaveRequestWorkflow::new(db)));
let api = Arc::new(DefaultWorkflowApi::new(engine));
let router = create_axum_router(api);
# let _ = router;
# Ok(()) }
Leave Request Sample
The sample leave_request flow includes:
- Manager approval task
- HR approval task (if manager approves)
- Workflow completion or cancellation
You can run:
cargo run --example leave_request
cargo run --example leave_request_actix --features actix
Then test endpoints:
./test_api.sh
API Endpoints
POST /workflows- create a workflow instanceGET /workflows/{id}- get workflow detailsGET /workflows/{id}/tasks- list workflow tasksPOST /tasks/{id}/complete- complete a task with payload
Language Support
Like Viewflow's i18n-friendly model, task naming can be locale-aware. In sample workflow:
locale=zh-CN: Chinese (Simplified)locale=zh-TW: Chinese (Traditional)- default: English
You can extend this by implementing your own WorkflowDefinition with custom localization strategy.
Development
cargo fmt
cargo check --all-features --examples
cargo test
Release
One-shot release helper:
./release.sh [repo-url] [version] [--publish] [--no-commit] [--no-push] [--skip-tests] [--skip-package] [--skip-dry-run]
Common flows:
# Local preflight only (no commit/push/publish)
./release.sh 0.1.0 --no-push --no-commit
# Push to GitHub, run checks, create and push tag
./release.sh https://github.com/<owner>/rust-viewflow.git 0.1.0
# Full release to crates.io
./release.sh https://github.com/<owner>/rust-viewflow.git 0.1.0 --publish
License
Dual-licensed under either of:
- MIT License (LICENSE-MIT)
- Apache License, Version 2.0 (LICENSE-APACHE)
at your option.
Dependencies
~43–61MB
~1M SLoC