Adapters

Choosing an adapter

Where your feedback lives — Prisma or SQLite for production, memory for tests and demos, localStorage for client-only setups.

An adapter is the storage layer behind InstaFix. All of them implement the same InstaFixStore contract (6 methods), so you can swap them without touching the widget.

AdapterWhere data livesUse it for
@instafix/adapter-prismaYour database, via PrismaProduction — already on Prisma
@instafix/adapter-sqliteA local .db file, via better-sqlite3Production — no ORM or database server needed
@instafix/adapter-memoryAn in-process arrayTests, previews, throwaway demos
@instafix/adapter-localstorageThe visitor's browserClient-side demos and prototypes — no server at all

Not sure which one? If the project already has Prisma set up, use it — otherwise SQLite gets you a real, durable store with nothing else to install or run. npx github:gnoopy/instafix#cli-dist init asks and wires up whichever you pick.

Need a different backend entirely (Postgres without Prisma, MongoDB, DynamoDB, …)? Write your own with @instafix/adapter-kit.

Two ways to mount a store

Server mode — the widget talks to an HTTP endpoint, and the endpoint talks to the store. This is the production shape:

// app/api/instafix/route.ts
import { createInstaFixHandler } from "@instafix/adapter-prisma";
import { prisma } from "@/lib/prisma";

export const { GET, POST, PATCH, DELETE, OPTIONS } = createInstaFixHandler({ prisma });

Client-side mode — the widget writes to a store directly in the browser, no server needed:

import { initInstaFix } from "@instafix/widget";
import { LocalStorageStore } from "@instafix/adapter-localstorage";

initInstaFix({ store: new LocalStorageStore(), projectName: "my-demo" });

Writing your own adapter? Install @instafix/adapter-kit: snapshot backends get a complete store from createCollectionStore, query backends implement the 6 methods, and both verify with the shared conformance suite (44 tests). See Writing an adapter.

Edit on GitHub

On this page