---
title: Config and services
description: The registry supplies settings and services that handlers use.
---

Config holds the app's settings. Services hold clients that do external work.

<Diagram caption="Create the registry at the entry with config for all handlers and services for actions, listeners, and crons.">
  <Flow>
    <Node title="env" subtitle="Read at the entry" />
    <Fan>
      <Node slot="from" title="createRegistry" subtitle="Receives config and services" tone="accent" />
      <Node title="ctx.config" subtitle="Available in every handler" />
      <Node title="ctx.services" subtitle="Actions, listeners, and crons" />
    </Fan>
  </Flow>
</Diagram>

```ts twoslash
import { init } from "logic-sdk";

declare const env: { MAX_ITEMS?: string };
declare const mailer: { sendConfirmation: (bookingId: string) => Promise<void> };
// ---cut---
const { query, createRegistry } = init<{
  scope: { actor: string | null };
  config: { bookings: { maxItems: number } };
  services: { mailer: typeof mailer };
}>();

const maxItems = query({
  async handler(ctx) {
    return ctx.config.bookings.maxItems;
  },
});

export const registry = createRegistry({
  modules: { bookings: { maxItems } },
  config: { bookings: { maxItems: Number(env.MAX_ITEMS ?? 20) } },
  services: { mailer },
});
```

- **Entry.** Read env and build clients at the entry. Declare shapes in `init`. Supply required fields to `createRegistry`.
- **Config (1).** Each handler and `jobs.scope.load` reads `ctx.config` from its registry.
- **Services (2).** Only actions, listeners, and crons get `ctx.services`. Keep client secrets inside the service.
- **Plain data.** Use strings, finite numbers, booleans, null, arrays, and plain objects. The registry reports the path of invalid values, such as a `Date`.
- **Read-only.** The registry copies and freezes config at creation. Test overrides merge object sections and replace arrays in the test registry.
- **Inspection.** See [CLI show](/docs/reference/cli#show) for config keys.

## Feature flags

Choose where to store a flag by who needs it and when its value must be current.

| Location | Use it for |
| --- | --- |
| Scope | A per-account or per-actor flag you resolve at the entry. Policies read flags here. |
| Service | A flag from an external provider. Resolve it in an action, listener, or cron. |
| Database | A flag that must be read with the rest of the transaction. Filter by account. |
| Config | A flag shared by every caller that changes when you create a new registry. |

For a job to use the original scope flag, save it in `jobs.scope.store` and carry it through `load`. To use the current value, resolve it again in `load` or read it from a service in the listener.

Pass a service flag to a query or mutation through input only if the function is internal. Clients can set the input of published functions.

## See also

[Scope](/docs/concepts/scope), [Jobs](/docs/concepts/jobs), [Testing](/docs/guides/testing)
