Developers · Overview

Developers

Civility is a set of libraries you add to a web app or a Tauri app. It stores the app's data on the device, syncs it through a Civility server, publishes share links, and calls AI and other services with the user's credentials.

These pages cover the client libraries. To run a server, see Hosting.

Packages

Package Import paths Use
jsr:@civility/cloud @civility/cloud Store, CloudStore, BlobStore, sharing, errors, manifest.
@civility/cloud/storage/idb, /opfs, /memory, /deno-fs Storage backends.
@civility/cloud/api Share, session and identity clients for pages without a store.
@civility/cloud/ui The civ-* custom elements. Styled by inro.css.
@civility/cloud/worker Service-worker blob proxy.
@civility/cloud/argon2-worker Key-derivation worker script, for setKdfWorkerUrl.
jsr:@civility/services @civility/services, @civility/services/ai, @civility/services/podcast Service calls: AI providers, Podcast Index, RSS.
jsr:@civility/cli @civility/cli (the civ command), @civility/cli/testing App ids, a local server, and a test server.
jsr:@civility/tauri @civility/tauri File storage and system-browser sign-in for Tauri apps.

@civility/cloud/internal is shared with the server and is not a public API.

Basic setup

Install the client:

deno add jsr:@civility/cloud

Create one store in one module and import it wherever you read or write data:

// store.ts
import { CloudStore } from '@civility/cloud'
import { IDBStorage } from '@civility/cloud/storage/idb'

export const APP_ID = 'app-k3m7q2x4p6w5z7n3b2v4c6h5' // from `civ id`
const APP_VERSION = '1.0.0'

type Settings = { theme: 'auto' | 'light' | 'dark' }
type Item = { title: string; done: boolean }

export const store = new CloudStore({
  id: APP_ID,
  storage: { db: new IDBStorage() },
  documents: ['settings'],
  collections: ['items'],
  versions: [{
    version: APP_VERSION,
    schema: {
      type: 'object',
      properties: {
        settings: { type: 'object' },
        items: { type: 'object' },
      },
    },
  }],
})

export const settings = store.document<Settings>('settings', { theme: 'auto' })
export const items = store.collection<Item>('items')

Without a cloud option the store is local only. Add cloud: { appId: APP_ID } to sync it. The entity API is the same in both cases.

Guides

Guide Covers
Store Local data: documents, collections, blobs, schema migrations.
Sync Sign-in, syncing data and blobs, events, sessions.
Registration App id, manifest, approved origins.
Services AI and other service calls with user or host credentials.
Testing In-memory tests and tests against a local server.

Recipes

Reference