Workflows

Workflow engine for managing renovation project phases and tasks. Template-based system where workflow templates define a sequence of phases and tasks; a state machine governs transitions; and a rules engine enables automatic progression.

Source Files

LayerPath
Schemabackend/src/db/schema.ts
Routesbackend/src/routes/workflow/ (tasks, phases, templates, deals, appointments, activities)
Task Servicebackend/src/services/task-service.ts
State Machinebackend/src/services/workflow-state-machine.ts
Config Servicebackend/src/services/workflow-config-service.ts
Template Servicebackend/src/services/workflow-template-service.ts
Pagefrontend/src/pages/internal/WorkflowPage.tsx
Componentsfrontend/src/components/workflow/ (5+ files)
Storefrontend/src/store/workflow.ts (Zustand)

Database Tables

TablePurpose
workflowTemplatesReusable workflow definitions (name, description, project type)
workflowTemplatePhasesPhases within a template (order, name, entry/exit criteria)
workflowTemplatePhaseTasksTasks within a phase (order, type, assignee rules, checklist)
workflowTemplateVersionsVersion history for templates (immutable snapshots)
workflowChecklistTemplatesReusable checklist definitions attached to tasks
workflowTaskTypesEnumeration of task types (e.g., inspection, document collection, approval)
workflowRulesAutomation rules for transitions (conditions and actions)
workflowTransitionLogAudit trail of state transitions (from, to, trigger, timestamp)
taskTimeBookingsTime tracking entries per task

Architecture

State Machine

workflow-state-machine.ts governs all phase and task transitions:

  • Phases progress linearly with configurable entry/exit criteria
  • Tasks within a phase can run in parallel or sequentially
  • Transitions are validated against the current state and rules before execution
  • Every transition is logged in workflowTransitionLog

Template Versioning

Templates are versioned via workflowTemplateVersions. When a template is modified, a new version snapshot is created. Active projects continue using the version they were started with — updates only affect new projects.

Rules Engine

workflowRules define automatic transitions:

Rule ComponentPurpose
ConditionWhen to fire (e.g., all tasks in phase complete)
ActionWhat to do (e.g., advance to next phase, notify user)
PriorityExecution order when multiple rules match

Key Features

  • Phase/task hierarchy — templates define phases; phases contain tasks; tasks have checklists
  • Time booking — staff log time against tasks via taskTimeBookings
  • Activity tracking — all workflow interactions recorded for audit
  • Template management — admins create and version templates in Admin Dashboard
  • Checklist templates — reusable checklists attached to task types

Frontend State

The workflow UI uses a Zustand store at frontend/src/store/workflow.ts for:

  • Current workflow instance and active phase/task
  • Task status updates and optimistic mutations
  • Filter and view state (Kanban vs. list)

Relationships

WorkflowTemplate 1──* Phases 1──* Tasks
WorkflowTemplate 1──* Versions
Task *──1 WorkflowTaskType
Task 1──* TaskTimeBookings
Task *──1 Users (assignee)
Project *──1 WorkflowTemplate (active workflow)
Task ──> Appointments
Task ──> Quotes

Projects | Users | Appointments | Quotes | Departments | Admin Dashboard | Service Layer Pattern | Database Architecture