Skip to content
Source
Sign inSign up
fuko/trytanstackdb.com
Open History to see the last commit

README.md

94 lines3.7 KB

1# trytanstackdb.com _(BETA version)_
2​
3> Note that this project is still in its early stages.
4​
5An interactive guide for taking the first steps with
6[`@tanstack/db`](https://tanstack.com/db/latest/docs/overview) by
7[fuko](https://fulop.dev/).
8​
9[🔗 trytanstackdb.com](https://trytanstackdb.com)
10​
11## 🚀 Main goals, motivations
12​
13It took a while for TanStack DB to "click" for me, but it's not because this
14library is too nieche. When I used it for a POC and showed that to my
15colleagues, they seemed to immediately understand the advantages of TanStack DB,
16because I could show exactly the things I explained.
17​
18This project aims to bring the same interactive and practical learning
19experience to everybody elseon the internet.
20​
21### Target audience
22​
23There are two types of people in the target audience of this project:
24​
251. Devs, who just heard about TanStack DB, and want to understand what it is,
26 and see if it could be useful for their use cases.
272. _(Future goal):_ People who want to build things with TanStack DB, and want
28 to see a reference implementation of the features it has.
29​
30## Architecture
31​
32The architecture was designed around the two things that I wanted to highlight
33in the interactive tutorial:
34​
351. TanStack DB can make applications feel incredibly fast, even when the network
36 latency is large
372. contrary to conventional local-first approaches, this library doesn't require
38 big technical changes on the back end (works with any database, no need for
39 adding new libs to your backend, simple api endpoints work just fine)
40​
41The guide runs next to a small Notes app built with TanStack DB. Its data lives
42in three query collections (folders, notes, account) that load from and save to
43a plain REST API.
44​
45Databases are expensive, so instead of running one on a server, the "backend"
46is an in-memory database behind a small REST API that runs in the browser
47(`src/api/fake-server.ts`). It is seeded from `src/fixtures` and starts over
48when the page is reloaded.
49​
50I wanted to make the syncing mechanisms observable. The app only talks to the
51API through `fakeFetch` (`src/api/fake-fetch.ts`), a `fetch`-like function that
52waits for the configured latency, can fail the next request on purpose, and
53records every request in a log. The network controls and the request inspector
54in the UI are built on top of it.
55​
56```mermaid
57sequenceDiagram
58 participant App as Notes app (TanStack DB collections)
59 participant FakeFetch as fakeFetch (latency, failures, request log)
60 participant Server as Fake server (in-memory REST API)
61​
62 App->>FakeFetch: API call
63 FakeFetch->>FakeFetch: Wait for the configured latency
64 FakeFetch->>Server: Forward request
65 Server->>FakeFetch: Return data
66 FakeFetch->>App: Respond to original request
67```
68​
69## Development
70​
71The project is a [TanStack Start](https://tanstack.com/start) app that uses
72[Vite+](https://viteplus.dev/) (the `vp` CLI) for tooling. See
73[AGENTS.md](./AGENTS.md) for more about Vite+.
74​
75```sh
76vp install # install dependencies
77vp run dev # start the dev server on http://localhost:3000
78vp check # format, lint and type check
79vp test # run the unit tests
80vp run build # build for production
81```
82​
83### Deployment
84​
85The app runs on Cloudflare Workers and deploys with the `cf` CLI. The worker
86(`trytanstackdb-v2`) and its custom domain (`v2.trytanstackdb.com`) are set in
87`cloudflare.config.ts`. `vp run deploy` runs `cf deploy`, which builds the app
88with the Cloudflare Vite plugin and uploads it. The domain lives on the
89Cloudflare account that owns the `trytanstackdb.com` zone, so `cf` must be
90logged in to that account.
91​
92CI runs on TanStack Source (`.source/workflows/ci.ts`). It checks every pull
93request into `v2`, and deploys each push to `v2` with the
94`CLOUDFLARE_API_TOKEN` CI secret.