Books
Books are the core entity in Nanahoshi. Each book record represents a single ebook file discovered during library scanning.Book schema
Books are stored in thebook table with the following key attributes:
(libraryId, filehash) to prevent duplicates within a library while allowing the same file across different libraries.
See the schema definition in packages/db/src/schema/general.ts:145-198.
Book metadata
Rich metadata is stored separately in thebook_metadata table with a 1:1 relationship:
packages/db/src/schema/general.ts:213-252.
Libraries
Libraries are collections of filesystem paths that Nanahoshi monitors for ebook files. Each library belongs to an organization and can contain multiple paths.Library schema
packages/db/src/schema/general.ts:60-85.
Library paths
Each library can monitor multiple filesystem paths through thelibrary_path table:
(libraryId, path) combination is unique to prevent duplicate path entries.
See packages/db/src/schema/general.ts:87-115.
Scanning workflow
- User triggers scan via
libraries.scanLibraryRPC endpoint - Library scanner discovers ebook files (
.epub,.pdf, etc.) - File events are queued to
file-eventsBullMQ queue file.event.workercreates book records and extracts basic metadata- Book indexing jobs are queued to
book-indexqueue book.index.workerindexes books into Elasticsearch
packages/api/src/routers/libraries/library.router.ts.
Collections
Collections are user-created groups of books, similar to playlists. Users can organize their books into custom collections.Collection schema
collection_book join table:
packages/db/src/schema/general.ts:287-316 and 440-474.
Collection operations
The collections router provides:list- List user’s collectionsgetDetails- Get collection with all bookslistBookMemberships- Check which collections contain a specific bookcreate- Create new collectionsetBookMembership- Add or remove book from collectionupdateVisibility- Toggle public/private statusdelete- Delete collection
packages/api/src/routers/collections/collections.router.ts.
Organizations
Organizations provide multi-tenancy. Each organization has its own libraries, members, and content isolation.Organization schema
member table:
packages/db/src/schema/auth.ts:79-124.
Organization context
The active organization is tracked in the user’s session:Metadata entities
Authors
Authors are shared entities that can be associated with multiple books:book_author join table with optional roles:
packages/db/src/schema/general.ts:268-343.
Series
Series group related books:book_series:
packages/db/src/schema/general.ts:254-267 and 345-368.
Publishers
book_metadata.publisherId.
See packages/db/src/schema/general.ts:200-211.
User interactions
Reading progress
Nanahoshi tracks reading progress for each user-book combination:packages/db/src/schema/general.ts:399-438.
Liked books
Users can like/favorite books:packages/db/src/schema/general.ts:370-397.
Activity feed
User activities are logged for social features:packages/db/src/schema/general.ts:482-508.
Scanned files
Thescanned_file table tracks discovered files before they become books:
packages/db/src/schema/general.ts:31-58.