cleaniquecoders/flowstone

Flowstone - Laravel Workflow Engine with Symfony Workflow Integration

Fund package maintenance!
Cleanique Coders

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/cleaniquecoders/flowstone

1.0.0 2025-10-23 09:12 UTC

This package is auto-updated.

Last update: 2025-10-23 09:16:56 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Flowstone is a powerful Laravel package that integrates the robust Symfony Workflow engine into your Laravel applications. Build sophisticated workflow and state machine systems with database-driven configurations, role-based permissions, and seamless Laravel integration.

🚀 Key Features

  • 🔄 Database-Driven Workflows - Configure workflows through the database for runtime flexibility
  • 🏛️ Symfony Workflow Integration - Built on the proven Symfony Workflow component
  • 👥 Role-Based Permissions - Control who can perform transitions with metadata-driven roles
  • 📊 Predefined Status Enum - Ready-to-use workflow states (Draft, Pending, Approved, etc.)
  • ⚡ Performance Optimized - Workflow configuration caching and efficient queries
  • 🎯 Multiple Workflow Types - Support for both State Machines and Workflows

Table of Contents

Installation

Install Flowstone via Composer:

composer require cleaniquecoders/flowstone

Publish and run the migrations:

php artisan vendor:publish --tag="flowstone-migrations"
php artisan migrate

Optionally, publish the configuration file:

php artisan vendor:publish --tag="flowstone-config"

Quick Start

1. Create a Workflow-Enabled Model

<?php

namespace App\Models;

use CleaniqueCoders\Flowstone\Concerns\InteractsWithWorkflow;
use CleaniqueCoders\Flowstone\Contracts\Workflow as WorkflowContract;
use CleaniqueCoders\Flowstone\Enums\Status;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;

class Document extends Model implements WorkflowContract
{
    use InteractsWithWorkflow;

    protected $fillable = ['title', 'content', 'status', 'author_id'];

    public function workflowType(): Attribute
    {
        return Attribute::make(get: fn () => 'document-approval');
    }

    public function workflowTypeField(): Attribute
    {
        return Attribute::make(get: fn () => 'workflow_type');
    }

    public function getMarking(): string
    {
        return $this->status ?? Status::DRAFT->value;
    }

    public function setMarking(string $marking): void
    {
        $this->status = $marking;
    }
}

2. Configure Your Workflow

Create a workflow configuration in the database:

use CleaniqueCoders\Flowstone\Models\Workflow;
use CleaniqueCoders\Flowstone\Models\WorkflowPlace;
use CleaniqueCoders\Flowstone\Models\WorkflowTransition;

// Create workflow
$workflow = Workflow::create([
    'name' => 'document-approval',
    'type' => 'state_machine',
    'initial_marking' => 'draft',
]);

// Add places (states)
foreach (['draft', 'review', 'approved', 'rejected'] as $place) {
    WorkflowPlace::create([
        'workflow_id' => $workflow->id,
        'name' => $place,
    ]);
}

// Add transitions
WorkflowTransition::create([
    'workflow_id' => $workflow->id,
    'name' => 'submit',
    'from_place' => 'draft',
    'to_place' => 'review',
]);

3. Use the Workflow

// Create a document
$document = Document::create([
    'title' => 'My Document',
    'content' => 'Document content...',
    'status' => 'draft',
]);

// Get available transitions
$transitions = $document->getEnabledToTransitions();
// Returns: ['review' => 'Review']

// Apply a transition
$workflow = $document->getWorkflow();
if ($workflow->can($document, 'submit')) {
    $workflow->apply($document, 'submit');
    $document->save(); // Now status is 'review'
}

Documentation

Comprehensive documentation is available in the docs/ directory:

Examples

Real-world examples are available in the examples/ directory:

  1. Document Approval - Classic approval process with roles
  2. E-commerce Orders - Order lifecycle management
  3. Content Publishing - Editorial workflow with scheduling
  4. Bug Tracking - Issue management for development teams
  5. Employee Onboarding - HR workflow with multi-department coordination

Each example includes complete implementation with models, controllers, views, and tests.

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.