# Open Function Standard

> The Open Function Standard — write backend functions that declare dependencies in a manifest. Run anywhere: Cloudflare Workers, Node.js, Bun, or Deno.

The Open Function Standard (OFS) is a specification for writing portable backend functions. An OFS function declares its dependencies (database, cache, AI, etc.) in a manifest — the runtime provides them. The same function runs on Cloudflare Workers, Node.js, Bun, or Deno without modification.

## The problem OFS solves

When you write a backend function today, it's tightly coupled to your platform:

```ts
// Platform-specific: only works on Cloudflare Workers

  async fetch(request, env) {
    const db = env.DB
    const result = await db.prepare('SELECT * FROM users WHERE id = ?')
      .bind(userId)
      .first()
    return Response.json(result)
  }
}
```

Move this to Node.js or Bun? Rewrite everything.

## The OFS approach

An OFS function declares what it needs. The runtime injects it:

```ts
// OFS function — runs on any supported runtime

  const user = await sdk.db.queryOne('SELECT * FROM users WHERE id = ?', [userId])
  return { user }
}
```

The `sdk` argument is injected by the OFS runner. On the edge, it uses the native database binding. On Node.js, it uses a compatible adapter. The function is identical.

## OFS manifest

Every OFS function has an `aerostack.json` manifest:

```json
{
  "name": "get-user",
  "version": "1.0.0",
  "description": "Fetch a user by ID",
  "runtime": "workers",
  "inputs": {
    "userId": { "type": "string", "required": true }
  },
  "outputs": {
    "user": { "type": "object" }
  },
  "requires": ["db"],
  "auth": "required"
}
```

| Field | Description |
|-------|-------------|
| `name` | Unique function identifier |
| `version` | Semantic version |
| `runtime` | Target runtime: `workers`, `node`, `bun`, `deno`, `any` |
| `inputs` | Input schema (validated before execution) |
| `outputs` | Output schema (validated after execution) |
| `requires` | SDK capabilities needed: `db`, `cache`, `ai`, `storage`, `queue`, `realtime` |
| `auth` | Authentication requirement: `required`, `optional`, `none` |

## Supported runtimes

| Runtime | Status |
|---------|--------|
| Cloudflare Workers | ✓ Stable |
| Node.js 20+ | ✓ Stable |
| Bun | ✓ Stable |
| Deno | Beta |
| Python | Beta (via generated SDK) |

## Why this matters

- **Publish once** — share a function in the Community Hub that any project can use
- **No vendor lock-in** — your functions aren't tied to one cloud
- **Testable** — run functions locally with mock SDK injections
- **Composable** — functions call other functions, building complex pipelines from simple pieces

OFS is the foundation for both the [Community Hub](/hub) (reusable functions) and the [Agents Marketplace](/agent-endpoints) (AI agents). Learning OFS unlocks both.

## Next steps

- [Writing OFS Functions](/ofs/writing) — step-by-step guide with examples
- [Publishing to the Hub](/ofs/publishing) — share your functions with the community
