Skip to content

refactor(core): extract LibraryBook DTOs + injectable cover/file URL layer#133

Merged
phildenhoff merged 1 commit into
mainfrom
extract-librarybook-serialization-cover-url-layer
Jun 30, 2026
Merged

refactor(core): extract LibraryBook DTOs + injectable cover/file URL layer#133
phildenhoff merged 1 commit into
mainfrom
extract-librarybook-serialization-cover-url-layer

Conversation

@phildenhoff

@phildenhoff phildenhoff commented Jun 29, 2026

Copy link
Copy Markdown
Member

Why

A future client/server build of Citadel needs to serialize a LibraryBook to JSON with HTTP cover/file URLs. Today the frontend-facing DTOs and all cover/file URL-building live in the Tauri crate, hardcoded to Tauri's asset:// protocol — libcalibre hands over the data model but not the serialized, URL-bearing shape the frontend consumes. This pulls that platform-agnostic layer out of the Tauri shell.

What changed

New crate crates/citadel-core owns the frontend-facing DTOs and the libcalibre → DTO conversion, with the URL scheme injected rather than hardcoded:

  • DTOs (book.rs / author.rs): LibraryBook, LibraryAuthor, LocalOrRemoteUrl, BookFile/LocalFile/RemoteFile, Identifier, plus from_library_book / from_author.
  • BookUrlBuilder trait (url.rs) with two impls:
    • AssetUrlBuilder — reproduces the desktop app's asset://localhost/… output byte-for-byte, including the ?v=<mtime_ms> cache-bust and the has_cover trust.
    • HttpUrlBuilder — the new Remote { url } path (https://…/api/books/<id>/cover, …/files/<name>.<ext>) for a future HTTP caller.
    • path_to_asset_url is shared here; cover_thumbs now imports it from the core crate (single source of truth), and src-tauri/libs/util.rs is removed.

citadel-core depends only on libcalibre / serde / specta / urlencodingno tauri. The Tauri shell re-exports LibraryBook/LibraryAuthor from it and injects &AssetUrlBuilder, so call sites and bindings.ts are unchanged.

Out of scope (follow-ups)

The server crate itself, HTTP routes, and the remote frontend client. Cover-thumbnail generation stays in Tauri for now (it just shares path_to_asset_url).

@github-actions

Copy link
Copy Markdown

libcalibre Test Coverage Report

Overall coverage: 81.63%

📊 Download HTML Report

Coverage breakdown available in the artifacts.

@phildenhoff phildenhoff enabled auto-merge (squash) June 29, 2026 06:52
…layer

Move the frontend-facing DTOs (LibraryBook, LibraryAuthor, LocalOrRemoteUrl,
the file list, Identifier) and the libcalibre->DTO conversion out of the Tauri
crate into a new platform-agnostic `citadel-core` crate, so a future
citadel-server can serialize the same shapes over HTTP.

The cover/file URL scheme is now injected via a `BookUrlBuilder` trait instead
of being hardcoded to Tauri's asset:// protocol:

- AssetUrlBuilder reproduces the desktop app's asset://localhost/... output
  byte-for-byte, including the ?v=<mtime_ms> cache-bust and has_cover trust.
- HttpUrlBuilder adds the Remote { url } path (https://.../api/books/<id>/...)
  for a future HTTP caller.

citadel-core depends only on libcalibre/serde/specta/urlencoding -- no tauri.
The Tauri shell re-exports LibraryBook/LibraryAuthor from citadel-core, injects
AssetUrlBuilder, and cover_thumbs now shares citadel_core::path_to_asset_url
(libs/util.rs removed). A unit test exercises both builders over the same Book.

bindings.ts is unchanged (specta emits identical names/shapes).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@phildenhoff phildenhoff force-pushed the extract-librarybook-serialization-cover-url-layer branch from c6ce4e4 to 20fb218 Compare June 30, 2026 03:48
@linear-code

linear-code Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

CDL-17

@github-actions

Copy link
Copy Markdown

libcalibre Test Coverage Report

Overall coverage: 81.63%

📊 Download HTML Report

Coverage breakdown available in the artifacts.

@phildenhoff phildenhoff merged commit 33b4d97 into main Jun 30, 2026
7 checks passed
@phildenhoff phildenhoff deleted the extract-librarybook-serialization-cover-url-layer branch June 30, 2026 03:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant