Skip to content

# Create your first flow

Now that pgflow is installed, let’s create a simple greeting workflow that demonstrates the core concepts.

Not production ready

pgflow is currently in Alpha stage and not yet production ready.

Prerequisites

- Completed the pgflow installation
- Basic understanding of TypeScript

## Creating a Simple Greeting Flow

Section titled “Creating a Simple Greeting Flow”

Our workflow will:

1. Take a person’s first and last name as input
2. Format a full name
3. Create a personalized greeting

### 1. Set up your project structure

Section titled “1. Set up your project structure”

First, create a directory for your flow:

    mkdir -p supabase/functions/_flows

- Directory
  supabase
  - Directory
    functions
    - Directory
      _flows
      - greet_user.ts

### 2. Create the flow definition

Section titled “2. Create the flow definition”

Create a file called `supabase/functions/_flows/greet_user.ts` with this content:

supabase/functions/_flows/greet_user.ts

    import { Flow } from 'npm:@pgflow/dsl';
    type Input = {  first_name: string;  last_name: string;};
    export default new Flow<Input>({  slug: 'greet_user',})  .step(    { slug: 'full_name' },    (input) => `${input.run.first_name} ${input.run.last_name}`  )  .step(    { slug: 'greeting', dependsOn: ['full_name'] },    (input) => `Hello, ${input.full_name}!`  );

### How this flow works

Section titled “How this flow works”

1. Input: The flow receives `first_name` and `last_name` parameters
2. first_name step: Combines the names using `input.run` to access the flow input
3. greeting step: Takes the result of the first step (via `input.full_name`) and creates a greeting

When run with `{"first_name": "Alice", "last_name": "Smith"}`, this produces `{ "greeting": "Hello, Alice Smith!" }`.

Key Concepts

- input.run: Contains the original flow input, accessible in every step
- step slugs: Unique identifiers for each step
- dependsOn: Specifies which steps must complete before a step can run
- JSON serialization: All inputs and outputs must be JSON-serializable

For more in-depth explanation of the Flow DSL, see Understanding the Flow DSL.