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

# A safe backend for an app built with AI

> Configure a backend with managed Postgres, sign-in, scheduled jobs, and secrets.

Configure managed Postgres, sign-in, and scheduled jobs in `floo.app.toml`, and store secrets outside the repository. Your server connects to the database and decides which rows each signed-in user can access.

## Declare the backend

```toml floo.app.toml theme={null}
[app]
name = "orders"
access_mode = "accounts"

[services.web]
type = "web"
path = "."
port = 8000
ingress = "public"

[managed.default]
type = "postgres"

[[routes]]
path = "/"
service = "web"
access = "accounts"

[[routes]]
path = "/api/export"
service = "web"
access = "api_key"
scope = "orders.read"

[cron.daily-digest]
schedule = "0 8 * * *"
command = "python -m jobs.daily_digest"
service = "web"
```

| Block | What floo does |
| - | - |
| `[managed.default]` | Provisions Postgres on the next deploy and injects `DATABASE_URL` into the server's environment |
| `access_mode = "accounts"` | Redirects anyone not signed in to floo's sign-in page; signed-in requests reach your code with `X-Floo-User-Email`, `X-Floo-User-Id`, and `X-Floo-User-Role` |
| `[[routes]]` with `access = "api_key"` | Admits a program on `/api/export` only with an app API key holding `orders.read`, and strips the key before forwarding |
| `[cron.daily-digest]` | Runs the command at 08:00 UTC in the `web` image, with the same env vars |

Store secrets outside git, through stdin so the value stays out of shell history:

```bash theme={null}
printf '%s' "$MAIL_API_KEY" | floo env set MAIL_API_KEY --stdin --secret --app orders --restart
```

Then commit and deploy:

```bash theme={null}
floo deploy --preflight
git add . && git commit -m "feat: add the orders backend"
floo deploy
```

## Scope rows to the signed-in user

The gateway has already checked the session. Your code reads who the user is from a header and scopes every query to them:

```python app/orders.py theme={null}
import os
from typing import Annotated

import psycopg
from fastapi import FastAPI, Header

app = FastAPI()


@app.get("/orders")
def my_orders(email: Annotated[str, Header(alias="X-Floo-User-Email")]):
    with psycopg.connect(os.environ["DATABASE_URL"]) as conn:
        rows = conn.execute(
            "SELECT id, total FROM orders WHERE owner_email = %s", [email]
        ).fetchall()
    return [{"id": r[0], "total": r[1]} for r in rows]
```

A request without a session never reaches this route, and floo's gateway drops any `X-Floo-*` header a caller sends, so the email comes from floo.

## Why data stays private

* **No database credentials in the browser.** Only your server's environment holds `DATABASE_URL`. Variables prefixed `NEXT_PUBLIC_`, `VITE_`, or `REACT_APP_` are baked into the browser bundle, so never put a secret under those names.
* **Sign-in before your code.** In `accounts` mode, floo's gateway validates the session on every request. Signed-in responses are marked `private`, so no shared cache serves one user's page to another.
* **Separate data per environment.** Dev and prod use separate databases with separate credentials. A preview gets its own database branch and never receives dev or prod credentials.
* **Write-only secrets.** A new env var is stored as a write-only secret, and `--json` output redacts secret-shaped values, so an agent's transcript does not capture them.
* **Scoped program access.** An app API key opens only the routes and scopes you declare, and is revocable on its own. Removing a member revokes their sessions at once.

## Next steps

> [card] [Postgres](https://getfloo.com/docs/guides/postgres.md)
>
> Injected variables, pgvector, migrations, and backups.

> [card] [App sign-in](https://getfloo.com/docs/guides/app-auth.md)
>
> Identity headers, invites, app roles, and sign-out.

> [card] [App API keys](https://getfloo.com/docs/guides/app-api-keys.md)
>
> Consumers, scopes, rate limits, and request history.

> [card] [Cron jobs](https://getfloo.com/docs/guides/cron-jobs.md)
>
> Schedules, timeouts, manual runs, and failure handling.

For customer sign-up instead of team sign-in, see [User accounts](https://getfloo.com/docs/guides/user-accounts.md).


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