MCPcopy Index your code
hub / github.com/instantdb/instant

github.com/instantdb/instant @main

repository ↗ · DeepWiki ↗ · Ask this repo → · + Follow
5,790 symbols 17,683 edges 1,273 files 179 documented · 3% updated 4d ago★ 10,35012 open issues
README

  <img alt="Shows the Instant logo" src="https://instantdb.com/readmes/logo_with_text_light_mode.svg">

stars

Get Started · Examples · Try the Demo · Docs · Discord

Instant is the best backend for AI-coded apps. You get auth, permissions, storage, presence, and streams — everything you need to ship apps your users will love.

You write relational queries in the shape of the data you want and Instant handles all the data fetching, permission checking, and offline caching. When you change data, optimistic updates and rollbacks are handled for you as well. Plus, every query is multiplayer by default.

We also support ephemeral updates, like cursors, or who's online. Currently we have SDKs for Javascript, React, and React Native.

How does it look? Here's a barebones chat app in about 12 lines:

// ༼ つ ◕_◕ ༽つ Real-time Chat
// ----------------------------------
// * Updates instantly
// * Multiplayer
// * Works offline

import { init, id } from "@instantdb/react";

const db = init({ 
  appId: process.env.NEXT_PUBLIC_APP_ID,
});

function Chat() {
  // 1. Read
  const { isLoading, error, data } = db.useQuery({
    messages: {},
  });

  // 2. Write
  const addMessage = (message) => {
    db.transact(db.tx.messages[id()].update(message));
  };

  // 3. Render!
  return <UI data={data} onAdd={addMessage} />;
}

Want to see for yourself? try a demo in your browser.

Motivation

Writing modern apps is full of schleps. Most of the time you start with the server: stand up databases, caches, ORMs, and endpoints. Then you write client-side code: stores, selectors, mutators. Finally you paint a screen. If you add multiplayer you need to think about stateful servers, and if you support offline mode, you need to think about IndexedDB and transaction queues.

To make things worse, whenever you add a new feature, you go through the same song and dance over and over again: add models, write endpoints, stores, selectors, and finally the UI.

Could it be better?

In 2021, we realized that most of the schleps we face as UI engineers are actually database problems in disguise. (We got into greater detail in this essay)

Shows how Instant compresses schleps

If you had a database on the client, you wouldn't need to think about stores, selectors, endpoints, or local caches: just write queries. If these queries were multiplayer by default, you wouldn't have to worry about stateful servers. And if your database supported rollback, you'd get optimistic updates for free.

So we built Instant. Instant gives you a database you can use in the client, so you can focus on what’s important: building a great UX for your users, and doing it quickly.

Architectural Overview

Here's how Instant works at a high level:

Shows how Instant compresses schleps

Under the hood, we store all user data as triples in one big Postgres database. A multi-tenant setup lets us offer a free tier that never pauses.

A sync server written in Clojure talks to Postgres. We wrote a query engine that understands datalog and InstaQL, a relational language that looks a lot like GraphQL:

// give me all users, their posts and comments
{
  users: {
    posts: {
      comments: {
      }
    }
  }
}

Taking inspiration from Asana’s WorldStore and Figma’s LiveGraph, we tail postgres’ WAL to detect novelty and invalidate relevant queries.

For the frontend, we wrote a client-side triple store. The SDK handles persisting a cache of recent queries to IndexedDB on web, and AsyncStorage in React Native.

All data goes through a permission system powered by Google's CEL library.

Getting Started

The easiest way to get started with Instant is by signing up on instantdb.com. You can create a functional app in 5 minutes or less.

If you have any questions, you can jump in on our discord.

Contributing

You can start by joining our discord and introducing yourself. Even if you don't contribute code, we always love feedback.

If you want to make changes, start by reading the client and server READMEs. There you'll find instructions to start Instant locally.

Extension points exported contracts — how you extend this code

EventSourceType (Interface)
(no doc) [10 implementers]
client/packages/core/src/Connection.ts
ButtonProps (Interface)
(no doc)
client/www/components/components/ui/button.tsx
AppProps (Interface)
(no doc)
client/sandbox/react-nextjs/pages/bugs/cascade-delete.tsx
AppSchema (Interface)
(no doc)
server/flags-config/instant.schema.ts
AppSchema (Interface)
(no doc)
examples/solidjs-vite/src/instant.schema.ts
AppSchema (Interface)
(no doc)
examples/ai-chat/src/instant.schema.ts
AppSchema (Interface)
(no doc)
examples/next-js-app-dir/src/instant.schema.ts
AppSchema (Interface)
(no doc)
examples/vue-vite/src/instant.schema.ts

Core symbols most depended-on inside this repo

push
called by 519
client/packages/core/src/Stream.ts
update
called by 403
client/packages/webhooks/src/index.ts
cn
called by 392
examples/ai-chat/src/lib/utils.ts
join
called by 363
client/www/components/new-landing/StreamsDemoJoin.tsx
transact
called by 337
client/packages/core/src/index.ts
id
called by 263
client/packages/core/src/utils/id.ts
optional
called by 210
client/packages/core/src/schemaTypes.ts
error
called by 198
client/packages/platform/src/api.ts

Shape

Function 4,476
Method 785
Class 283
Interface 244
Enum 1
Route 1

Languages

TypeScript90%
Python9%
Java1%

Modules by API surface

client/packages/core/src/Reactor.js113 symbols
client/packages/cli/src/ui/index.ts87 symbols
client/packages/platform/src/api.ts75 symbols
client/packages/core/src/Stream.ts61 symbols
client/packages/core/src/store.ts60 symbols
client/packages/python/tests/test_streams_state.py58 symbols
client/packages/admin/src/index.ts51 symbols
examples/ai-chat/src/components/ai-elements/prompt-input.tsx49 symbols
client/packages/components/src/components/ui.tsx48 symbols
client/www/components/dash/OAuthApps.tsx47 symbols
client/packages/core/src/instaql.ts47 symbols
client/packages/cli/src/ui/lib.ts42 symbols

Dependencies from manifests, versioned

@ai-sdk/anthropic3.0.9 · 1×
@ai-sdk/openailatest · 1×
@ai-sdk/provider3.0.8 · 1×
@ai-sdk/react3.0.19 · 1×
@anthropic-ai/sdk0.60.0 · 1×
@arethetypeswrong/cli0.17.4 · 1×
@babel/core7.17.9 · 1×
@babel/parser8.0.0-beta.0 · 1×
@babel/preset-env7.16.11 · 1×
@babel/runtime7.20.0 · 1×
@babel/standalone7.29.1 · 1×
@babel/types8.0.0-beta.0 · 1×

Datastores touched

instantDatabase · 1 repos

For agents

$ claude mcp add instant \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact