rust-viewflow 0.1.0

Rust workflow library inspired by Viewflow, compatible with Axum and Actix-web
Documentation

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)

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 definitions
  • src/db: database trait and backend implementations
  • src/api: API contract + Axum/Actix adapters
  • examples: 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 integration
  • actix: 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:

  1. Manager approval task
  2. HR approval task (if manager approves)
  3. 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 instance
  • GET /workflows/{id} - get workflow details
  • GET /workflows/{id}/tasks - list workflow tasks
  • POST /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:

at your option.