> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agentfront.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Flow Generator

> Generate a @Flow class extending FlowBase

Generates a `@Flow` class with all lifecycle stage methods: `pre`, `execute`, `post`, `finalize`, and `error`.

## Usage

```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
nx g @frontmcp/nx:flow audit-log --project crm
```

## Options

| Option | Type | Default | Description |
| - | - | - | - |
| `name` | `string` | — | **Required.** The name of the flow |
| `project` | `string` | — | **Required.** The project to add the flow to |
| `directory` | `string` | — | Subdirectory within `src/flows/` |

## Generated Code

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
import { Flow, FlowBase, FlowHooksOf, z, type FlowPlan, type FlowRunOptions } from '@frontmcp/sdk';

const name = 'audit-log' as const;

const inputSchema = z.object({
  // TODO: describe the flow input
  value: z.string().default(''),
});

const outputSchema = z.object({
  // TODO: describe the flow output
  result: z.string(),
});

const stateSchema = z.object({
  result: z.string().default(''),
});

const plan = {
  pre: ['pre'],
  execute: ['execute'],
  post: ['post'],
  finalize: ['finalize'],
} as const satisfies FlowPlan<string>;

declare global {
  interface ExtendFlows {
    [name]: FlowRunOptions<AuditLogFlow, typeof plan, typeof inputSchema, typeof outputSchema, typeof stateSchema>;
  }
}

const { Stage } = FlowHooksOf<typeof name>(name);

@Flow({
  name,
  description: 'TODO: describe what this flow does',
  plan,
  inputSchema,
  outputSchema,
  access: 'public',
})
export default class AuditLogFlow extends FlowBase<typeof name> {
  @Stage('pre')
  async pre() {
    // TODO: pre-processing logic
  }

  @Stage('execute')
  async execute() {
    // TODO: main execution logic
    this.state.set('result', this.rawInput.value ?? '');
  }

  @Stage('post')
  async post() {
    // TODO: post-processing logic
  }

  @Stage('finalize')
  async finalize() {
    this.respond({ result: this.state.result ?? '' });
  }
}
```

The `declare global { interface ExtendFlows }` block registers the flow's input, output and state types, so `runFlow('audit-log', …)` is fully typed. Each step in the `plan` is implemented by a method decorated with `@Stage`, and `FlowHooksOf(name)` exposes `Stage`, `Will`, `Did` and `Around` for plugins that hook the flow.

See the [Flows guide](/frontmcp/servers/flows) for lifecycle details and hook integration.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.