# Ten minutes, end to end

There is a runnable version of all of this:

```bash
git clone https://github.com/rishabhshuklax/skm && cd argala
npm ci
npm run build && npm run argala:example
```

It starts a relay, links a second device without moving a private key —
including the bit where a person compares a pairing code — refuses to link a
device the relay invented for itself, shares a graph with another member,
rejects a forged author, rotates a stolen laptop out, and then prints what the
relay's database actually holds.

## The server

```ts
import Fastify from 'fastify';
import { openDb, registerRelay, SqliteDirectory } from '@argala/relay';

const db = openDb('data/relay.db');
const app = Fastify();

await registerRelay(app, {
  db,
  directory: new SqliteDirectory(db),
  authenticate: async (req) => {
    const session = await mySessions.verify(req);
    // The token must name the member AND the device it was issued to.
    return session ? { memberId: session.userId, deviceId: session.deviceId } : null;
  },
});

await app.listen({ port: 8787 });
```

## The device

```ts
import { ArgalaEngine, HttpTransport, bestStore, IdbKeyStore, defineKinds } from '@argala/client';
import { z } from 'zod';

const engine = await ArgalaEngine.open({
  memberId: me.id,
  deviceId: localStorage.getItem('argala-device') ?? ArgalaEngine.newDeviceId(),
  transport: new HttpTransport({ baseUrl: '/api/argala', credentials: 'same-origin' }),
  store: await bestStore({ name: me.id }),
  keyStore: new IdbKeyStore(),
  kinds: defineKinds({
    note: z.object({ body: z.string().max(10_000) }),
    task: z.object({ title: z.string(), done: z.boolean() }),
  }),
});

await engine.openGraph('u', { create: true }); // my own graph
engine.startAutoSync();

await engine.put('u', { kind: 'note', data: { body: 'hello' } });
const notes = await engine.listKind('u', 'note'); // typed, local, instant
```

That is a working end-to-end encrypted app. The remaining sections explain
each part in detail.

---
