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](https://github.com/viewflow/viewflow), designed for loose coupling and production usage.

## Documentation Languages

- [English]./docs/i18n/en/README.md
- [简体中文]./docs/i18n/zh-Hans/README.md
- [繁體中文]./docs/i18n/zh-Hant/README.md
- [Deutsch]./docs/i18n/de/README.md
- [Español]./docs/i18n/es/README.md
- [Français]./docs/i18n/fr/README.md
- [Italiano]./docs/i18n/it/README.md
- [日本語]./docs/i18n/ja/README.md
- [한국어]./docs/i18n/ko/README.md
- [Português]./docs/i18n/pt/README.md
- [Русский]./docs/i18n/ru/README.md
- [Српски]./docs/i18n/sr/README.md
- [Қазақша]./docs/i18n/kk/README.md

Language index: [docs/README.md](./docs/README.md)

## Usage Docs (Multilingual)

- [English Usage]./docs/i18n/en/usage.md
- [简体中文使用文档]./docs/i18n/zh-Hans/usage.md
- [繁體中文使用文件]./docs/i18n/zh-Hant/usage.md
- [Deutsch Nutzung]./docs/i18n/de/usage.md
- [Español Uso]./docs/i18n/es/usage.md
- [Français Utilisation]./docs/i18n/fr/usage.md
- [Italiano Utilizzo]./docs/i18n/it/usage.md
- [日本語 使い方]./docs/i18n/ja/usage.md
- [한국어 사용 가이드]./docs/i18n/ko/usage.md
- [Português Uso]./docs/i18n/pt/usage.md
- [Русский Использование]./docs/i18n/ru/usage.md
- [Српски Употреба]./docs/i18n/sr/usage.md
- [Қазақша Қолдану]./docs/i18n/kk/usage.md

## 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

```bash
cargo add rust-viewflow
```

## Feature Flags

- `axum` (default): enables Axum router integration
- `actix`: enables Actix-web scope integration

Examples:

```bash
cargo check --all-features --examples
```

## Quick Start (Axum + SQLite)

```rust
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:

```bash
cargo run --example leave_request
cargo run --example leave_request_actix --features actix
```

Then test endpoints:

```bash
./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

```bash
cargo fmt
cargo check --all-features --examples
cargo test
```

## Release

One-shot release helper:

```bash
./release.sh [repo-url] [version] [--publish] [--no-commit] [--no-push] [--skip-tests] [--skip-package] [--skip-dry-run]
```

Common flows:

```bash
# 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]./LICENSE-MIT)
- Apache License, Version 2.0 ([LICENSE-APACHE]./LICENSE-APACHE)

at your option.