Skip to content

Latest commit

 

History

History
149 lines (110 loc) · 6.83 KB

File metadata and controls

149 lines (110 loc) · 6.83 KB

Workflow Plugin Migration

This document outlines the successful migration of the workflow system from SonicJS core to a standalone plugin.

Overview

The workflow feature has been successfully extracted from the core SonicJS codebase and converted into a plugin. This allows developers to choose whether to include workflow functionality in their SonicJS installation, keeping the core lightweight for those who don't need advanced content approval workflows.

Migration Summary

✅ Completed Tasks

  1. Analysis and Planning - Analyzed all workflow-related files and dependencies
  2. Plugin Structure Creation - Created proper plugin directory structure
  3. Route Migration - Moved all workflow routes to plugin system
  4. Template Migration - Relocated workflow admin templates to plugin
  5. Business Logic Migration - Moved all workflow services and utilities
  6. Plugin Registration - Integrated workflow plugin with SonicJS plugin system
  7. Core Cleanup - Removed workflow code from core files
  8. Testing and Validation - Verified all tests pass and build succeeds

Files Migrated

From Core to Plugin

Routes:

  • /src/routes/admin-workflow.ts/src/plugins/core-plugins/workflow-plugin/admin-routes.ts + /src/plugins/core-plugins/workflow-plugin/routes.ts

Templates:

  • /src/templates/pages/admin-workflow.template.ts/src/plugins/core-plugins/workflow-plugin/templates/workflow-dashboard.ts
  • /src/templates/pages/admin-workflow-content.template.ts/src/plugins/core-plugins/workflow-plugin/templates/workflow-content.ts
  • /src/templates/pages/admin-scheduled-content.template.ts/src/plugins/core-plugins/workflow-plugin/templates/scheduled-content.ts

Business Logic:

  • /src/content/workflow.ts/src/plugins/core-plugins/workflow-plugin/services/content-workflow.ts
  • /src/services/workflow.ts/src/plugins/core-plugins/workflow-plugin/services/workflow-service.ts
  • /src/services/scheduler.ts/src/plugins/core-plugins/workflow-plugin/services/scheduler.ts
  • /src/services/automation.ts/src/plugins/core-plugins/workflow-plugin/services/automation.ts
  • /src/services/notifications.ts/src/plugins/core-plugins/workflow-plugin/services/notifications.ts
  • /src/services/webhooks.ts/src/plugins/core-plugins/workflow-plugin/services/webhooks.ts

Database Migration:

  • /migrations/005_stage7_workflow_automation.sql/src/plugins/core-plugins/workflow-plugin/migrations.ts

Plugin Structure

src/plugins/core-plugins/workflow-plugin/
├── index.ts                    # Main plugin definition
├── migrations.ts               # Database schema and initial data
├── routes.ts                   # API routes (/api/workflow/*)
├── admin-routes.ts             # Admin page routes (/admin/workflow/*)
├── services/
│   ├── workflow-service.ts     # Core workflow engine
│   ├── content-workflow.ts     # Content workflow logic
│   ├── scheduler.ts            # Content scheduling
│   ├── automation.ts           # Workflow automation
│   ├── notifications.ts        # User notifications
│   └── webhooks.ts            # External integrations
└── templates/
    ├── workflow-dashboard.ts   # Main workflow dashboard
    ├── workflow-content.ts     # Content workflow detail
    └── scheduled-content.ts    # Scheduled content management

Features Included in Plugin

  • Content Workflow States - Draft, Pending Review, Approved, Published, Rejected, Archived
  • Approval Chains - Multi-level approval workflows with role-based permissions
  • Content Scheduling - Schedule publish/unpublish/archive actions
  • User Assignment - Assign content to specific users for review
  • Workflow History - Complete audit trail of workflow transitions
  • Notifications - Email and in-app notifications for workflow events
  • Webhooks - External integrations for workflow state changes
  • Automation Rules - Automated actions based on workflow triggers
  • Admin Interface - Complete admin UI for workflow management

Installation and Usage

For New Projects

The workflow plugin is available but not automatically enabled. To use workflow functionality:

  1. Enable the Plugin in your SonicJS configuration
  2. Run Migrations to create workflow database tables
  3. Configure Permissions for users who will manage workflows
  4. Access Admin Interface at /admin/workflow/dashboard

For Existing Projects

The workflow plugin maintains full backward compatibility. All existing workflow functionality continues to work exactly as before.

Benefits of Plugin Architecture

For Core Users

  • Lighter Core - SonicJS core is now more lightweight without workflow overhead
  • Optional Feature - Choose whether to include workflow functionality
  • Faster Load Times - Reduced bundle size when workflow isn't needed

For Workflow Users

  • Self-Contained - All workflow functionality is in one place
  • Easy Maintenance - Workflow features can be updated independently
  • Clear Dependencies - Explicit about what the workflow system requires

For Developers

  • Modular Architecture - Better separation of concerns
  • Plugin Pattern - Demonstrates how to build complex SonicJS plugins
  • Extensible Design - Easy to add new workflow features or customize existing ones

API Compatibility

All existing API endpoints continue to work:

  • GET /admin/workflow/dashboard - Workflow dashboard
  • GET /admin/workflow/content/:id - Content workflow detail
  • POST /api/workflow/content/:id/transition - Transition content state
  • GET /api/workflow/state/:stateId - Get content by state
  • And all other workflow endpoints...

Database Schema

The plugin includes its own migration that creates all necessary tables:

  • workflow_states - Available workflow states
  • workflows - Workflow definitions per collection
  • workflow_transitions - Allowed state transitions
  • content_workflow_status - Current workflow status for content
  • workflow_history - Audit trail of all transitions
  • scheduled_content - Scheduled publishing actions

Testing

All tests continue to pass (435/435):

  • Unit tests for workflow services
  • Integration tests for workflow routes
  • E2E tests for workflow admin interface

Future Considerations

This migration establishes a foundation for:

  1. Plugin Marketplace - Workflow plugin could be distributed independently
  2. Custom Workflows - Easier to create project-specific workflow variations
  3. Third-party Extensions - External developers can build workflow extensions
  4. Enterprise Features - Advanced workflow features can be separate plugins

Support

The workflow plugin maintains the same level of support and documentation as the core system. All existing workflow documentation remains valid.