Sandbox
@tinyplex/tinybase

Reactive data store and sync engine for JavaScript

TinyBase gives you a keyed store, table data, listeners, queries, indexes, metrics, and relationships. It can persist data locally or to databases, and it supports CRDT-style synchronization across devices and servers. Optional modules bind the store to React, Solid, and Svelte.

5,168 stars135 forksTypeScriptUpdated 14d ago
James Pearce - TinyBase, Local First Reactive In Browser Database
devtools-fm3.9k views • 2 years ago
Who it's for

People who are building local-first apps and want a data layer that stays in sync across sessions and devices.

What it delivers

You can keep app state reactive, offline-friendly, and synchronized without wiring those pieces together yourself.

What it does

Key-value and table storage

Create a store, set values, tables, rows, and cells, and read them back with a simple API.

Granular listeners

Watch values, tables, rows, or cells and run code when just that part of the data changes.

Reactive UI bindings

Use the optional React, Solid, and Svelte modules to bind components directly to store data.

Queries, indexes, metrics, and relationships

Build filtered, joined, grouped, and aggregated views over tabular data without writing SQL.

Persistence and sync

Save data to browser storage, IndexedDB, SQLite, PostgreSQL, and other backends, with CRDT-based synchronization.

Pre-built reactive components and tools

Use the included UI components, undo stack, and inspector tools around the store.

How to get it

  1. 1Run
    > npm create tinybase@latest
    
    📦 Creating your project...

README

Local first.

Sync on demand.

Fast always.

TinyBase is a reactive in-memory data store with persistence and synchronization for local-first JavaScript and TypeScript apps that need to feel instant, work offline, and stay consistent when they come back online.

NEW! v9.7 release

"The one with node:sqlite!"

Get started

Try the demos

Read the docs


Your first TinyBase app

Create a todo list, a chat app, a drawing tool, a charting app, or a tic-tac-toe game - with sync & persistence! - in less than 60s.

> npm create tinybase@latest

📦 Creating your project...

It's Reactive

TinyBase lets you listen to changes made to any part of your data. This means your app will be fast, since you only spend rendering cycles on things that change. The optional bindings to React, pre-built components, and charts let you easily build fully reactive UIs on top of TinyBase. You even get a built-in undo stack, and developer tools!

It's Database-Like

Consumer app? Enterprise app? Or even a game? Model key-value data and tabular data with optional typed schematization, whatever its data structures. There are built-in indexing, metric aggregation, and tabular relationships APIs - and a powerful query engine to select, join, filter, and group data (reactively!) without SQL.

It Synchronizes

TinyBase has native CRDT support, meaning that you can deterministically synchronize and merge data across multiple sources, clients, and servers. And although TinyBase is an in-memory data store, you can easily persist your data to file, browser storage, IndexedDB, SQLite or PostgreSQL databases, and more.

It's Built For A Local-First World

TinyBase works anywhere that JavaScript does, but it's especially great for local-first apps: where data is stored locally on the user's device and that can be run offline. It's tiny by name, tiny by nature: just 7.3kB - 16.4kB and with no dependencies - yet 100% tested, fully documented, and of course, open source!


TinyBase works great on its own, but also plays well with friends.

UI Frameworks

Storage & Sync

Schema Systems

(Baffled by all these logos? Check out our architectural options guide to make sense of it all!)




Start with a simple key-value store.

Creating a Store requires just a simple call to the createStore function. Once you have one, you can easily set Values in it by unique Id. And of course you can easily get them back out again.

Read more about using keyed value data in The Basics guide.

import {createStore} from 'tinybase';

const store = createStore()
  .setValues({employees: 3})
  .setValue('open', true);

console.log(store.getValues());
// -> {employees: 3, open: true}

Level up to use tabular data.

For other types of data applications, a tabular data structure is more useful. TinyBase lets you set and get nested Table, Row, or Cell data, by unique Id - and in the same Store as the keyed values!

Read more about setting and changing data in The Basics guide.

store
  .setTable('pets', {fido: {species: 'dog'}})
  .setCell('pets', 'fido', 'color', 'brown');

console.log(store.getRow('pets', 'fido'));
// -> {species: 'dog', color: 'brown'}

Register granular listeners.

The magic starts to happen when you register listeners on a Value, Table, Row, or Cell. They get called when any part of that object changes. You can also use wildcards - useful when you don't know the Id of the objects that might change.

Read more about listeners in the Listening To Stores guide.

const listenerId = store.addTableListener('pets', () =>
  console.log('changed'),
);

store.setCell('pets', 'fido', 'sold', false);
// -> 'changed'

store.delListener(listenerId);

Bind to data in UI libraries.

If you're using React, Solid, or Svelte in your application, the optional ui-react module, ui-solid module, or ui-svelte module provide hooks and functions to bind to the data in a Store.

For example, the useCell hook in this example fetches the dog's color. But it also registers a listener on that cell that will fire and re-render the component whenever the value changes!

Basically you simply describe what data you want in your user interface and TinyBase will take care of the whole lifecycle of updating it for you.

Read more about the using hooks in the Using React Hooks guide and the Building UIs With Svelte guide.

import React from 'react';
import {createRoot} from 'react-dom/client';
import {useCell} from 'tinybase/ui-react';

const App1 = () => {
  const color = useCell('pets', 'fido', 'color', store);
  return <>Color: {color}</>;
};

const app = document.createElement('div');
const root = createRoot(app);
root.render(<App1 />);
console.log(app.innerHTML);
// -> 'Color: brown'

store.setCell('pets', 'fido', 'color', 'walnut');
console.log(app.innerHTML);
// -> 'Color: walnut'

root.unmount();

Pre-built reactive components.

The UI modules also provide ba

Files in the repo

Repository payload26 top-level entries
  • .github
  • docs
  • playwright-report
  • site
  • skills
  • src
  • support
  • test
  • .gitignore
  • .prettierrc
  • agents.md
  • CODE_OF_CONDUCT.md
  • context7.json
  • CONTRIBUTING.md
  • coverage.json
  • cspell.json
  • eslint.config.js
  • gulpfile.mjs
  • LICENSE
  • package-lock.json
  • package.json
  • playwright.config.ts
  • readme.md
  • releases.md
  • svelte.config.js
  • vitest.config.ts

Discussion (0)

Ask about usage, or say what you built with it

Sign in to join the discussion.

No comments yet. Be the first to say what this is good for.

More other

🎨 Best DeepSeek Harness Design Plugin. The open-source Claude Design alternative. 🖥️ Local-first desktop app. 🖼️ Your coding agent becomes the design engine: prototypes, landing pages, dashboards, slides, images & video — real files, HTML/PDF/PPTX/MP4 export. 🤖 Claude Code / Codex / Cursor / DeepSeek Harness / OpenCode & 20+ CLIs via BYOK.

95k
tinyhumansai/
openhuman

OpenHuman is an open source personal AI for Mac, Windows and Linux — local-first memory, agent orchestration, and deep research.

40k

Your Personal AI Assistant; easy to install, deploy on your own machine or on the cloud; supports multiple chat apps with easily extensible capabilities.

35k

😎 Awesome lists about all kinds of interesting topics [NOTE: Pull requests are temporarily disabled until I have a chance to catch up with the existing ones]

505k

AIPOCH Open-Science is an open-source, local-first, model-agnostic AI research workbench for macOS, Windows, and Linux, with scientific agents, Python/R notebooks, data connectors, and reproducible provenance.

4k