Visitors

Define hierarchical capability trees and user journeys for actors interacting with your system.

Keywords

  • visitor - Define a visitor/user/actor
  • can - Define capability (in visitor context)
  • Nested blocks represent state transitions and capability scopes

visitor Keyword

The visitor construct defines what actions a user or actor can perform, organized in a hierarchical tree structure with nested capabilities and state transitions.

Syntax

visitor {
    can action
    can action {
        state_name {
            can nested_action
        }
    }
}
✨ Edit in Studio

Key Features

  • Hierarchical capabilities - Nest actions within actions
  • State transitions - Named blocks represent state changes
  • Scope management - Inner capabilities only available in certain contexts
  • User journey mapping - Model complete user flows

Basic Examples

Simple Visitor

visitor {
    can browse products
    can view product details
    can search
}
✨ Edit in Studio

Visitor with State Transition

visitor {
    can browse
    can login {
        logged in {
            can view profile
            can view orders
            can logout
        }
    }
}
✨ Edit in Studio

Nested Capabilities

visitor {
    can browse {
        browsing {
            can search products
            can filter by category
            can sort results
            can view details {
                viewing_product {
                    can add to cart
                    can read reviews
                    can share
                }
            }
        }
    }
}
✨ Edit in Studio

Advanced Patterns

E-Commerce User Journey

visitor {
    # Anonymous user capabilities
    can view landing page
    can browse products
    can search
    can view product details
    
    # Registration flow
    can register {
        registering {
            can fill form
            can verify email
        }
    }
    
    # Authentication flow
    can login {
        logged in {
            # Shopping capabilities
            can add to cart
            can view cart
            can checkout {
                checking out {
                    can enter shipping info
                    can select payment method
                    can apply coupon
                    can place order
                }
            }
            
            # Account management
            can manage profile {
                can update email
                can change password
                can set preferences
            }
            
            # Order management
            can view orders {
                can view order details
                can track shipment
                can request refund
            }
            
            can logout
        }
    }
}
✨ Edit in Studio

Content Platform

visitor {
    can see landing page
    can browse content
    can search articles
    
    can login {
        logged in {
            can read premium content
            can save bookmarks
            can leave comments
            
            can create content {
                creating {
                    can write article
                    can upload images
                    can preview
                    can publish
                }
            }
            
            can manage profile {
                can update bio
                can change avatar
                can view statistics
            }
        }
    }
    
    can subscribe {
        subscribed {
            can access premium features
            can download content
            can attend webinars
        }
    }
}
✨ Edit in Studio

Todo Application

visitor {
    can see landing page
    can see docs {
        can see instructions
        can see examples
    }
    
    can register
    
    can login {
        logged in {
            can list todo tables
            can create todo table
            
            can enter todo table {
                can add new todo
                can edit todo
                can mark todo done
                can mark todo undone
                can delete todo
                can filter todos
                can sort todos
            }
            
            can manage account {
                can update profile
                can change password
                can delete account
            }
            
            can logout
        }
    }
}
✨ Edit in Studio

Understanding Visitor Structure

Capability Levels

Visitors support deep nesting to represent different scopes:

visitor {
    # Level 1: Public capabilities
    can browse
    
    # Level 2: Action with context
    can login {
        # Level 3: State after login
        logged in {
            # Level 4: Capabilities in logged-in state
            can view dashboard
            
            # Level 5: Nested action
            can manage settings {
                # Level 6: Settings context
                managing_settings {
                    # Level 7: Specific settings actions
                    can update preferences
                }
            }
        }
    }
}
✨ Edit in Studio

State Blocks

Named blocks (like logged in, browsing) represent states or contexts:

visitor {
    can login {
        logged in {              # State: user is authenticated
            can view account     # Only available when logged in
        }
    }
    
    can shop {
        shopping {               # State: user is shopping
            can add to cart      # Only available while shopping
        }
    }
}
✨ Edit in Studio

Best Practices

Naming Conventions

  • Action names: Use verb phrases

    • can browse products
    • can view details
    • can place order
  • State names: Use present tense or adjectives

    • logged in
    • browsing
    • checking out

Organization

  1. Group related capabilities together
  2. Limit nesting depth to 4-6 levels for readability
  3. Use consistent state names across your app
  4. Start with public capabilities then authenticated ones

Example Structure

visitor {
    # Public capabilities first
    can view public_page
    can browse public_content
    
    # Authentication flows
    can login { ... }
    can register { ... }
    
    # Authenticated capabilities
    can login {
        logged in {
            # Core features
            can use_feature_a
            can use_feature_b
            
            # Account management
            can manage_account { ... }
            
            # Exit
            can logout
        }
    }
}
✨ Edit in Studio

Integration with Other Constructs

With Roles

role CustomerRole {
    permission products {
        read
    }
    permission orders {
        create,
        read
    }
}

visitor {
    can login {
        logged in {
            # Implicitly has CustomerRole permissions
            can browse products
            can place order
            can view orders
        }
    }
}
✨ Edit in Studio

With Workflows

workflow OrderFlow {
    state cart -> checkout
    state checkout -> payment
    state payment -> confirmed
}

visitor {
    can shop {
        shopping {
            can add to cart        # -> cart state
            can checkout {         # -> checkout state
                checking_out {
                    can pay         # -> payment state
                }
            }
        }
    }
}
✨ Edit in Studio

With Agents

agent OrderProcessor {
    can process order when submitted
    can send confirmation
}

visitor {
    can place order {
        # Triggers OrderProcessor agent
    }
}
✨ Edit in Studio

Complete Examples

Social Media Platform

visitor {
    can view feed
    can view profiles
    can search users
    
    can register {
        registering {
            can fill profile
            can upload avatar
            can verify email
        }
    }
    
    can login {
        logged in {
            can create post {
                posting {
                    can write text
                    can upload media
                    can add tags
                    can publish
                }
            }
            
            can interact {
                can like posts
                can comment
                can share
                can follow users
            }
            
            can manage content {
                can edit posts
                can delete posts
                can view analytics
            }
            
            can manage account {
                can update profile
                can change privacy
                can block users
            }
        }
    }
}
✨ Edit in Studio

Project Management Tool

visitor {
    can view landing
    can see pricing
    
    can signup {
        signing_up {
            can choose plan
            can enter details
            can verify
        }
    }
    
    can login {
        logged in {
            can list projects
            
            can create project {
                can set name
                can add members
                can configure
            }
            
            can enter project {
                in_project {
                    can view board
                    can create task
                    can edit task
                    can assign task
                    can comment
                    
                    can manage project {
                        can edit settings
                        can invite members
                        can view reports
                    }
                }
            }
            
            can manage workspace {
                can view billing
                can manage users
                can configure integrations
            }
        }
    }
}
✨ Edit in Studio

Common Patterns

Anonymous + Authenticated

visitor {
    # Anonymous
    can browse
    can search
    
    # Authenticated
    can login {
        logged in {
            can create
            can edit
            can delete
        }
    }
}
✨ Edit in Studio

Multi-Step Process

visitor {
    can start_process {
        step1 {
            can complete_step1 {
                step2 {
                    can complete_step2 {
                        step3 {
                            can finish
                        }
                    }
                }
            }
        }
    }
}
✨ Edit in Studio

Role-Based Access

visitor {
    can login {
        logged in {
            can access_user_features
            
            # Admin-only
            can access_admin {
                admin_mode {
                    can manage_users
                    can view_analytics
                    can configure_system
                }
            }
        }
    }
}
✨ Edit in Studio

Related Keywords

  • role - Define permissions for visitors
  • workflow - Model state transitions
  • agent - Process visitor actions

Next Steps