Foundation: importer pipeline + storage #1
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "foundation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
First of four plans implementing the books server design at
docs/superpowers/specs/2026-04-10-books-server-design.md. Delivers the foundation: abooksGo binary that watches an inbox directory, parses dropped epubs, persists metadata in SQLite, and files them into a managed library tree under<author>/<title>.epub. No HTTP, no auth, no Kobo — those come in plans 2–4.What's in here
internal/config/— env-based config loader (BOOKS_DATA_DIRplus three path overrides)internal/store/— SQLite store with embedded migrations. Full 11-table schema applied up front (most tables empty until later plans). Typed CRUD for books and authors.MaxOpenConns(1)so theforeign_keyspragma actually applies to every query.internal/library/— sanitised path components (handles/,\,:, control chars, whitespace, unicode),Place/WriteCover/Removewithos.Rename+ EXDEV-style copy fallback. Atomic via.tmprename.internal/epub/— pure functional OPF parser. Bytes in viaio.ReaderAt,Metadatastruct + cover bytes out. Supports both EPUB2 (<meta name=\"cover\">) and EPUB3 (properties=\"cover-image\") cover declarations.internal/importer/— orchestrates parse → upsert → place → set file path. Duplicate detection byfile_hashruns before upsert so re-dropped files are deleted, not re-placed. Failed imports quarantined toinbox/.failed/<name>with sidecar.err.internal/inbox/— startup scanner (filepath.WalkDir, skips.failed/and hidden) + fsnotify watcher with size-stability debouncing.main.go— wires everything, signal handling, slog logging.Out of scope (plans 2–4)
Test plan
go test ./...andgo test -race ./...clean across all packages.failed/with sidecar.err, server stays uplibrary/Anne Author/The Smoke Test.epubKnown follow-ups (deferred to plan 2)
ListBooksflagged withTODO(plan-2)internal/inbox/watcher.go(fsnotify timing is fiddly)PRAGMA foreign_keys=1is on but the junction tables lackREFERENCESclausesauthorswhen a book's author list is replacedPlan:
docs/superpowers/plans/2026-04-10-foundation.md.