P-LensOpen the app

Philosophy

Your book, on your device

P-Lens is built around one decision: a player's book is files on the player's own device, in a format other software reads. This page sets out what follows from it: local-first and offline, no login, sync the relay cannot read, open source, and the things the app leaves out on purpose.

Origin

Where it started

P-Lens began as an experiment: whether hledger, the plain-text double-entry accounting tool written in Haskell, would run compiled to WebAssembly, as an app in the browser with no server behind it. It did. hledger is at its best with books that hold more than one currency, and the author went looking for an everyday world where people hold units other than yen, with exchange rates. Pachinko and pachislot, where every parlor's balls are a unit of their own, were that world.

The tool came first, and the purpose after it.

Files

The files are the record

A free app can disappear one day, for any number of ordinary reasons. P-Lens is built on the assumption that it will, and that the book must not disappear with it. The README opens with it (README.md):

The book of record is the journal files on your device. If P-Lens disappears, hledger -f main.journal still reads them as they are.

Inside the browser the files are kept in IndexedDB, used as a container and nothing more. The first of the design document's invariants:

The journal text is the only source of truth. IndexedDB holds journal files; it is a container, never a second record. Nothing hledger can answer — a balance, a total, a count — is stored.

With one record, there is no difference between the data in the app and the data exported from it. The files also say what they are, for whoever is handed them alone, a person or a program. A book's main.journal opens with a comment; the test fixture's (main.journal):

; A P-Lens book: pachinko and pachislot play, kept as a plain-text hledger journal.
; Made with P-Lens, open source at https://github.com/p-lens-dev/p-lens
; Read and checked by hledger, with thanks: https://github.com/simonmichael/hledger
;
; What is where:
;   accounts.journal      commodities and accounts; a parlor is the savings accounts tagged parlor-id
;   prices.journal        P directives: what a parlor's tokens exchange for, by day
;   transactions/2026.journal  one entry per play, tagged play-id, game-kind and machine: a file a year, by the entry's date
;   pachinko-play/        a pachinko play's readings as JSON Lines, in a file named by its play-id
;   pachislot-play/       a pachislot play's, the same
; Each parlor-id, with the parlor's name, is the one the open parlor list gives: https://github.com/p-lens-dev/p-lens-parlors
; (app.p-lens.jp reads that list as it is published at https://parlors.p-lens.jp). Machines are named as P-Lens's catalog names them.
; The layout, the accounts and every tag are described in ARCHITECTURE.md in the P-Lens repository.
;
; Point hledger at this file: hledger -f main.journal bal
  • Backup is the book's files as they are kept, in a zip, beside a small manifest (ARCHITECTURE.md): "No journal includes it, so the zip unpacked is a book desktop hledger opens." It is not encrypted, and the screen says so: an archive sealed with a key is lost with the key.
  • Export writes the whole book as one journal, which "hledger opens it by itself and reads it to the same figures" (ARCHITECTURE.md), as a test checks; or the plays as a CSV a spreadsheet opens.

What this does not cover is the device itself. A book cleared with the browser's data, or lost with the phone, comes back only from a backup or from another device it is synced with. The app asks the browser to keep its storage, and whether that is granted is the browser's decision.

Local-first

Local-first, and offline

The design document describes the app as keeping a player's record "as one local-first hledger book" (ARCHITECTURE.md). The accounting, the theoretical values and every report are worked out on the device. Another of the invariants:

Everything works offline. The engine and the app shell are precached; no backend is needed to start, read or write.

Playing alone does not depend on anything that crosses devices (ARCHITECTURE.md): starting, following and recording a play, and reading and setting right a book, "go to the device's own storage and hledger and nowhere else", and a relay that is down changes nothing of them. A test keeps that code apart.

Privacy

No login, no ads

There is no account to make. The operator never receives a name, an email address or a phone number, and the book stays on the device unless the player syncs, shares, sends, backs up or exports it (privacy policy, sections 1 and 2). There is no advertising in the app and no advertising tool behind it.

What does reach the operator's servers, as the privacy policy lists it:

  • Page views, through Cloudflare Web Analytics, which uses no cookies and does not track individuals; the operator sees totals. The book's contents are not sent.
  • The shared catalog of machines and their calculation conditions, which every user shares and adds to: a random identifier the device makes for itself, what a user registers or marks, and which calculation condition was chosen when a play started, published as counts. The book's contents (results, parlors, cabinet numbers) are not sent for it.
  • Sync and sharing, once the player starts them: encrypted, as the next section describes.

The project's own article on its relay gives the reason. A database of who lost how much, where and when, carries a responsibility just by existing: leaked, it is an incident, and even if it never leaks, someone may one day ask for it. What is not held cannot leak and cannot be handed over. So the books are not held.

Sync

Sync the relay cannot read

A book can be kept in step between a player's own devices and shared with other players. Whatever crosses devices is encrypted on the device before it leaves, and travels through a relay over the Nostr protocol. From the design document (ARCHITECTURE.md):

The operator reads no book and no play (PROTOCOL.md §1.2): whatever is carried is sealed on the device, by keys derived from secrets no relay holds; what a relay can read of it is listed there, openly.

The README says the same of the relay: "The relay carries sealed events only; it can read neither a book nor a play." (README.md) What the relay can see is listed in the protocol: that P-Lens is in use, which feature an event belongs to, when it was made and roughly how large it is, which events belong together, the public keys and roles of a shared book's members, and the address a device connects from. Not the amounts, not the parlors, not the plays.

Sealed on the device, keys never on the server, opened only by the other devices: that is what end-to-end encryption usually describes, and we believe the description fits. Nobody outside the project has reviewed the design, so take that as our belief rather than a claim. Encrypted data no device has read or written for a while is deleted from the relay. The article Encrypted ledger sync over Nostr goes through the protocol and the code.

Self-hosting

A relay of your own

The relay lives in a repository of its own, p-lens-relay, with the protocol (PLN-1) and the conformance tests any relay can be checked with. Per the app's README (README.md), it runs by the same code on Cloudflare, as the official one does, or on a server of one's own with Bun, and any Nostr relay that passes the conformance tests works too, strfry among them.

For now, a build of the app names its relay (VITE_RELAY_URL), and the app has no setting for it, so using a relay of one's own also takes one's own build of the app. Letting users choose a relay in the app is planned, which is why the relay has a repository of its own; a few code changes remain before that.

Open source

Open source

The app is free software under GPL-3.0-or-later, its source on GitHub. Its accounting is hledger's, and hledger is GPL-3.0-or-later too; the app ships hledger compiled to WebAssembly, and is published under the same licence. Anyone who receives it may have the source and pass it on.

The relay is in its own repository under MIT, as is the layout package packages/solid-gathering-shell. The names P-Lens and Pレンズ, the logo and the text of the terms and privacy policy belong to the operator of app.p-lens.jp and are not covered by the GPL; a fork leaves them out and uses its own (README.md).

Trade-offs

Left out on purpose

Most players have no reason to learn debits and credits, and P-Lens is made for them. The shortest way to record a play is two numbers, the money put in and the money that came back; the app composes the entry. To make that possible, the book leaves out things an accounting program would normally have:

  • No accounts of one's own. The account tree is fixed. There is no screen to add an account, and the app picks the account for every line.
  • No liabilities. The tree has assets, revenue, expenses and equity.
  • No expenses outside play. Travel and meals have no account. The book counts what happens with balls and tokens inside the parlor.
  • No entry that raises cash, and nothing after the prize counter.The accounting model explains where the book ends.
  • No closing of periods, no budgets, no tax. A month or a year is only a query. The app shows what was spent and what came back, not what may be spent, and the terms of use do not promise the book for any tax filing.

The code says it of the account tree in one line (accounts.ts):

/**
 * The account tree every P-Lens book is kept in. Small on purpose; it grows
 * when a book needs a branch it does not have, not before.
 */

What was removed is the places where a player would have to touch bookkeeping, not the bookkeeping. Every entry balances, and hledger checks it before it is kept. Exported, the book opens in desktop hledger with its income statement and balance sheet, and a player who wants a travel account can add one to the files.

Limits

What the app does not do

  • It does not send the book on its own. A backup is made when its button is pressed and at no other time (ARCHITECTURE.md); sync starts only when the player starts it. While a book has no current backup, the app says so in a corner of the screen, and sends nothing because of it.
  • It does not keep figures beside the journal. Every total on screen is asked of hledger from the text each time.
  • It does not record what happens after the counter. The book ends with the prizes the parlor hands over.
  • It does not say how much to spend. There is no budget, and no target.
  • It is not in the app stores. It is opened at app.p-lens.jp and installed from there to the home screen.

Cost

What it costs

Everything in P-Lens is free. Sync alone may become paid at some point. Of everything that passes through the operator's servers, sync is the one part that serves only the people using it, and it takes room on the server for each book it carries. A book also works fully without it, so charging for sync would never hold anyone's record back.

A relay can be run by oneself, with one's own build of the app; then sync stays free, on one's own server.