E-commerce starter

E-commerce starter

Highlight product discovery, curation, and checkout paths with Spectral workflows.

Spectral Example: E Commerce Starter

# Complete E-Commerce System Example

type Product {
    id: string
    name: string
    price: number
    description: string
    stock: number
}

type Order {
    id: string
    customerId: string
    items: array
    status: OrderStatus
    total: number
    createdAt: datetime
}

type Review {
    id: string
    productId: string
    rating: number
    comment: string
    author: string
}

enum OrderStatus {
    pending
    processing
    shipped
    delivered
    cancelled
    refunded
}

enum UserRole {
    customer
    seller
    admin
    support
}

# Roles and Permissions
role CustomerRole {
    permission orders {
        create,
        read,
        cancel
    }
    permission products {
        read,
        search
    }
    permission reviews {
        create,
        read
    }
    permission account {
        read,
        update
    }
}

role SellerRole {
    permission products {
        create,
        read,
        update,
        delete
    }
    permission orders {
        read
    }
    permission analytics {
        read
    }
}

role AdminRole {
    permission users {
        create,
        read,
        update,
        delete
    }
    permission products {
        create,
        read,
        update,
        delete
    }
    permission orders {
        read,
        update,
        cancel
    }
    permission system {
        read,
        update,
        delete
    }
}

# Workflows
workflow OrderProcessing {
    state pending -> processing, cancelled
    state processing -> shipped, cancelled
    state shipped -> delivered
    state delivered -> completed
    state cancelled -> refunded
    state refunded -> completed
}

workflow ProductLifecycle {
    state draft -> active
    state active -> archived
    state archived -> draft, active
}

# Agents
agent OrderProcessor: AdminRole {
    can fetch order when exists
    can validate order if valid_items
    can process payment if has_payment_method
    can update order status
    can send notification to customer
    can handle refunds when requested
}

agent ProductCatalogManager: SellerRole {
    can create product
    can update product details
    can manage inventory
    can publish product
    can archive product
    can view analytics
}

agent CustomerSupportAgent: AdminRole {
    can retrieve customer
    can view order history
    can process refund
    can update order status
    can send notifications
}

# Visitor - Customer Journey
visitor {
    can browse {
        can search products
        can filter products
        can view product details {
            can view images
            can read reviews
            can check availability
        }
    }
    can account {
        can register
        can login {
            can access dashboard
            can view profile
            can update profile {
                can change password
                can update contact info
                can manage addresses
            }
            can view order history {
                can view order details
                can track shipment
                can request refund
            }
            can manage cart {
                can add to cart
                can remove from cart
                can update quantity
                can checkout
            }
        }
        can logout
    }
    can checkout {
        can enter shipping address
        can select shipping method
        can enter payment info
        can review order
        can place order
    }
    can review {
        can write product review if purchased
        can rate product
        can upload images
    }
    can support {
        can contact support
        can view FAQs
        can report issue
    }
}

# Visitor - Seller Journey
visitor {
    can manage store {
        can view store dashboard
        can manage inventory {
            can add products
            can update stock
            can set prices
        }
        can view orders {
            can process orders
            can update shipment
            can handle returns
        }
        can view analytics {
            can view sales report
            can view traffic report
            can view customer report
        }
    }
    can account {
        can view profile
        can update profile
        can manage billing
        can view transactions
    }
}

# Visitor - Admin Journey
visitor {
    can admin panel {
        can manage users {
            can view users
            can create user
            can update user
            can delete user
            can assign role
            can suspend user
        }
        can manage content {
            can review products
            can approve products
            can remove products
            can manage categories
        }
        can manage orders {
            can view all orders
            can update order status
            can process refunds
            can cancel orders
        }
        can manage system {
            can view logs
            can configure settings
            can manage integrations
            can view analytics {
                can view user metrics
                can view sales metrics
                can view system health
            }
        }
    }
}