Organize Flow code
This guide outlines best practices for organizing your pgflow codebase to improve maintainability, reusability, and clarity.
How to structure your code
Section titled “How to structure your code”Following the pattern from Create Flow, organize flows and tasks in underscore-prefixed folders using Supabase’s pattern for shared code:
mkdir -p supabase/functions/_flows supabase/functions/_tasksDirectorysupabase
Directoryfunctions
Directory_flows
- analyze_website.ts
Directory_tasks
- scrapeWebsite.ts
- summarizeWithAI.ts
- extractTags.ts
- saveWebsite.ts
Directoryanalyze_website_worker
- index.ts
- deno.json
This structure enables:
- Sharing tasks across multiple flows
- Running multiple workers for the same flow (horizontal scaling)
- Clear separation of flow definitions from execution
- Standard Supabase pattern for shared code
Learn more
Section titled “Learn more” Create Reusable Tasks How to design task functions that work well across multiple flows
Naming flow steps Best practices for naming steps in your flows
Examples
Section titled “Examples” AI Web Scraper Tutorial See the shared structure pattern in action with a complete real-world example