clove/pkviewer
README.md
# pkviewer
Websites for [PluralKit](https://pluralkit.me) systems.
PluralKit holds the identity and the data. pkviewer handles how that identity is
presented on the web: every system gets a public page, every member can have one,
and systems that sign in can choose a readable address and customise how their
pages look.
**pkviewer is a third-party project. It is not PluralKit, and is not affiliated
with or endorsed by the PluralKit project.** It reads PluralKit's public API and
shows only information PluralKit already makes public.
Live at **[pkviewer.xyz](https://pkviewer.xyz)**. The feature set is
deliberately small.
---
## What is in here
```
api/ Hono on Deno. Owns SQLite, sessions, the PluralKit client,
Discord OAuth, and all business logic. The only process that
opens the database.
api/shared/ Types, the theme vocabulary, and validation used by both tiers.
web/ SvelteKit on Deno. Renders pages and the management UI. Has no
database driver and no PluralKit client — it reaches the API
over HTTP.
deploy/ runit services for the API and the web tier.
deno.json Every dependency and every task, for the whole repository.
```
The split is deliberate: SQLite permits one writer at a time, and confining all
database access to one long-lived process removes write contention as a category
of bug rather than managing it.
## One origin
Everything a person visits lives on a single user-facing origin:
| Path | |
|---|---|
| `/` | landing page |
| `/login` | Discord sign-in |
| `/auth/...` | OAuth callbacks, proxied to the API by the web tier |
| `/manage/...` | authenticated management UI |
| `/admin/...` | platform administration |
| `/s/...` | public system and member pages |
The API stays internal. The browser never talks to it directly: page loads and
SvelteKit remote commands run on the web tier's server and forward the session
cookie, which is what keeps `INTERNAL_API_ORIGIN` internal.
The session cookie keeps the `__Host-` prefix. It forbids a `Domain` attribute,
so the cookie is pinned to exactly this host and no sibling subdomain can set or
overwrite it.
In development the origin is `http://system.localhost:3000`, which Chrome and
Firefox resolve to 127.0.0.1 with no setup. **Safari does not resolve
`*.localhost`**; add an `/etc/hosts` entry if you use it.
## Prerequisites
- [Deno](https://deno.com) 2.5 or newer. It runs both tiers, the tests and the
tooling. There is no Node, npm or Bun step.
- No database server. SQLite is a file, opened through Deno's built-in
`node:sqlite`.
## Getting started
```bash
deno install
cp .env.example .env # then read the comments in it
deno task dev
```
That starts both tiers together:
```
site http://system.localhost:3000 /, /login, /manage, /s/...
api http://127.0.0.1:3001/health
```
Migrations run automatically on API start, so a fresh checkout needs no bootstrap
step.
> **Every task reads `.env` from the repository root**, through `--env-file`.
> Run tasks from the root (`deno task ...`) rather than from inside `api/` or
> `web/`.
The database defaults to `api/data/pkviewer.db`, because `DATABASE_PATH` is
relative and the API runs from `api/`.
Signing in needs Discord OAuth credentials; see `.env.example`, which documents
every variable. Everything else — public pages, the whole rendering path — works
without them, and the API says so at startup rather than refusing to run.
## Commands
| Command | What it does |
|---|---|
| `deno task dev` | Both tiers, with the API on `--watch` and Vite's dev server |
| `deno task test` | Full test suite, API and web |
| `deno task build` | Production build of the web tier into `web/build` |
| `deno task start-api` | Run the API for production |
| `deno task start-web` | Serve `web/build` for production |
| `deno task migrate` | Apply migrations without starting the server |
| `deno task check` | Origin guard, both type checks and tests — run before pushing |
| `deno task check:domain` | Fails if a deployment hostname is hardcoded |
| `deno task admin:list` | List platform administrators |
| `deno task admin:grant <discord-id>` | Make an account an administrator |
| `deno task admin:revoke <discord-id>` | Remove an administrator |
## Local test data
Claiming a system needs Discord OAuth. To poke at the management UI without it,
seed a local account and session:
```bash
deno task seed <system-id> # any publicly visible PluralKit system
```
It prints a session token and the cookie line to paste into the browser console.
The seed **reads the system's identifiers from PluralKit** rather than inventing
them, so a seeded row satisfies the same invariant a real claim does. It uses a
fabricated Discord id, so it never ties local data to a real account.
It is a development script and refuses to run when `NODE_ENV=production`.
## Testing
```bash
deno task test # everything
deno test -A api/test/slugs.test.ts # one file
```
Tests use in-memory SQLite and a stubbed PluralKit, so they need no network and
no local database. The web tests read the source directly to guard things no
request-level test sees: the shape of the content security policy, badges staying
out of a theme's reach, and the management stylesheet's cascade.
## Deploying
Production runs as two [runit](http://smarden.org/runit/) services, `deploy/api`
and `deploy/web`, each with its own `svlogd` logger under
`/var/log/pkviewer/`. Shared settings — the checkout path, ports, and the user
to run as — live in `deploy/env.sh`. Secrets stay in `.env`.
```bash
deno install
deno task build
# link deploy/api and deploy/web into your runit service directory
```
The API listens on loopback only. Only the web tier should be reachable, so put
a TLS proxy or a tunnel in front of it. The web tier treats requests as `https`
and trusts the `Host` header, which a tunnel such as Cloudflare Tunnel preserves.
## Documentation
**User-facing documentation is a separate site and is not served by this
application:** [docs.doughmination.gay](https://docs.doughmination.gay/projects/pkviewer).
It also carries the support links — Discord, Matrix, and the repository.
The reasoning for anything structural lives in the code, next to what it
constrains: the migrations explain the schema, `web/src/hooks.server.ts` explains
the security headers, and the tests state the invariant each one guards. Start
with the file you are changing.
## Third-party notices
pkviewer reads the public [PluralKit API](https://pluralkit.me/api/) and sends a
consistent `User-Agent` identifying itself, as PluralKit asks. It never asks for
a PluralKit token in order to claim a system.
Built with [Deno](https://deno.com), [Hono](https://hono.dev),
[SvelteKit](https://svelte.dev/docs/kit), [Svelte](https://svelte.dev),
[Zod](https://zod.dev) and [Bootstrap Icons](https://icons.getbootstrap.com).
Fonts are served from [Google Fonts](https://fonts.google.com).
## Licence
[MIT](LICENSE). © 2026 Clove Twilight.
The licence covers this source code. It does not grant any rights in the
pkviewer name, and it changes nothing about the relationship with PluralKit:
pkviewer is an independent third-party project, not affiliated with or endorsed
by PluralKit, and anything you build from this source is too.