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

# The EdgeSpark client object

> How the EdgeSpark runtime SDK works: database, auth, storage, secrets, vars, and request context imports available inside your handlers.

The EdgeSpark runtime gives your server code a typed SDK for platform services. You import what you need from `edgespark` and `edgespark/http`, then use those values inside route handlers.

This page is about the server runtime. For browser code in the scaffolded `web/` app, use [`@edgespark/web`](/sdk/web).

## Runtime pattern

Your entry point exports a static Hono app:

```typescript server/src/index.ts theme={null}
import { db } from "edgespark";
import { auth } from "edgespark/http";
import { Hono } from "hono";
import { posts } from "@defs";

const app = new Hono().get("/api/posts", async (c) => {
  const rows = await db.select().from(posts);

  return c.json({
    posts: rows,
    userEmail: auth.user.email,
  });
});

export default app;
```

The SDK values are request-scoped, so you use them inside handlers rather than configuring them yourself.

## Client shape

The runtime is split into focused imports:

* `db` from `edgespark` for Drizzle database access
* `storage` from `edgespark` for R2 operations
* `secret` from `edgespark` for encrypted secrets
* `vars` from `edgespark` for plain environment variables
* `ctx` from `edgespark` for request-scoped helpers such as `runInBackground()` and `environment`
* `auth` from `edgespark/http` for the current authenticated user and auth helpers

## `db`

A [Drizzle ORM](https://orm.drizzle.team) instance connected to your project's D1 database:

```typescript theme={null}
const rows = await db.select().from(posts);
```

See the [database SDK reference](/sdk/database) for the full API.

## `auth`

Authentication state for the current request:

```typescript theme={null}
const email = auth.user.email;
```

Routes under `/api/*` require login. Routes under `/api/public/*` allow anonymous access. See [path-based auth](/concepts/path-based-auth).

## `storage`

Typed access to your declared buckets:

```typescript theme={null}
const object = await storage.from(buckets.uploads).get("docs/report.pdf");
```

See the [storage SDK reference](/sdk/storage) for the full API.

## `secret`

Reads environment-scoped secrets:

```typescript theme={null}
const apiKey = secret.get("STRIPE_SECRET_KEY");
```

See [manage secrets](/guides/secrets) for the CLI workflow.

## `vars`

Reads plain runtime configuration:

```typescript theme={null}
const apiBaseUrl = vars.get("PUBLIC_API_BASE_URL");
```

See the [vars SDK reference](/sdk/vars) for the runtime API.

## `ctx`

Request-scoped helpers:

```typescript theme={null}
ctx.runInBackground(sendAnalyticsEvent());

if (ctx.environment === "production") {
  // Production-only behavior
}
```

## Generated types

The runtime SDK is typed from generated files in `server/src/__generated__/`. Run `edgespark pull types` whenever you need to refresh those declarations.

## See also

<Columns cols={2}>
  <Card title="SDK overview" icon="book" href="/sdk/overview">
    The full SDK reference index for database, auth, storage, secrets, and context.
  </Card>

  <Card title="Project structure" icon="folder" href="/guides/project-structure">
    Where generated types and repo-authored defs live in the scaffold.
  </Card>
</Columns>
