Files
PubScript/README.md
T
Schwitzz 1c9b531996 Implement CHUNK #2: server layer, core schemas/adapters, contract tests, seed
Complete the server-backed storage layer for PubScript so the app can run
against a real Fastify + SQLite backend instead of only local IndexedDB.

Server (@pubscript/server):
- db.ts: better-sqlite3 schema + migrations (users, shares, projects, books,
  chapters, entities, boards, ai_sessions, audit); WAL mode; idempotent
  admin bootstrap via PUBSCRIPT_ADMIN_EMAIL/PASSWORD.
- auth.ts: argon2 hashing, JWT-ish session tokens, guards, auth routes.
- routes.ts: REST CRUD for projects/books/chapters/entities/boards/ai_sessions
  with multi-tenant isolation and optimistic concurrency (baseRev).
- ws.ts: Fastify websocket hub for autosave + presence events.
- mapping.ts: row <-> core type conversion.

Core (@pubscript/core):
- Zod domain schemas (projects, books, chapters, entities, boards, ai_sessions)
  exported from index.
- storage-local.ts (IndexedDB/Dexie) and storage-server.ts (REST) adapters
  implementing the StorageAdapter contract.

Tests & tooling:
- storage.contract.test.ts: parameterized over both adapters; wired as
  `pnpm contract` and added to CI.
- seed.ts (`pnpm --filter server seed`): creates demo project "The Glass Harbor"
  — 3 chapters of prose, 4 linked characters, 1 world location, 6-node board.
- Dockerfile + compose wiring for the server runtime.

Acceptance: seed project opens with 3 chapters, 4 linked characters, 1 board.
2026-10-24 18:31:20 -05:00

43 lines
1.7 KiB
Markdown

# PubScript
A self-hostable, multi-user writing studio for novelists — one codebase that runs as a web app and as a native desktop app, with a local-first AI co-writing engine built in.
See **[PLAN.md](./PLAN.md)** for the full vision, architecture, and data model. The `CHUNK#n.md` files are the executable work orders.
## Quickstart
```bash
pnpm i && pnpm dev # run the app shell at http://localhost:5173
pnpm test # run every workspace's unit tests
pnpm typecheck # strict TypeScript across the monorepo
pnpm build # build web + server
```
## Docker (self-host)
```bash
docker compose -f docker/compose.yaml up --build
# → http://localhost:8080 (health: curl localhost:8080/api/health)
```
One container serves the web app, runs the Fastify API, and stores SQLite on a volume.
## Repository layout
| Path | What it is |
|---|---|
| `PLAN.md` | Single source of truth for *what* and *why* |
| `CHUNK#n.md` | Executable, step-by-step work orders |
| `apps/web/` | React 19 + Vite app (runs in browser AND in Tauri) |
| `packages/core/` | Domain types, ULIDs, time, token budget, `StorageAdapter` contract |
| `packages/ui/` | Design tokens, theme engine (Ink / Parchment / Nocturne / Terminal), component kit |
| `server/` | Fastify + SQLite: auth, multi-tenant, WS, admin, AI proxy |
| `docker/` | Dockerfile + compose (one container serves app + API + data) |
| `docs/` | ADRs, data model reference, AI role prompts, parity matrix |
## Status
**CHUNK #1 — Scaffold & Foundations** is complete: monorepo, strict TypeScript, the app shell, the theming system, the `packages/core` contracts, a Fastify server skeleton, and a green CI pipeline.
*Next: [CHUNK #2](./CHUNK%232.md) — Data Model, Storage & Auth.*