# booklore-app/booklore architecture

> Architecture diagram of the GitHub repository booklore-app/booklore, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/booklore-app/booklore
- Repository: https://github.com/booklore-app/booklore

## Overview

1. **Repository shape**
   - This is a two-part monorepo: a **Spring Boot backend** in `booklore-api` and an **Angular frontend** in `booklore-ui`.
   - The backend is the system of record for library state, user data, metadata, tasks, and sync state. The frontend is a rich client that talks to the backend over REST and WebSocket.

2. **Backend runtime and persistence**
   - `booklore-api` is a Java/Gradle application (`BookloreApplication`) built around the usual **controller → service → repository → entity** layering.
   - Persistence is in **MariaDB**, with schema management via **Flyway** migrations under `src/main/resources/db/migration`.
   - The model is heavily normalized around books, files, metadata, shelves, users, progress, tasks, devices, and settings.

3. **Core domain boundary**
   - The main domain boundary is the **library catalog**: books, files, authors, categories/tags, shelves, library paths, and user-specific state.
   - DTOs, entities, mappers, and repositories are all split explicitly, so the diagram should show:
     - REST controllers at the edge
     - services orchestrating use cases
     - repositories handling DB access
     - file/metadata/device subsystems hanging off the core catalog

4. **File system and import pipeline**
   - Book files live outside the database on mounted storage; the app reads and sometimes writes them depending on storage mode.
   - The **library ingestion pipeline** is a major subsystem:
     - file watching / monitoring
     - file processing and fingerprinting
     - grouping and library assignment
     - metadata extraction
     - persistence of book/file records
   - `bookdrop` is a distinct import path: watched folder → parsed files → metadata enrichment → review/finalize → library import.

5. **Metadata enrichment and writing**
   - Metadata handling is its own subsystem with extractors, parsers, writers, matchers, and refresh tasks.
   - The backend supports multiple file types and metadata formats through specialized processors for **EPUB, PDF, CBZ, AZW3, MOBI, FB2, and audiobooks**.
   - External metadata providers include services like **Google Books, Open Library/OpenLibrary-style lookups, Amazon, Audible/Audnexus, Hardcover, ComicVine, RanobeDb, Douban, Goodreads, LubimyCzytac**, and similar sources.
   - Metadata can be stored in DB, written back into files, or persisted as sidecar metadata, depending on settings and format.

6. **Reader/streaming subsystem**
   - Reading is not just download: the backend exposes reader-oriented services for **EPUB, PDF, comics/CBZ, and audiobooks**.
   - There are dedicated reader services for streaming content, serving page/audio data, and managing reading progress, bookmarks, annotations, notes, and viewer preferences.
   - The `templates/epub` and `assets/foliate` resources indicate server-side EPUB generation plus a browser reader integration layer.

7. **Device and interoperability integrations**
   - Several integrations are first-class architecture boundaries:
     - **Kobo** sync and device auth
     - **OPDS** feeds and users
     - **KOReader** sync/progress compatibility
     - optional **Komga** compatibility / clean-mode handling
     - email sending for “share book” workflows
     - Hardcover sync for external catalog enrichment
   - These are exposed as dedicated controllers/services and have their own DTOs, repositories, and security flows.

8. **Authentication, authorization, and security**
   - Security is a major cross-cutting subsystem with:
     - local login / JWT
     - refresh tokens
     - rate limiting
     - OIDC login/callback/backchannel logout
     - per-resource access control via annotations and aspects
   - There are specialized filters for different protected resources, plus WebSocket auth and device-specific auth flows.
   - Authorization is domain-aware: access checks can be tied to libraries or books, not just general roles.

9. **Asynchronous work and scheduled tasks**
   - Long-running work is separated into tasks and cron/scheduler services rather than handled inline in request threads.
   - Important background jobs include:
     - library scan/rescan
     - metadata refresh and cleanup
     - deleted-book cleanup
     - recommendation updates
     - BookDrop periodic scans
     - OIDC/session cleanup
   - Task history and progress are persisted, and the frontend can monitor them.

10. **Real-time notifications**
   - The backend publishes live events over **WebSocket/STOMP-style messaging** for things like log notifications, task progress, book add/remove events, and library health updates.
   - This is the main push channel the UI uses to reflect asynchronous backend work without polling everywhere.

11. **Frontend structure**
   - The Angular app is organized by feature folders: books, metadata, readers, settings, stats, bookdrop, notebook, author/series browsers, and library creation.
   - Each feature typically has:
     - route-facing container components
     - smaller presentational components
     - feature-specific services/state helpers
   - Shared concerns live in `src/app/shared` and `src/app/core`:
     - auth/OIDC/bootstrap
     - API config
     - reusable layout
     - websocket client
     - shared UI primitives and helpers

12. **Frontend/backend interaction model**
   - The UI relies on backend APIs for all authoritative state: library browsing, metadata editing, reader actions, stats, tasks, settings, and device sync.
   - It also consumes live notifications for progress and system events.
   - Feature services wrap the HTTP API, while reader features additionally manage browser-side state for progress, notes, selection, and display preferences.

13. **Operational packaging**
   - The repo is designed for self-hosting: Dockerfiles, compose examples, Helm chart example, and podman examples are all included.
   - The README makes a key deployment constraint explicit: **local filesystem storage is expected for write-heavy file operations**; network storage can be used only in a reduced “metadata-only” mode where file writes/reorganization are disabled.

14. **What to emphasize in an architecture diagram**
   - Draw the system as:
     - **Browser UI**
     - → **Spring Boot API**
     - → **MariaDB**
     - → **filesystem/book library paths**
     - with side integrations to **metadata providers, OIDC identity providers, Kobo/OPDS/KOReader devices, email, and background schedulers**
   - Add a separate lane for **real-time WebSocket notifications** and another for **async tasks/watchers** so the import, sync, and refresh flows are visually distinct from normal request/response traffic.

Main entry points: [`booklore-api/src/main/java/org/booklore/controller`](https://github.com/booklore-app/booklore/tree/develop/booklore-api/src/main/java/org/booklore/controller) (REST edge), [`booklore-ui/src`](https://github.com/booklore-app/booklore/tree/develop/booklore-ui/src) (Browser UI), [`booklore-api/src/main/resources/db/migration`](https://github.com/booklore-app/booklore/tree/develop/booklore-api/src/main/resources/db/migration) (MariaDB), [`booklore-api/src/main/java/org/booklore/service/metadata`](https://github.com/booklore-app/booklore/tree/develop/booklore-api/src/main/java/org/booklore/service/metadata) (Metadata engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_repo["Booklore"]
  node_providers(("External services<br/>identity+metadata+devices"))
end

subgraph group_backend["Backend"]
  node_api["Spring API<br/>Boot app"]
  node_api_web["REST edge<br/>controllers"]
  node_api_catalog["Catalog services<br/>domain services"]
  node_api_library["Library pipeline<br/>ingestion/watchers"]
  node_api_metadata["Metadata engine<br/>extract/match/write"]
  node_api_reader["Reader services<br/>streaming/serve"]
  node_api_devices["Device sync<br/>integrations"]
  node_api_security["Security<br/>authn/authz"]
  node_api_tasks["Async tasks<br/>jobs/scheduler"]
  node_db[("MariaDB<br/>relational store")]
  node_fs[("Library files<br/>filesystem storage")]
end

subgraph group_frontend["Frontend"]
  node_ui["Browser UI<br/>Angular client"]
  node_ui_core["Core shell<br/>auth/layout"]
  node_ui_library["Library features<br/>books/catalog UI"]
  node_ui_metadata["Metadata UI<br/>editing/workflows"]
  node_ui_reader["Readers<br/>reading clients"]
  node_ui_settings["Settings<br/>admin UI"]
  node_ui_realtime(("Live feed<br/>stomp/websocket"))
end

subgraph group_infra["Ops"]
  node_deploy["Packaging<br/>docker/helm/podman"]
end

node_ui -->|"bootstraps"| node_ui_core
node_ui -->|"navigates"| node_ui_library
node_ui -->|"edits"| node_ui_metadata
node_ui -->|"reads"| node_ui_reader
node_ui -->|"administers"| node_ui_settings
node_ui_core -->|"subscribes"| node_ui_realtime
node_ui -->|"REST"| node_api_web
node_ui_realtime -->|"WS/STOMP"| node_api
node_api -->|"exposes"| node_api_web
node_api_web -->|"guards"| node_api_security
node_api_web -->|"delegates"| node_api_catalog
node_api_web -->|"delegates"| node_api_library
node_api_web -->|"delegates"| node_api_metadata
node_api_web -->|"delegates"| node_api_reader
node_api_web -->|"delegates"| node_api_devices
node_api_web -->|"delegates"| node_api_tasks
node_api_catalog -->|"persists"| node_db
node_api_library -->|"watches"| node_fs
node_api_library -->|"records"| node_db
node_api_metadata -->|"queries"| node_providers
node_api_metadata -->|"writes"| node_fs
node_api_metadata -->|"stores"| node_db
node_api_reader -->|"streams"| node_fs
node_api_reader -->|"tracks"| node_db
node_api_devices -->|"syncs with"| node_providers
node_api_devices -->|"persists"| node_db
node_api_tasks -->|"tracks"| node_db
node_api_tasks -->|"runs"| node_api_library
node_api_tasks -->|"refreshes"| node_api_metadata
node_api_security -->|"OIDC"| node_providers
node_api_security -->|"stores"| node_db
node_api -->|"serves files"| node_fs
node_api -.->|"packaged by"| node_deploy

click node_ui "https://github.com/booklore-app/booklore/tree/develop/booklore-ui/src"
click node_ui_core "https://github.com/booklore-app/booklore/tree/develop/booklore-ui/src/app/core"
click node_ui_library "https://github.com/booklore-app/booklore/tree/develop/booklore-ui/src/app/features/book"
click node_ui_metadata "https://github.com/booklore-app/booklore/tree/develop/booklore-ui/src/app/features/metadata"
click node_ui_reader "https://github.com/booklore-app/booklore/tree/develop/booklore-ui/src/app/features/readers"
click node_ui_settings "https://github.com/booklore-app/booklore/tree/develop/booklore-ui/src/app/features/settings"
click node_ui_realtime "https://github.com/booklore-app/booklore/tree/develop/booklore-ui/src/app/shared/websocket"
click node_api "https://github.com/booklore-app/booklore/blob/develop/booklore-api/src/main/java/org/booklore/BookloreApplication.java"
click node_api_web "https://github.com/booklore-app/booklore/tree/develop/booklore-api/src/main/java/org/booklore/controller"
click node_api_catalog "https://github.com/booklore-app/booklore/tree/develop/booklore-api/src/main/java/org/booklore/service/book"
click node_api_library "https://github.com/booklore-app/booklore/tree/develop/booklore-api/src/main/java/org/booklore/service/library"
click node_api_metadata "https://github.com/booklore-app/booklore/tree/develop/booklore-api/src/main/java/org/booklore/service/metadata"
click node_api_reader "https://github.com/booklore-app/booklore/tree/develop/booklore-api/src/main/java/org/booklore/service/reader"
click node_api_devices "https://github.com/booklore-app/booklore/tree/develop/booklore-api/src/main/java/org/booklore/service/kobo"
click node_api_security "https://github.com/booklore-app/booklore/tree/develop/booklore-api/src/main/java/org/booklore/config/security"
click node_api_tasks "https://github.com/booklore-app/booklore/tree/develop/booklore-api/src/main/java/org/booklore/service/task"
click node_db "https://github.com/booklore-app/booklore/tree/develop/booklore-api/src/main/resources/db/migration"
click node_deploy "https://github.com/booklore-app/booklore/tree/develop/Dockerfile"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_providers toneBlue
class node_api,node_api_web,node_api_catalog,node_api_library,node_api_metadata,node_api_reader,node_api_devices,node_api_security,node_api_tasks,node_db,node_fs toneAmber
class node_ui,node_ui_core,node_ui_library,node_ui_metadata,node_ui_reader,node_ui_settings,node_ui_realtime toneMint
class node_deploy toneRose
```

## Components

### Booklore

Two-part monorepo with backend API, Angular UI, and deployment assets.

- **External services**: identity+metadata+devices · OIDC providers, book metadata sources, device endpoints, and email infrastructure.

### Backend

Spring Boot application with layered domain services and persistence.

- [Spring API](https://github.com/booklore-app/booklore/blob/develop/booklore-api/src/main/java/org/booklore/BookloreApplication.java): Boot app · Main backend application exposing REST, WebSocket, and protected file endpoints. · `booklore-api/src/main/java/org/booklore/BookloreApplication.java`
- [REST edge](https://github.com/booklore-app/booklore/tree/develop/booklore-api/src/main/java/org/booklore/controller): controllers · Controllers for books, libraries, metadata, readers, tasks, auth, and integrations. · `booklore-api/src/main/java/org/booklore/controller`
- [Catalog services](https://github.com/booklore-app/booklore/tree/develop/booklore-api/src/main/java/org/booklore/service/book): domain services · Book, shelf, author, notebook, recommendation, and user-facing catalog orchestration. · `booklore-api/src/main/java/org/booklore/service/book`
- [Library pipeline](https://github.com/booklore-app/booklore/tree/develop/booklore-api/src/main/java/org/booklore/service/library): ingestion/watchers · Library scans, file watching, grouping, processing, deletions, and bookdrop import. · `booklore-api/src/main/java/org/booklore/service/library`
- [Metadata engine](https://github.com/booklore-app/booklore/tree/develop/booklore-api/src/main/java/org/booklore/service/metadata): extract/match/write · Metadata extraction, provider lookups, matching, refresh, sidecar handling, and writers. · `booklore-api/src/main/java/org/booklore/service/metadata`
- [Reader services](https://github.com/booklore-app/booklore/tree/develop/booklore-api/src/main/java/org/booklore/service/reader): streaming/serve · EPUB, PDF, comic, and audiobook streaming plus progress and annotations. · `booklore-api/src/main/java/org/booklore/service/reader`
- [Device sync](https://github.com/booklore-app/booklore/tree/develop/booklore-api/src/main/java/org/booklore/service/kobo): integrations · Kobo, OPDS, KOReader, Komga compatibility, email sharing, and Hardcover sync. · `booklore-api/src/main/java/org/booklore/service/kobo`
- [Security](https://github.com/booklore-app/booklore/tree/develop/booklore-api/src/main/java/org/booklore/config/security): authn/authz · JWT login, refresh tokens, OIDC, rate limiting, resource access checks, and WebSocket auth. · `booklore-api/src/main/java/org/booklore/config/security`
- [Async tasks](https://github.com/booklore-app/booklore/tree/develop/booklore-api/src/main/java/org/booklore/service/task): jobs/scheduler · Scheduled scans, metadata refresh, cleanup, recommendations, and task history. · `booklore-api/src/main/java/org/booklore/service/task`
- [MariaDB](https://github.com/booklore-app/booklore/tree/develop/booklore-api/src/main/resources/db/migration): relational store · Persistent system of record for users, books, metadata, tasks, sync state, and settings. · `booklore-api/src/main/resources/db/migration`
- **Library files**: filesystem storage · Mounted book storage, import folders, sidecars, covers, and generated files.

### Frontend

Angular client organized by feature areas and shared application services.

- [Browser UI](https://github.com/booklore-app/booklore/tree/develop/booklore-ui/src): Angular client · Rich web client for browsing, reading, metadata editing, tasks, and settings. · `booklore-ui/src`
- [Core shell](https://github.com/booklore-app/booklore/tree/develop/booklore-ui/src/app/core): auth/layout · Bootstrap, auth, API config, layout, websocket client, and shared services. · `booklore-ui/src/app/core`
- [Library features](https://github.com/booklore-app/booklore/tree/develop/booklore-ui/src/app/features/book): books/catalog UI · Book browsing, shelves, authors, series, library creation, and book actions. · `booklore-ui/src/app/features/book`
- [Metadata UI](https://github.com/booklore-app/booklore/tree/develop/booklore-ui/src/app/features/metadata): editing/workflows · Metadata search, review, bulk edit, cover tools, and sidecar management. · `booklore-ui/src/app/features/metadata`
- [Readers](https://github.com/booklore-app/booklore/tree/develop/booklore-ui/src/app/features/readers): reading clients · Ebook, PDF, comic, and audiobook readers with local viewing state. · `booklore-ui/src/app/features/readers`
- [Settings](https://github.com/booklore-app/booklore/tree/develop/booklore-ui/src/app/features/settings): admin UI · Security, devices, email, metadata, reader preferences, tasks, and users. · `booklore-ui/src/app/features/settings`
- [Live feed](https://github.com/booklore-app/booklore/tree/develop/booklore-ui/src/app/shared/websocket): stomp/websocket · Client-side notification and progress stream for backend events. · `booklore-ui/src/app/shared/websocket`

### Ops

Build, packaging, and deployment support for self-hosted installs.

- [Packaging](https://github.com/booklore-app/booklore/tree/develop/Dockerfile): docker/helm/podman · Container, compose, chart, and example deployment assets for self-hosting. · `Dockerfile`

## Connections

- Browser UI → Core shell: bootstraps · App shell initializes auth, layout, config, and notifications.
- Browser UI → Library features: navigates · Primary catalog browsing and library actions.
- Browser UI → Metadata UI: edits · Metadata search, merge, and bulk update workflows.
- Browser UI → Readers: reads · Launches ebook, PDF, comic, and audiobook viewers.
- Browser UI → Settings: administers · Settings and management screens.
- Core shell → Live feed: subscribes · Receives task progress and system notifications.
- Browser UI → REST edge: REST · All authoritative state is fetched and mutated through backend APIs.
- Live feed → Spring API: WS/STOMP · Live notifications are pushed from the backend.
- Spring API → REST edge: exposes · HTTP and WebSocket entry points.
- REST edge → Security: guards · Protected endpoints and auth flows are enforced at the edge.
- REST edge → Catalog services: delegates · Controllers hand off catalog use cases to services.
- REST edge → Library pipeline: delegates · Library import, scan, and file management endpoints.
- REST edge → Metadata engine: delegates · Metadata edit, lookup, refresh, and sidecar endpoints.
- REST edge → Reader services: delegates · Streaming and reader-specific endpoints.
- REST edge → Device sync: delegates · Kobo, OPDS, KOReader, email, and compatibility endpoints.
- REST edge → Async tasks: delegates · Task creation, monitoring, and history endpoints.
- Catalog services → MariaDB: persists · Books, shelves, users, progress, notes, and permissions.
- Library pipeline → Library files: watches · Reads mounted storage and reacts to file changes.
- Library pipeline → MariaDB: records · Persists file, grouping, and library state.
- Metadata engine → External services: queries · Calls external metadata and enrichment sources.
- Metadata engine → Library files: writes · Can write metadata, sidecars, covers, and reorganized files.
- Metadata engine → MariaDB: stores · Persists metadata, proposals, jobs, and settings.
- Reader services → Library files: streams · Serves book content and generated reader assets.
- Reader services → MariaDB: tracks · Stores progress, bookmarks, annotations, and preferences.
- Device sync → External services: syncs with · Device ecosystems and external sync targets.
- Device sync → MariaDB: persists · Device auth, snapshots, settings, and sync state.
- Async tasks → MariaDB: tracks · Task history, cron configuration, and progress.
- Async tasks → Library pipeline: runs · Scheduled scans and periodic bookdrop work.
- Async tasks → Metadata engine: refreshes · Metadata refresh, cleanup, and recommendation updates.
- Security → External services: OIDC · Login, callback, and backchannel logout integrate with identity providers.
- Security → MariaDB: stores · Refresh tokens, secrets, sessions, and auth mappings.
- Spring API → Library files: serves files · Reader and file operations depend on local filesystem storage.
- Spring API → Packaging: packaged by · Container and platform assets deploy the application.
