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

# Configuration

Pass `SyncClientOptions` to `createSyncClient`.

## Quick example

```ts
import { createSyncClient } from "@stratasync/client";

const client = createSyncClient({
  // Required adapters
  storage: storageAdapter,
  transport: transportAdapter,
  reactivity: reactivityAdapter,

  // Optional
  dbName: "my-app-sync",
  userId: "user-123",
  version: 1,
  userVersion: 1,
  groups: ["workspace-abc"],
  optimistic: true,
  batchMutations: true,
  batchDelay: 50,
  bootstrapMode: "auto",
  rebaseStrategy: "server-wins",
  fieldLevelConflicts: true,
});
```

## Required adapters

### storage

**Type:** `StorageAdapter`

Local persistence for model rows, metadata, the outbox, partial indexes, and sync actions.

```ts
import { createIndexedDbStorage } from "@stratasync/storage-idb";

const storage = createIndexedDbStorage();
```

The `StorageAdapter` interface defines methods for:

- `get`, `getAll`, `put`, `delete`: basic CRUD for model rows
- `getByIndex`: indexed lookups
- `getMeta`, `setMeta`: sync metadata (last sync ID, schema hash, and more)
- `getOutbox`, `addToOutbox`, `removeFromOutbox`: pending transaction persistence
- `hasPartialIndex`, `setPartialIndex`: partial model index tracking
- `addSyncActions`, `getSyncActions`, `clearSyncActions`: sync action log
- `writeBatch`: batch write operations
- `clear`, `count`: storage management

### transport

**Type:** `TransportAdapter`

Server communication: bootstrap, delta subscriptions, batch mutations, and connection state.

```ts
import { createGraphQLTransport } from "@stratasync/transport-graphql";

const transport = createGraphQLTransport({
  endpoint: "https://api.example.com/graphql",
  syncEndpoint: "https://api.example.com/sync",
  wsEndpoint: "wss://api.example.com/sync/ws",
  auth: { getAccessToken: async () => "token" },
});
```

The `TransportAdapter` interface defines:

- `bootstrap(options)`: stream initial data as `AsyncGenerator<ModelRow>`
- `batchLoad(options)`: lazy-load models by index
- `mutate(batch)`: submit transaction batches
- `subscribe(options)`: real-time delta subscription
- `fetchDeltas(after, limit?)`: poll for missed deltas
- `getConnectionState()`: current connection state
- `onConnectionStateChange(callback)`: subscribe to connection changes
- `close()`: clean up resources

### reactivity

**Type:** `ReactivityAdapter`

Makes identity map entries observable for UI re-rendering.

```ts
import { createMobXReactivity } from "@stratasync/mobx";

const reactivity = createMobXReactivity();
```

## Simple options

All optional.

| Option           | Type                                        | Default     | Description                                                                                                                                                              |
| ---------------- | ------------------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `dbName`         | `string`                                    | `"sync-db"` | Database name for storage. Each unique name creates a separate IndexedDB database.                                                                                       |
| `userId`         | `string`                                    | -           | Logged-in user ID. Used for storage isolation in multi-user scenarios.                                                                                                   |
| `version`        | `number`                                    | -           | Client version for storage naming. Incrementing triggers a fresh bootstrap.                                                                                              |
| `userVersion`    | `number`                                    | -           | Per-user version for storage naming. Incrementing triggers a fresh bootstrap.                                                                                            |
| `groups`         | `string[]`                                  | -           | Sync groups for multi-tenancy. The client syncs only models belonging to the specified groups.                                                                           |
| `optimistic`     | `boolean`                                   | `true`      | Apply mutations to the identity map before the server confirms them. Rolls back on rejection.                                                                            |
| `batchMutations` | `boolean`                                   | `false`     | Batch multiple mutations into a single network request.                                                                                                                  |
| `batchDelay`     | `number` (ms)                               | -           | Delay before sending a mutation batch. Only applies when `batchMutations` is `true`.                                                                                     |
| `bootstrapMode`  | `"auto" \| "full" \| "local"`               | `"auto"`    | `auto`: use local storage if available and the schema matches, otherwise bootstrap from server. `full`: always bootstrap from server. `local`: never contact the server. |
| `schema`         | `SchemaDefinition \| ModelRegistrySnapshot` | -           | Explicit schema definition. If omitted, the client uses the global `ModelRegistry` populated by decorators.                                                              |
| `modelFactory`   | `ModelFactory \| ModelFactoryFactory`       | -           | Custom factory for creating model instances from raw data. Defaults to `ModelRegistry` constructors with `_applyUpdate`.                                                 |
| `yjsTransport`   | `YjsTransport`                              | -           | Yjs transport for collaborative editing. Enables `client.yjs` with document and presence managers. See [Y-Doc](/packages/y-doc).                                         |

## Conflict resolution

### rebaseStrategy

**Type:** `"server-wins" | "client-wins" | "merge"`: **Default:** `"server-wins"`

How the client resolves conflicts with concurrent server changes.

| Strategy        | Behavior                                                            |
| --------------- | ------------------------------------------------------------------- |
| `"server-wins"` | Server changes take precedence. Client changes drop on conflict.    |
| `"client-wins"` | Client changes take precedence. Server changes are overridden.      |
| `"merge"`       | Field-level merge. Non-conflicting fields from both sides are kept. |

### fieldLevelConflicts

**Type:** `boolean`: **Default:** `true`

Detect conflicts per-field rather than per-model. When enabled, non-overlapping field changes coexist without conflict.