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

# Flows-101

Almost every runtime has a main thread. Whatever code you write, it's executed by that thread unless specified otherwise.

In metz, that's not the case. If you want something executed, you need to create a "thread". If you don't, things simply don't run.

In metz, **a flow captures the idea of a thread**. It's not *exactly* that, but there's good overlap.

For example, here are two story scripts. One does nothing, and the other works:

<CodeGroup>
  ```typescript Authenticate Normally theme={null}
  const service = new AuthenticationService();

  /*
   * This code will have no effect.
  */
  service.authenticate('123');
  ```

  ```typescript Authenticate but DB is down theme={null}
  const service = new AuthenticationService();
  service.isDatabaseDown = true;

  /*
   * Will actually start executing 'authenticate'.
  */
  std.flow("Authenticate user", service).authenticate('123').run();
  ```
</CodeGroup>

<br />

Unlike threads, flows have an identity that you provide. It's not a nameless, behind the scene thing executing your code. Flows are front and center.

## Business and Logical Flows

In PRDs, or even Design Documents you might have come across the term 'Flow'. Something like 'User login' flow or 'Use Cache' flow.

In those documents, a flow represents a sequence of events that occur under that context. Mind you, the flow is a small part of a larger picture, it
doesn't tell the full story. We could be talking about a PRD to launch referrals or a Design Document about data pipelines.

We choosing the same terminology in metz is not serendipitous. It's called a flow in metz to capture this exact meaning.

**A business or logical flow, and a metz flow are meant to be exactly the same.**

<Accordion title="How is it different from a story?">
  Once again, as is the case with PRDs and Design documents, a flow is a small part of a larger design.

  A story can be talking about 'User accepts referral', and it can contain a flow called 'User signs up'. And the signup flow will kick off
  a chain of events, data getting passed around, but all under the context of 'User signs up'.
  <br />Which in turn is happening in service of a user accepting a referral.

  The story could change to 'User refuses referral', and the 'User signs up' flow will still kick off and do its job.
</Accordion>

You can see how flows interact with each other and the system:

<video muted playsInline controls className="w-full aspect-video" src="https://mintcdn.com/metzsh/fELY9edQkrehV0tS/videos/flws.mp4?fit=max&auto=format&n=fELY9edQkrehV0tS&q=85&s=9d059bcce2378f16505393045a933b37" data-path="videos/flws.mp4" />

## How to use flows?

You can [create a flow](/standard-library#flow) through the following syntax:

```typescript theme={null}
std.flow(
	"<name of the flow>",
	main, // An instance of a class.
)
.hello() // Simply call the method you want to run.
.run(); // Normal flows are not eagerly executed, call 'run' when you want.
```

<Accordion title="My flow is not running. Why?">
  1. Did you use `std.flow` to create it?
  2. If yes, then did you pass an instance of the class and not some other object?
  3. Did you call the method you want to execute?
  4. Did you call `.run()` on the method you want to execute?

  If the answer is yes to all the question and it still doesn't work, please [create an issue](https://github.com/metz-sh/simulacrum/issues/new) on github.
  Or for a swifter response, [join our slack](https://metzcommunity.slack.com/join/shared_invite/zt-1xr4ooes0-AhIP47ENEqrKmnfpCw6e8Q#/shared-invite/email) and we will get on it right away.
</Accordion>

There's so much more to flows but we will stop here for now and dig deeper in [Flows-102](/flows-102) later.

<br />

And with that, we have learnt the basic building blocks of metz. Go to the [playground](https://app.metz.sh/try) to try those things,
but come back soon!

In the next section we will cover how to go beyond just one class and file.
