Workflow Recipes

Ready-to-use Spectral patterns for common development scenarios. Copy and adapt these recipes to jumpstart your projects.

🎯 What are Workflow Recipes?

Workflow recipes are proven Spectral patterns for:

  • State machines and business workflows
  • CRUD operations and data flows
  • Authentication and authorization
  • Multi-step processes
  • Real-world application patterns

📝 Todo App Workflow

A simple task management workflow with three states.

type Task {
  id: string
  title: string
  description: string
  status: TaskStatus
  assigneeId: string
}

enum TaskStatus {
  todo
  in_progress
  done
}

workflow TaskFlow {
  initial: todo
  todo -> in_progress
  in_progress -> done
  in_progress -> todo when reverted
}

visitor TaskManager {
  can create tasks
  can view tasks
  can edit tasks
  can delete tasks
  can assign tasks
}

visitor TeamMember {
  can view tasks
  can update own tasks
}
✨ Edit in Studio

Use case: Project management, issue tracking, task boards


🛒 E-commerce Order Flow

Complete order processing workflow with payments and fulfillment.

type Order {
  id: string
  customerId: string
  items: OrderItem[]
  total: number
  status: OrderStatus
}

type OrderItem {
  productId: string
  quantity: number
  price: number
}

enum OrderStatus {
  pending
  payment_received
  processing
  shipped
  delivered
  cancelled
}

workflow OrderProcessing {
  initial: pending
  pending -> payment_received when payment_confirmed
  payment_received -> processing
  processing -> shipped when items_packed
  shipped -> delivered when customer_confirms
  pending -> cancelled when timeout
  payment_received -> cancelled when refund_requested
}

visitor Customer {
  can create orders
  can view own orders
  can cancel own pending orders
}

visitor Merchant {
  can view all orders
  can process orders
  can update order status
  can handle refunds
}

agent OrderProcessor {
  can validate order
  can process payment
  can notify customer
  can update inventory
}
✨ Edit in Studio

Use case: Online stores, marketplaces, subscription services


📄 Document Approval Workflow

Multi-stage document review and approval process.

type Document {
  id: string
  title: string
  content: string
  authorId: string
  status: DocumentStatus
  reviewers: string[]
}

enum DocumentStatus {
  draft
  pending_review
  approved
  rejected
  published
}

workflow DocumentApproval {
  initial: draft
  draft -> pending_review when submitted
  pending_review -> approved when all_reviewers_approve
  pending_review -> rejected when reviewer_rejects
  rejected -> draft when author_revises
  approved -> published when author_publishes
}

visitor Author {
  can create documents
  can edit own draft documents
  can submit for review
  can revise rejected documents
}

visitor Reviewer {
  can view pending documents
  can approve documents
  can reject documents
  can add comments
}

visitor Publisher {
  can view approved documents
  can publish documents
  can unpublish documents
}
✨ Edit in Studio

Use case: Content management, legal docs, approval flows


🎫 Support Ticket System

Customer support ticket lifecycle with SLA tracking.

type Ticket {
  id: string
  customerId: string
  subject: string
  description: string
  priority: Priority
  status: TicketStatus
  assignedTo: string
}

enum Priority {
  low
  medium
  high
  urgent
}

enum TicketStatus {
  open
  assigned
  in_progress
  waiting_customer
  resolved
  closed
}

workflow TicketLifecycle {
  initial: open
  open -> assigned when agent_assigned
  assigned -> in_progress when agent_starts
  in_progress -> waiting_customer when info_needed
  waiting_customer -> in_progress when customer_responds
  in_progress -> resolved when issue_fixed
  resolved -> closed when customer_confirms
  resolved -> in_progress when customer_reopens
}

visitor Customer {
  can create tickets
  can view own tickets
  can respond to tickets
  can close own tickets
}

visitor Agent {
  can view all tickets
  can assign tickets
  can update ticket status
  can respond to tickets
  can resolve tickets
}

visitor Manager {
  can view all tickets
  can reassign tickets
  can view reports
  can manage agents
}

agent TicketRouter {
  can classify ticket
  can assign based on priority
  can escalate urgent tickets
  can send notifications
}
✨ Edit in Studio

Use case: Help desk, customer support, IT ticketing


👤 User Onboarding Flow

Multi-step user registration and verification process.

type User {
  id: string
  email: string
  name: string
  status: UserStatus
  emailVerified: boolean
  profileCompleted: boolean
}

enum UserStatus {
  pending
  email_sent
  email_verified
  profile_setup
  active
  suspended
}

workflow UserOnboarding {
  initial: pending
  pending -> email_sent when registration_submitted
  email_sent -> email_verified when email_confirmed
  email_verified -> profile_setup when user_continues
  profile_setup -> active when profile_completed
  active -> suspended when violation_detected
  suspended -> active when appeal_approved
}

visitor NewUser {
  can register
  can verify email
  can complete profile
}

visitor User {
  can view own profile
  can update own profile
  can deactivate own account
}

visitor Admin {
  can view all users
  can suspend users
  can activate users
  can delete users
}

agent OnboardingBot {
  can send welcome email
  can send verification email
  can send reminder emails
  can track completion
}
✨ Edit in Studio

Use case: SaaS onboarding, user registration, KYC flows


💰 Payment Processing Workflow

Secure payment handling with refunds and disputes.

type Payment {
  id: string
  orderId: string
  amount: number
  currency: string
  status: PaymentStatus
  method: PaymentMethod
}

enum PaymentStatus {
  pending
  processing
  succeeded
  failed
  refunded
  disputed
}

enum PaymentMethod {
  credit_card
  debit_card
  paypal
  bank_transfer
}

workflow PaymentFlow {
  initial: pending
  pending -> processing when payment_submitted
  processing -> succeeded when payment_confirmed
  processing -> failed when payment_declined
  failed -> pending when retry_allowed
  succeeded -> refunded when refund_issued
  succeeded -> disputed when customer_disputes
}

visitor Merchant {
  can process payments
  can issue refunds
  can view transactions
}

visitor Customer {
  can submit payments
  can view own payments
  can dispute payments
}

agent PaymentProcessor {
  can validate payment details
  can charge payment method
  can handle webhooks
  can send receipts
}
✨ Edit in Studio

Use case: Payment gateways, billing systems, transaction processing


📦 Inventory Management

Product inventory tracking with stock alerts.

type Product {
  id: string
  name: string
  sku: string
  quantity: number
  status: StockStatus
  reorderLevel: number
}

enum StockStatus {
  in_stock
  low_stock
  out_of_stock
  discontinued
}

workflow InventoryManagement {
  initial: in_stock
  in_stock -> low_stock when quantity_below_threshold
  low_stock -> out_of_stock when quantity_zero
  out_of_stock -> in_stock when stock_replenished
  low_stock -> in_stock when stock_replenished
  in_stock -> discontinued when product_discontinued
}

visitor WarehouseManager {
  can add products
  can update stock levels
  can set reorder levels
  can discontinue products
}

visitor PurchasingAgent {
  can view low stock items
  can create purchase orders
  can receive inventory
}

agent StockMonitor {
  can check stock levels
  can send low stock alerts
  can auto-create purchase orders
  can notify suppliers
}
✨ Edit in Studio

Use case: Warehouse management, retail inventory, supply chain


🏥 Appointment Booking System

Medical or service appointment scheduling workflow.

type Appointment {
  id: string
  patientId: string
  providerId: string
  datetime: string
  status: AppointmentStatus
  duration: number
}

enum AppointmentStatus {
  requested
  confirmed
  checked_in
  in_progress
  completed
  cancelled
  no_show
}

workflow AppointmentFlow {
  initial: requested
  requested -> confirmed when provider_accepts
  requested -> cancelled when patient_cancels
  confirmed -> checked_in when patient_arrives
  checked_in -> in_progress when appointment_starts
  in_progress -> completed when appointment_ends
  confirmed -> no_show when patient_absent
  confirmed -> cancelled when provider_cancels
}

visitor Patient {
  can request appointments
  can view own appointments
  can cancel own appointments
  can check in
}

visitor Provider {
  can view own schedule
  can confirm appointments
  can cancel appointments
  can mark completed
}

visitor Receptionist {
  can view all appointments
  can check in patients
  can reschedule appointments
  can handle walk-ins
}

agent AppointmentReminder {
  can send confirmation
  can send reminder 24h before
  can send reminder 1h before
  can handle responses
}
✨ Edit in Studio

Use case: Healthcare, consulting, service bookings


🎓 Course Enrollment Workflow

Online learning platform enrollment and progress tracking.

type Enrollment {
  id: string
  studentId: string
  courseId: string
  status: EnrollmentStatus
  progress: number
  grade: number
}

enum EnrollmentStatus {
  pending
  active
  in_progress
  completed
  dropped
  failed
}

workflow EnrollmentFlow {
  initial: pending
  pending -> active when payment_received
  active -> in_progress when student_starts
  in_progress -> completed when all_modules_finished
  in_progress -> failed when deadline_passed
  active -> dropped when student_withdraws
  pending -> dropped when payment_expired
}

visitor Student {
  can browse courses
  can enroll in courses
  can view own enrollments
  can drop courses
  can access course materials
}

visitor Instructor {
  can view enrolled students
  can grade assignments
  can post announcements
  can provide feedback
}

visitor Admin {
  can manage courses
  can manage enrollments
  can process refunds
  can generate reports
}

agent ProgressTracker {
  can track completion
  can calculate grades
  can send progress updates
  can award certificates
}
✨ Edit in Studio

Use case: E-learning platforms, training programs, certifications


🔄 CI/CD Pipeline Workflow

Automated build, test, and deployment pipeline.

type Build {
  id: string
  commitHash: string
  branch: string
  status: BuildStatus
  startTime: string
  endTime: string
}

enum BuildStatus {
  queued
  building
  testing
  deploying
  succeeded
  failed
  cancelled
}

workflow CICDPipeline {
  initial: queued
  queued -> building when runner_available
  building -> testing when build_succeeds
  building -> failed when build_fails
  testing -> deploying when tests_pass
  testing -> failed when tests_fail
  deploying -> succeeded when deploy_succeeds
  deploying -> failed when deploy_fails
  queued -> cancelled when user_cancels
  building -> cancelled when user_cancels
}

visitor Developer {
  can trigger builds
  can view build logs
  can cancel builds
}

visitor DevOps {
  can view all builds
  can trigger deployments
  can rollback deployments
  can configure pipelines
}

agent PipelineRunner {
  can checkout code
  can run build commands
  can execute tests
  can deploy artifacts
  can send notifications
}
✨ Edit in Studio

Use case: DevOps automation, continuous delivery, deployment pipelines


🎯 Best Practices

1. Keep States Minimal

Use only necessary states. More states = more complexity.

# ❌ Too many states
enum Status { created, validated, processed, verified, approved, published, archived }

# ✅ Just enough states
enum Status { draft, approved, published }
✨ Edit in Studio

2. Name States Clearly

Use descriptive names that indicate the state of the entity.

# ❌ Unclear
enum Status { s1, s2, s3 }

# ✅ Clear
enum Status { pending, processing, completed }
✨ Edit in Studio

3. Model Conditions Explicitly

Make transition conditions explicit in your workflow.

workflow OrderFlow {
  pending -> processing when payment_confirmed
  processing -> shipped when items_ready
  processing -> cancelled when out_of_stock
}
✨ Edit in Studio

4. Separate Concerns

Use different visitors for different roles.

visitor Customer {
  can view orders
  can create orders
}

visitor Admin {
  can view all orders
  can cancel orders
  can issue refunds
}
✨ Edit in Studio

5. Use Agents for Automation

Let agents handle automated tasks.

agent NotificationService {
  can send email
  can send sms
  can send push notification
}
✨ Edit in Studio

Quick Start Tips

  1. Start with types - Define your data structures first
  2. Add workflows - Model state transitions
  3. Define visitors - Specify who can do what
  4. Add agents - Automate repetitive tasks
  5. Implement with AI - Use spectral implement to create implementation

📚 Next Steps


Need a custom recipe? Ask your AI assistant or check out more examples.