vroqjs.com

06-big-tree-and-apis/02-when-to-write-a-script.md

When to write a script

When to write a script

Write a BigTree script when the logic belongs on the server side or when the app needs a stable backend operation that should not be implemented separately in each UI file.

Good reasons to write a script

Create a script when:

  • the operation needs server-side data or services
  • multiple apps or features may reuse the same operation
  • the behavior should be centrally defined
  • secrets, tokens, or privileged access should stay out of UI code
  • the app would otherwise duplicate the same remote logic repeatedly

Examples:

  • listing server-side resources
  • executing remote debug operations
  • performing structured data updates
  • presence or RPC coordination

When not to write a script

Do not write a script when:

  • the logic is purely local UI behavior
  • the operation is only local state composition
  • an existing script already provides the needed behavior
  • a small client-side helper is enough

Avoid creating scripts that only wrap another script without adding real value.

Script ownership

A script should represent one clear backend capability.

Do not combine unrelated business operations in one generic script.

Final rule

Write a script when the behavior is truly backend-owned and should be exposed as a stable reusable operation.