Introduction
What the database is, how its data is organized, and which packages an application uses.
Mimic DB is an open-source realtime document database. Applications keep collaborative, structured state in it: a board, a design file, a form that several people edit at once. Every client that has a document open sees the others' edits as they happen, and the server checks every edit against the document's schema before it accepts it.
This page explains the model and the pieces. To build something right away, go to the quickstart.
The model
Data is organized in three levels:
- A database is the unit of access control and of limits. Users' grants, database keys and limits are set per database. A database is known by an id of 32 hexadecimal characters; it has no name in the server.
- A collection belongs to a database and holds documents of one schema. The schema is versioned: a migration takes every document of the collection from one version to the next.
- A document is one value that follows the collection's schema. It is the unit of collaboration: clients open a document, edit it together, and converge on the same value. Documents are independent of one another.
A document changes through transactions: atomic batches of small commands such as "set this field", "insert this list item" or "move this tree node". The server is authoritative. It evaluates each transaction against its latest copy of the document, checks the result against the schema, makes it durable, and then sends the committed change to every client that has the document open. Each committed change advances the document's revision.
The server keeps documents, their history and their checkpoints in PostgreSQL. A document is loaded into memory when it is used and leaves memory again once it is idle, so a deployment can hold far more documents than fit in memory.
The pieces
| Piece | What it is |
|---|---|
mimicd | The server. It serves an HTTP API for documents (/v1/databases), an administration API (/v1/admin), and the WebSocket endpoint clients edit documents over (/v1/sessions). |
@voidhash/mimic-core | The document model shared by every client and the server: schemas, values, commands and validation. You define your document schemas with it. |
@voidhash/mimic | The browser client: it opens a document over a WebSocket, applies edits optimistically, and keeps them in sync. It has zustand bindings and an undo history. |
@voidhash/mimic-server | What your backend uses: the engine SDK, which reads and writes documents and mints document tokens over the HTTP API, and the framework you write migrations with. |
A typical application has three parts. The backend uses
@voidhash/mimic-server with a database key that stays on the server. When a
signed-in user opens a document, the backend mints a short-lived document
token for that one document. The browser passes the token to
@voidhash/mimic and edits the document directly against mimicd.
Where to go next
You need a running server to build against. There are two ways to get one:
Cloud
Use the hosted service: create a database in the dashboard and connect to it.
Self-hosting
Run mimicd yourself, over PostgreSQL, as one process or several.
Then continue here: