> For the complete documentation index, see [llms.txt](https://manual.bubble.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://manual.bubble.io/help-guides/logic.md).

# Logic

Logic is what makes a Bubble app do things. Learn how workflows, dynamic expressions, conditions, and navigation work together on the frontend and backend.

In the [*Design*](https://manual.bubble.io/help-guides/design.md) section, we looked at how to make your app look the way you want, and in the [*Data*](https://manual.bubble.io/help-guides/data.md) section, how information is stored, changed, and fetched from the database[^1]. The *Logic* section covers how to make your app *do* things.

Logic is what happens when a user interacts with your app: what runs when they click a button, what they're allowed to see, which page they end up on, and what gets saved along the way. In Bubble, you build that logic visually, by combining [workflows](#workflows), [dynamic expressions](#dynamic-expressions), and [conditions](#conditions). Together they can handle anything from a single button click to complex processes that run on the server without the user ever seeing them. You can also [ask the Bubble AI Agent](#build-logic-with-bubble-ai) to build logic for you, then review and edit what it creates.

## How the pieces fit together

Most features in your app use several of these tools at once. Say you're building a **Publish** button for a blog post:

<table><thead><tr><th width="206.9609375">Part</th><th>What it does in the example</th></tr></thead><tbody><tr><td><a href="#frontend-and-backend">Frontend and backend</a></td><td>The click happens on the <strong>user's device</strong>, while the change to the database happens on <strong>Bubble's server</strong>.</td></tr><tr><td><a href="#workflows">Workflow</a></td><td>When the user clicks <strong>Publish</strong>, a workflow runs that changes the post's status and sends the user to the post.</td></tr><tr><td><a href="#dynamic-expressions">Dynamic expression</a></td><td>The workflow uses expressions like <code>Current page's Post</code> to know which post to change.</td></tr><tr><td><a href="#conditions">Condition</a></td><td>The button is only visible when <a data-footnote-ref href="#user-content-fn-2"><code>Current User</code></a> is the post's author. A matching condition on the workflow stops it from running for anyone else.</td></tr><tr><td><a href="#navigation">Navigation</a></td><td>After publishing, the user is taken to the published post's page.</td></tr></tbody></table>

The articles in this section cover each of these in detail.

***

## Frontend and backend

Every Bubble app runs in two places: the *frontend*, which is the user's browser or device, and the *backend*, which is Bubble's server. Some logic runs on one side, some on the other, and knowing the difference helps you build apps that are fast, secure, and reliable. For example, showing a popup[^3] happens instantly on the user's device, while saving a record or running a scheduled task happens on the server.

**Article:** [The frontend and backend](https://manual.bubble.io/help-guides/logic/the-frontend-and-backend.md)

***

## Workflows

A workflow connects an [*event*](https://manual.bubble.io/help-guides/logic/workflows/events.md), such as a user clicking a button, with one or more [*actions*](https://manual.bubble.io/help-guides/logic/workflows/actions.md), such as saving data to the [database](https://manual.bubble.io/help-guides/data/the-database.md), showing an element[^4], or sending an email. Workflows are where most of your app's logic lives.

You can also run workflows on the server, as [*backend workflows*](https://manual.bubble.io/help-guides/logic/the-frontend-and-backend.md#backend-workflows). These can run on a schedule, be triggered by changes in the database, or be called from other workflows and external services.

**Article series:** [Workflows](https://manual.bubble.io/help-guides/logic/workflows.md)

***

## Dynamic expressions

Dynamic expressions let you work with values that change, instead of typing in fixed values. You build them like sentences, combining a [*data source*](#user-content-fn-5)[^5], such as [`Current User`](https://manual.bubble.io/core-resources/data/data-sources.md#current-user) or [`Do a search for`](#user-content-fn-6)[^6], with [*operators*](#user-content-fn-7)[^7] that narrow it down or transform it. With expressions, you can calculate values, search the database, check whether something is true, and pull in data from [external APIs](#user-content-fn-8)[^8].

**Article:** [Dynamic expressions](https://manual.bubble.io/help-guides/logic/dynamic-expressions.md)\
**Video:** [How to build expressions](https://www.youtube.com/watch?v=mrh8OV79snk)

***

## Conditions

Conditions are rules that decide how elements, workflows, and actions behave. On an element, a condition can change how it looks or works, such as hiding a button or making it unclickable when the user isn't logged in. On a workflow or action, a condition decides whether it runs at all, such as stopping a workflow if the user doesn't have permission.

{% hint style="warning" %}
Element conditions are useful for the user experience, but they aren't a security measure. A technical user can change how an element behaves on their own device, so use a condition on the workflow to stop it from running, and [privacy rules](#user-content-fn-9)[^9] to protect data.

**Article section:** [Using conditions for security](https://manual.bubble.io/help-guides/logic/conditions.md#using-conditions-for-security)
{% endhint %}

**Article:** [Conditions](https://manual.bubble.io/help-guides/logic/conditions.md)

***

## Navigation

Navigation is how users move around your app. In a web app, that can mean going to another page, either in your own app or on an external site, or moving around within the same page by showing and hiding elements, without reloading. With [Bubble for native mobile apps](https://manual.bubble.io/help-guides/getting-started/building-for.../native-ios-and-android.md), users move between views[^10] instead, using a tab bar or the *Go to view* action.

**Article series:** [Navigation](https://manual.bubble.io/help-guides/logic/navigation.md)

***

## Device resources

Native mobile apps can also use resources on the user's device, such as the camera and photo library, location services, and push notifications. Users may need to grant permission first.

**Article series:** [Device resources](https://manual.bubble.io/help-guides/logic/device-resources.md)

***

## Build logic with Bubble AI

You don't have to build all of your logic by hand. The [Bubble AI Agent](https://manual.bubble.io/help-guides/ai/bubble-ai-agent.md) can create and edit frontend and backend workflows, generate dynamic expressions, and explain how your app works. Describe what you want in plain language, and depending on the approval mode you've picked, the Agent can show you a plan to approve or cancel before it changes anything. Everything it builds stays visual, so you can open the **Workflow** or **Backend workflows** tab to review it and edit it yourself.

Keep each prompt focused on one feature, and select the element or workflow you mean first, so the Agent has the right context. The Agent declines very complex workflows, and it can't build custom events, payment actions, or analytics actions in backend workflows. It can still explain how to set those up yourself.

Here are a few prompts to try:

{% code overflow="wrap" %}

```
Create a workflow that runs when the user clicks the Publish button. It should change the status of the current page's Post to Published, then send the user to the post's page.
```

{% endcode %}

{% code overflow="wrap" %}

```
Can you generate an expression for this text element that shows how many posts the current user has written?
```

{% endcode %}

{% code overflow="wrap" %}

```
Create a backend workflow named publish-post with a parameter for post. It should change the post's status to Published, and only run if the status is Draft.
```

{% endcode %}

```
Why isn't this workflow running?
```

{% code overflow="wrap" %}

```
Can you explain all the places a user can navigate to from this page?
```

{% endcode %}

**Article:** [Edit apps with AI](https://manual.bubble.io/help-guides/ai/bubble-ai-agent/edit-apps-with-ai.md)\
**Article:** [Generate apps with AI](https://manual.bubble.io/help-guides/ai/bubble-ai-agent/generate-apps-with-ai.md)

***

## FAQ: Logic

<details>

<summary>What does logic mean in Bubble?</summary>

Logic is everything your app does, as opposed to how it looks or what data it stores. It covers what runs when a user clicks a button, what they're allowed to see, and where they end up. You build it with workflows, dynamic expressions, and conditions. For an example of how they work together, see [How the pieces fit together](#how-the-pieces-fit-together).

</details>

<details>

<summary>Do I need to know how to code to build logic in Bubble?</summary>

No. You build logic visually: workflows are made up of events and actions you set up in the **Workflow** tab, and expressions read like sentences. You can also describe what you want to the [Bubble AI Agent](https://manual.bubble.io/help-guides/ai/bubble-ai-agent.md), and it builds the logic for you to review.

</details>

<details>

<summary>What's the difference between a workflow, a dynamic expression, and a condition?</summary>

A workflow *does* something: an event starts it, and its actions run. A dynamic expression *produces a value*, such as a number, a text, or a list of things, and you can use it in elements, conditions, and workflows. A condition is an expression that returns a yes or a no, and it decides how an element looks or whether a workflow or action runs.

</details>

<details>

<summary>Should my logic run on the frontend or the backend?</summary>

Use the frontend when you're reacting to what the user does on the page. Use the backend when work needs to happen without the user, such as on a schedule or in response to a change in the database, or when it has to finish even if the user leaves.

**Article section:** [Why the difference matters](https://manual.bubble.io/help-guides/logic/the-frontend-and-backend.md#why-the-difference-matters)

</details>

<details>

<summary>Is hiding a button enough to keep my app secure?</summary>

No. Hiding an element or making it unclickable helps the user experience, but a technical user can get around it. To stop something from running, place a condition on the workflow, ideally one that's checked on the server, such as a field on `Current User`. To protect data, use [privacy rules](https://manual.bubble.io/help-guides/data/the-database/protecting-data-with-privacy-rules.md), which keep data from reaching the user's device. The [security dashboard](https://manual.bubble.io/help-guides/security/security-dashboard.md) can also flag potential vulnerabilities in your app.

**Article section:** [Using conditions for security](https://manual.bubble.io/help-guides/logic/conditions.md#using-conditions-for-security)

</details>

<details>

<summary>Does the logic in my app affect workload?</summary>

It can. Work done on Bubble's server uses [workload](https://manual.bubble.io/help-guides/workload.md), the measure of how much server work your app does. Actions that run only on the user's device, like showing an element or setting a custom state, don't add to it.

**Article:** [Optimizing workload](https://manual.bubble.io/help-guides/workload/optimizing-workload.md)

</details>

<details>

<summary>Does logic work the same way in native mobile apps?</summary>

Mostly. Native mobile apps and web apps are both built on workflows and a database, so the same ideas apply. The main differences are that users move between views instead of pages, and that native mobile apps can use [device resources](#device-resources).

**Article:** [Native mobile vs. web development](https://manual.bubble.io/help-guides/getting-started/building-for.../native-ios-and-android/native-mobile-vs.-web-development.md)

</details>

[^1]: The database stores all your app's data, such as users, posts, and orders.\
    **Article:** [The database](https://manual.bubble.io/help-guides/data/the-database.md)

[^2]: Using the `Current User` data source, you can automatically fetch the data saved on the user currently using the app.\
    **Article:** [User accounts](https://manual.bubble.io/help-guides/data/user-accounts.md)

[^3]: A popup is a container that hovers above all other elements on the screen.\
    **Article:** [Popup element (web)](https://manual.bubble.io/help-guides/design/elements/web-app/containers/popups.md)

[^4]: *Elements* are the objects that you place on the page as you design your app. There are many different types of elements, like texts, buttons, input fields, and calendars.\
    **Article series:** [Elements](https://manual.bubble.io/help-guides/design/elements.md)

[^5]: A data source is any place from which Bubble can retrieve data, such as the database, the current user, or an API.\
    **Reference:** [Data sources](https://manual.bubble.io/core-resources/data/data-sources.md)

[^6]: Bubble lets you set up flexible database searches and narrow down the results by applying dynamic constraints. Database searches are made using the `Do a search for` data source.\
    **Article:** [Finding data in the database](https://manual.bubble.io/help-guides/data/the-database/finding-data.md)

[^7]: Operators are functions that can be performed on a data source, such as counting, sorting, and calculating.\
    **Reference:** [Operators](https://manual.bubble.io/core-resources/data/operations-and-comparisons.md)

[^8]: An API call sends a request to an external app to get data back. For example, you could send a request to a weather service to get updated weather information. Outgoing API calls are made with the API Connector.\
    **Article:** [The API Connector](https://manual.bubble.io/help-guides/integrations/api/the-api-connector.md)

[^9]: Privacy rules decide which data each user is allowed to see, before anything is sent to their device.\
    **Article:** [Protecting data with privacy rules](https://manual.bubble.io/help-guides/data/the-database/protecting-data-with-privacy-rules.md)

[^10]: A view is the top-level element in a native mobile app, serving the same role that a page does in a web app.\
    **Article:** [The view element (mobile)](https://manual.bubble.io/help-guides/design/elements/ios-and-android-app/the-view.md)
