Add booksorter design and implementation plan
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
commit
a2ea154cd8
2 files changed
+745
No files matched your search
@@ -0,0 +1,319 @@
|
||||
# Booksorter design
|
||||
|
||||
Date: 2026-11-18. Status: awaiting approval.
|
||||
|
||||
## Intent
|
||||
|
||||
Steve wants his home bookshelves arranged as topically as they can be. The
|
||||
tool gets him there with the least effort: scan a pile of books with the
|
||||
laptop's camera, print one 3x5 card per book, put each card in its book, and shelve the books
|
||||
in the order the cards say.
|
||||
|
||||
Each card carries one sort number. The tool chooses that number itself. Steve
|
||||
does not want to pick a classification system, choose between candidate
|
||||
numbers, or tune settings. Sane defaults everywhere.
|
||||
|
||||
## Goals
|
||||
|
||||
1. **Pile scanning is fast.** Hold one barcode after another up to the camera.
|
||||
Each scan is acknowledged within about a second, and slow lookups never
|
||||
block the next scan.
|
||||
2. **Every book gets one canonical shelf number, chosen automatically.**
|
||||
3. **Barcodes are not the only way in.** Typed ISBN, title and author search,
|
||||
LCCN, and fully manual entry all work.
|
||||
4. **Scans build a print queue; printing produces a PDF** laid out for Avery
|
||||
5388 (three 3x5 index cards per letter sheet), front side only.
|
||||
5. **A persistent catalog** of every book scanned, viewable in shelf order, so
|
||||
a new book's neighbours on the shelf are visible.
|
||||
|
||||
## Non-goals (first version)
|
||||
|
||||
- Double-sided cards. The front carries everything. A back side may come
|
||||
later as an off-by-default option.
|
||||
- Avery products other than 5388. Templates are data, so adding one later is
|
||||
a small job, but only 5388 ships now. The 10-per-sheet business card
|
||||
(2 x 3.5 inches) is the first one to add afterwards.
|
||||
- Scanning with a phone, or any setup involving two devices. Everything runs
|
||||
on one laptop. Running the whole app on a phone is a possible later step.
|
||||
- Accounts, login, multiple users, cloud hosting.
|
||||
- Printing the Dewey number. It is stored when found, never shown on the card.
|
||||
- Reading the copyright page or cover by OCR.
|
||||
- AI-estimated numbers for books no source knows.
|
||||
- Loan tracking, reading status, ratings, cover images.
|
||||
|
||||
## Anti-goals
|
||||
|
||||
These make the tool a failure even if it technically works:
|
||||
|
||||
- Asking Steve to choose a classification system or pick among candidate
|
||||
numbers during normal scanning.
|
||||
- A scan flow that waits on a network lookup before accepting the next book.
|
||||
- Cards that print out of register with the Avery perforations.
|
||||
- Depending on a paid service or one that needs an API key.
|
||||
|
||||
## Constraints
|
||||
|
||||
- One user, one laptop. The app is opened at `localhost`, where browsers
|
||||
grant camera access with no certificate.
|
||||
- Laptop webcams are often fixed-focus and low resolution, so barcode reading
|
||||
may be finicky. This is the riskiest assumption in the design and must be
|
||||
proven on the real laptop before anything else is built on it. Typed ISBN
|
||||
is always available beside the camera.
|
||||
- The Library of Congress catalog sends no CORS header, so it must be called
|
||||
from a server, not from the browser.
|
||||
- The Library of Congress reportedly blocks clients above roughly 10 requests
|
||||
a minute. A block arrives as an HTML page with status 200.
|
||||
- The printer is a Brother laser. Card stock goes through the manual feed
|
||||
slot, one side only.
|
||||
|
||||
## Approaches
|
||||
|
||||
### Which number is canonical
|
||||
|
||||
Measured on 42 real ISBNs across genres on 2026-11-18:
|
||||
|
||||
| | Dewey | Library of Congress |
|
||||
|---|---|---|
|
||||
| Exact match for the scanned edition | 67% | 83% |
|
||||
| Counting other editions of the same work | 95% | 98% |
|
||||
| What a source returns | topic number only | full call number: class, author cutter, year |
|
||||
|
||||
1. **Library of Congress call number (chosen).** Assigned by the national
|
||||
library to nearly every US-published book, published free, finer-grained
|
||||
than Dewey, and a complete shelf address, so no two books tie. Harder to
|
||||
read than a decimal number.
|
||||
2. **Dewey.** Easier to read. A third of books came back without one, OCLC
|
||||
closed its free lookup in January 2024, and the number stops at the topic,
|
||||
so the rest of the shelf order would have to be invented locally.
|
||||
3. **Dewey when available, LC otherwise.** Two systems cannot share a shelf.
|
||||
|
||||
Steve handed this choice over ("sane defaults"). Claude picked option 1.
|
||||
|
||||
### Where it runs
|
||||
|
||||
1. **A small local app on Steve's laptop (chosen).** One program serves the
|
||||
page at `localhost`, does the lookups, and keeps the catalog in one SQLite
|
||||
file. Something outside the browser is needed for Library of Congress
|
||||
lookups regardless.
|
||||
2. **A hosted static page with the catalog in the phone's browser storage.**
|
||||
Nothing to run, but iOS can evict that storage and printing card stock
|
||||
from a phone is awkward.
|
||||
3. **A hosted app with a cloud database.** Reachable anywhere, at the cost of
|
||||
an account, a login and a deployment for a one-person tool.
|
||||
|
||||
Claude picked option 1. Steve then ruled out any setup that needs a phone and
|
||||
a computer together: one laptop, its own camera.
|
||||
|
||||
## How it works
|
||||
|
||||
### The pieces
|
||||
|
||||
One program on Steve's Linux laptop does three things: serves the web page at
|
||||
`localhost`, looks books up, and stores the catalog in a single SQLite file.
|
||||
Starting it is one command, and it listens only on the laptop itself.
|
||||
|
||||
The page has three views:
|
||||
|
||||
- **Scan.** The camera view beside a running list of this session's scans,
|
||||
with the ISBN box and the other alternate-input forms.
|
||||
- **Print queue.** The books waiting for cards, and the button that makes
|
||||
the PDF.
|
||||
- **Catalog.** Every book in shelf order.
|
||||
|
||||
The page layout should hold up on a narrow screen, so that running the whole
|
||||
thing on a phone later is not ruled out. Nothing else is built for that now.
|
||||
|
||||
### Scanning
|
||||
|
||||
1. The laptop camera reads EAN-13 barcodes continuously. Only codes starting
|
||||
978 or 979 count as ISBNs; the 5-digit price add-on is ignored.
|
||||
2. On a read: a beep and a flash on screen, and the ISBN is recorded at
|
||||
once. The scanner is ready for the next book immediately.
|
||||
3. The same ISBN read again within a few seconds is ignored. An ISBN already
|
||||
in the catalog is not added twice: the page says "already in catalog" and
|
||||
offers to queue a reprint.
|
||||
4. Each book is resolved in the background. The session list shows each scan
|
||||
move from "looking up" to its title and call number, or to "needs
|
||||
attention".
|
||||
|
||||
The ISBN box stays focused while the camera runs, so a typed ISBN, or a USB
|
||||
barcode scanner (which types like a keyboard), works with no mode switch.
|
||||
|
||||
### Alternate input
|
||||
|
||||
For a book whose barcode is missing, covered, or unreadable:
|
||||
|
||||
- **Type the ISBN** (10 or 13 digits, hyphens allowed, check digit verified).
|
||||
- **Search by title and author.** Results list title, author, year and
|
||||
publisher; picking one adds it. This is the one place the user chooses
|
||||
among candidates, because only they can see the book.
|
||||
- **Type the LCCN** printed on the copyright page of older books.
|
||||
- **Enter it by hand.** Title, author, and a call number copied from the
|
||||
copyright page or typed from knowledge.
|
||||
|
||||
### Choosing the number
|
||||
|
||||
For each book the server tries these in order and stops at the first that
|
||||
yields a Library of Congress class:
|
||||
|
||||
| Step | Source | What it gives | Confidence |
|
||||
|---|---|---|---|
|
||||
| 1 | Library of Congress catalog, by ISBN | Full call number for this edition | exact |
|
||||
| 2 | Open Library edition record, by ISBN | Call number for this edition, messier | exact |
|
||||
| 3 | Library of Congress catalog, by title and author | Call number for another edition | approximate |
|
||||
| 4 | Open Library work-level search | Class numbers pooled from all editions | approximate |
|
||||
| 5 | Nothing found | Goes to "needs attention" | none |
|
||||
|
||||
Open Library is also asked first for title, author, publisher, year and
|
||||
subjects, because it answers quickly and lets the page confirm the title
|
||||
within a second or so. If Open Library returns an LCCN, the Library of
|
||||
Congress record is fetched by LCCN instead of by ISBN.
|
||||
|
||||
Rules that keep this automatic:
|
||||
|
||||
- **Several candidates.** Normalize them all, then take the most frequent.
|
||||
Break ties with the most specific (longest class part), then
|
||||
alphabetically. Never ask.
|
||||
- **Class without a cutter.** When a source gives only the class
|
||||
(`QA76.76.A65`), build the rest: an author cutter from the Library of
|
||||
Congress cutter table applied to the author's surname (or the title when
|
||||
there is no author), then the publication year.
|
||||
- **Approximate numbers** come from a different edition, so their year is
|
||||
replaced with this edition's year.
|
||||
- **Legacy fiction classes.** When a record has both an old `PZ3` or `PZ4`
|
||||
number and a literature number (`PR`, `PS` and so on), prefer the
|
||||
literature number.
|
||||
- **Fiction gets no special treatment.** It is shelved by its call number
|
||||
like everything else, which groups it by country and era, then author.
|
||||
- **Dewey** from any source is stored on the book record and otherwise unused.
|
||||
|
||||
Everything fetched from a source is cached in the database, so a book can be
|
||||
re-resolved later without asking the source again. Library of Congress
|
||||
requests go through a throttle (start at one every 6 seconds) and the server
|
||||
detects the HTML block page and backs off.
|
||||
|
||||
### The call number as data
|
||||
|
||||
A call number is parsed into parts: class letters (one to three), class
|
||||
number (integer with optional decimal), up to two cutters (a letter and
|
||||
digits read as a decimal fraction), and a trailing year or volume.
|
||||
|
||||
- **Display form** is normalized: `QA76.73.R87 K53 2018`. The inputs are
|
||||
messy (`TX719 .C454 2001`, `QA76.73.C15K47 1988`, Open Library's
|
||||
zero-padded `QA-0076.76000000.A65`), and all must parse to the same parts.
|
||||
- **Sort key** is derived from the parts so that plain string comparison in
|
||||
the database gives correct shelf order: letters alphabetically, class
|
||||
number numerically, each cutter by letter then by its digits as a decimal
|
||||
(`.R87` before `.R9`), then year.
|
||||
|
||||
A call number that will not parse is kept as typed, sorted after everything
|
||||
else, and flagged for attention.
|
||||
|
||||
### The card
|
||||
|
||||
Avery 5388: letter sheet, three cards, each 5 inches wide by 3 inches tall on
|
||||
the sheet. Believed geometry is 1 inch top and bottom margins, 1.75 inch side
|
||||
margins, no gaps. This must be checked against Avery's published template
|
||||
before the layout code is written.
|
||||
|
||||
The card is read as a bookmark: upright, 3 inches wide and 5 tall, so its
|
||||
content is rotated a quarter turn on the sheet. The call number sits in the
|
||||
top inch, the part that sticks out of the book.
|
||||
|
||||
```
|
||||
┌──────────────────────────┐
|
||||
│ QA76.73.R87 │ class: where on the shelves
|
||||
│ K53 2018 │ cutter and year: which book
|
||||
│ ──────────────────────── │
|
||||
│ Science │
|
||||
│ Mathematics │
|
||||
│ │
|
||||
│ The Rust Programming │
|
||||
│ Language │
|
||||
│ Steve Klabnik, │
|
||||
│ Carol Nichols │
|
||||
│ No Starch Press, 2018 │
|
||||
│ │
|
||||
│ Rust (Computer program │
|
||||
│ language) │
|
||||
│ │
|
||||
│ ISBN 9781593278281 ~ │
|
||||
└──────────────────────────┘
|
||||
```
|
||||
|
||||
- Line 1 is the class part, the largest type on the card. Line 2 is the
|
||||
cutter and year, slightly smaller. Both must be readable in the top inch.
|
||||
- Below the rule: the plain-language names of the main class and subclass,
|
||||
from the Library of Congress outline (a small fixed table, about 220
|
||||
entries, shipped with the app). A class missing from the table leaves
|
||||
these lines blank.
|
||||
- Then title, authors, publisher and year, up to two subject headings, ISBN.
|
||||
- A small `~` in the corner marks an approximate number.
|
||||
- Long titles shrink a step, then truncate with an ellipsis. Nothing ever
|
||||
overflows the card or pushes the call number down.
|
||||
|
||||
### Printing
|
||||
|
||||
- The print queue holds every book scanned and not yet printed. A book in
|
||||
"needs attention" is not in the queue until it has a number; a card is
|
||||
never printed with a placeholder.
|
||||
- The PDF opens in a browser tab, and the print screen says to print at
|
||||
actual size.
|
||||
- "Print" produces a PDF with cards in shelf order, so the stack of cards
|
||||
comes out already sorted.
|
||||
- For a partly used sheet, the user picks which position (1, 2 or 3) the
|
||||
first card starts at.
|
||||
- The PDF is drawn at exact coordinates by the server, not by the browser's
|
||||
print dialog, which scales and adds margins unpredictably. It must be
|
||||
printed at 100% scale.
|
||||
- A calibration page prints the three card outlines on plain paper to hold
|
||||
against an Avery sheet. Horizontal and vertical offset settings, in
|
||||
fractions of a millimetre, correct a printer that shifts the image.
|
||||
- After printing, the user confirms the cards came out, and those books
|
||||
leave the queue. Any book can be queued again from the catalog.
|
||||
|
||||
### Catalog
|
||||
|
||||
A list of every book in shelf order with search by title, author, ISBN or
|
||||
call number. Each book can be edited (including overriding its call number,
|
||||
which marks it manual and stops automatic re-resolution), deleted, or queued
|
||||
for a reprint. A "needs attention" filter shows books without a usable
|
||||
number.
|
||||
|
||||
## Error handling
|
||||
|
||||
- **Lookup fails or a source is down.** The scan is kept and retried with
|
||||
backoff. It never disappears. After retries run out it goes to "needs
|
||||
attention" with the reason.
|
||||
- **No source knows the book.** "Needs attention", with the title and author
|
||||
search and manual entry one tap away.
|
||||
- **The laptop is offline.** Scans are still recorded and resolve when the
|
||||
connection returns.
|
||||
- **The camera will not read a barcode.** Type the ISBN in the box beside it.
|
||||
- **Library of Congress block page.** Detected, treated as a temporary
|
||||
failure, throttle widened.
|
||||
|
||||
## Testing
|
||||
|
||||
- Call-number parsing, normalization and sort order, against a table of real
|
||||
values including every messy form listed above.
|
||||
- Cutter generation against the published examples in the Library of
|
||||
Congress cutter table.
|
||||
- The number-choosing rules, using recorded source responses as fixtures. No
|
||||
test calls a live service.
|
||||
- PDF geometry: card boxes land on the exact coordinates for each start
|
||||
position, and text stays inside its box for very long titles.
|
||||
- ISBN validation and ISBN-10 to ISBN-13 conversion.
|
||||
- One manual end-to-end check with the laptop camera and the real printer.
|
||||
|
||||
## Left to the builder
|
||||
|
||||
- Language, framework and libraries. Claude's call is TypeScript throughout
|
||||
(server and web app) with SQLite, unless the machine's installed tooling
|
||||
argues for something else.
|
||||
- The barcode-reading library, provided it works in the laptop's browser and
|
||||
does not rule out phone browsers later.
|
||||
- How the page learns that a background lookup finished (server-sent events,
|
||||
polling, or websockets).
|
||||
- Database schema, API shape, fonts and exact type sizes on the card.
|
||||
- Retry counts and backoff timings.
|
||||
Reference in new issue
Block a user