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

# Adapter generator

> Add and export an adapter scaffold in an existing package

The `adapter` generator adds a named adapter object beneath an existing package’s `src/adapters` directory.

## Command

```sh theme={null}
bun run nx g @amisi-mobile-starter/generators:adapter analytics posthog
```

The positional arguments are the target package followed by the adapter name.

## Options

| Option    | Required | Description                                         |
| --------- | -------- | --------------------------------------------------- |
| `package` | Yes      | Existing directory name under `packages/`           |
| `name`    | Yes      | Adapter name normalized to a file and property name |

## Generated files

For the example above, the generator:

1. Verifies that `packages/analytics/src/index.ts` exists.
2. Stops if `packages/analytics/src/adapters/posthog.ts` already exists.
3. Creates `packages/analytics/src/adapters/posthog.ts`.
4. Adds `export * from './adapters/posthog';` to the package entry point when missing.
5. Formats the generated files.

The initial implementation is equivalent to:

```ts theme={null}
export const posthogAdapter = {
  name: 'posthog',
};
```

<Warning>
  The scaffold does not implement a domain adapter contract. Replace it with the exact interface used by the target package, add initialization and cleanup behavior where required, and test provider failures before registering it.
</Warning>

## Complete the adapter

* Keep provider SDK imports inside the adapter module.
* Match the package’s existing adapter interface and registration pattern.
* Validate configuration before making provider calls.
* Avoid embedding secrets or logging credentials.
* Add tests for initialization, operations, cleanup, and error paths.
* Run `bun run verify`.

<Card title="Create a feature package" icon="boxes-stacked" href="/generators/feature">
  Generate a minimal domain package before adding package-specific adapters.
</Card>
