# cporcellijr/bookbridge architecture

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

- Interactive diagram: https://gitdiagram.com/cporcellijr/bookbridge
- Repository: https://github.com/cporcellijr/bookbridge

## Overview

BookBridge is a self-hosted, multi-user synchronization engine for reading and listening progress across ebook readers, audiobook servers, and reading trackers. Its central workflow coordinates service-specific sync clients around shared book mappings and progress state; when needed, it aligns ebook text with audio timing so positions can cross formats. The README also describes matching suggestions, annotations, read-along EPUB generation, session summaries, and settings management. Connections below follow explicit README statements or SOURCE INDEX references; unsampled feature links are documented at subsystem level rather than inferred call chains.

Main entry points: [`src/sync_manager.py`](https://github.com/cporcellijr/bookbridge/blob/main/src/sync_manager.py) (Sync manager), [`src/services/alignment_service.py`](https://github.com/cporcellijr/bookbridge/blob/main/src/services/alignment_service.py) (Alignment maps), [`src/db/models.py`](https://github.com/cporcellijr/bookbridge/blob/main/src/db/models.py) (Book and progress data), [`src/sync_clients/sync_client_interface.py`](https://github.com/cporcellijr/bookbridge/blob/main/src/sync_clients/sync_client_interface.py) (Sync client contract)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_orchestration["Sync orchestration"]
  node_manager["Sync manager<br/>[sync_manager.py]"]
  node_interface["Sync client contract"]
end

subgraph group_connectors["Service connectors"]
  node_abs_sync["Audiobookshelf sync<br/>[abs_sync_client.py]"]
  node_kosync["KOReader sync"]
  node_storyteller_sync["Storyteller sync"]
  node_tracker_sync["Tracker sync clients"]
  node_service_apis["Service APIs<br/>[api_clients.py]"]
end

subgraph group_alignment["Alignment and media"]
  node_ebook["Ebook parsing<br/>[ebook_utils.py]"]
  node_alignment_service["Alignment maps"]
  node_transcriber["Audio transcription<br/>[transcriber.py]"]
  node_transcript["Storyteller transcripts"]
end

subgraph group_product["Matching and product features"]
  node_forge["Read-along generation<br/>[forge_service.py]"]
  node_suggestions["Library suggestions"]
  node_matching["Book matching<br/>[llm_matching.py]"]
  node_annotations["Annotation synchronization"]
  node_sessions["Session summaries"]
end

subgraph group_platform["Web and state"]
  node_web["Web dashboard<br/>[web_server.py]"]
  node_book_data["Book and progress data<br/>[models.py]"]
  node_database[("Database service")]
  node_user_config["User credentials<br/>[user_config.py]"]
  node_user_context["User context<br/>[user_context.py]"]
end

node_reader(("Readers and users"))

node_reader -->|"manages sync"| node_web
node_manager -->|"uses contract"| node_interface
node_abs_sync -->|"implements contract"| node_interface
node_kosync -->|"implements contract"| node_interface
node_storyteller_sync -->|"implements contract"| node_interface
node_manager -->|"coordinates alignment"| node_alignment_service
node_manager -->|"loads transcripts"| node_transcript
node_manager -->|"extracts text"| node_ebook
node_manager -->|"reads book state"| node_book_data
node_alignment_service -->|"stores alignment"| node_book_data
node_alignment_service -->|"uses ebook parsing"| node_ebook
node_alignment_service -->|"uses transcription"| node_transcriber
node_transcriber -->|"reads transcript format"| node_transcript
node_forge -->|"uses alignment"| node_alignment_service
node_forge -->|"uses transcripts"| node_transcript
node_suggestions -->|"ranks candidates"| node_matching
node_suggestions -->|"reads book data"| node_book_data
node_service_apis -->|"transfers ebook files"| node_ebook
node_database -->|"persists models"| node_book_data
node_user_config -->|"resolves user settings"| node_user_context
node_annotations -.->|"syncs annotations"| node_abs_sync
node_sessions -->|"summarizes activity"| node_book_data
node_manager -.->|"syncs services"| node_service_apis
node_reader -->|"syncs reading state"| node_manager

click node_web "https://github.com/cporcellijr/bookbridge/blob/main/src/web_server.py"
click node_manager "https://github.com/cporcellijr/bookbridge/blob/main/src/sync_manager.py"
click node_interface "https://github.com/cporcellijr/bookbridge/blob/main/src/sync_clients/sync_client_interface.py"
click node_abs_sync "https://github.com/cporcellijr/bookbridge/blob/main/src/sync_clients/abs_sync_client.py"
click node_kosync "https://github.com/cporcellijr/bookbridge/blob/main/src/sync_clients/kosync_sync_client.py"
click node_storyteller_sync "https://github.com/cporcellijr/bookbridge/blob/main/src/sync_clients/storyteller_sync_client.py"
click node_tracker_sync "https://github.com/cporcellijr/bookbridge/blob/main/src/sync_clients/sync_client_interface.py"
click node_service_apis "https://github.com/cporcellijr/bookbridge/blob/main/src/api/api_clients.py"
click node_book_data "https://github.com/cporcellijr/bookbridge/blob/main/src/db/models.py"
click node_database "https://github.com/cporcellijr/bookbridge/blob/main/src/db/database_service.py"
click node_user_config "https://github.com/cporcellijr/bookbridge/blob/main/src/utils/user_config.py"
click node_user_context "https://github.com/cporcellijr/bookbridge/blob/main/src/utils/user_context.py"
click node_ebook "https://github.com/cporcellijr/bookbridge/blob/main/src/utils/ebook_utils.py"
click node_alignment_service "https://github.com/cporcellijr/bookbridge/blob/main/src/services/alignment_service.py"
click node_transcriber "https://github.com/cporcellijr/bookbridge/blob/main/src/utils/transcriber.py"
click node_transcript "https://github.com/cporcellijr/bookbridge/blob/main/src/utils/storyteller_transcript.py"
click node_forge "https://github.com/cporcellijr/bookbridge/blob/main/src/services/forge_service.py"
click node_suggestions "https://github.com/cporcellijr/bookbridge/blob/main/src/services/suggestions_service.py"
click node_matching "https://github.com/cporcellijr/bookbridge/blob/main/src/services/llm_matching.py"
click node_annotations "https://github.com/cporcellijr/bookbridge/blob/main/src/services/annotation_sync_service.py"
click node_sessions "https://github.com/cporcellijr/bookbridge/blob/main/src/services/reading_session_aggregator.py"

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_manager,node_interface,node_reader toneBlue
class node_abs_sync,node_kosync,node_storyteller_sync,node_tracker_sync,node_service_apis toneAmber
class node_ebook,node_alignment_service,node_transcriber,node_transcript toneMint
class node_forge,node_suggestions,node_matching,node_annotations,node_sessions toneRose
class node_web,node_book_data,node_database,node_user_config,node_user_context toneIndigo
```

## Components

### Sync orchestration

- [Sync manager](https://github.com/cporcellijr/bookbridge/blob/main/src/sync_manager.py): `src/sync_manager.py`
- [Sync client contract](https://github.com/cporcellijr/bookbridge/blob/main/src/sync_clients/sync_client_interface.py): `src/sync_clients/sync_client_interface.py`

### Service connectors

- [Audiobookshelf sync](https://github.com/cporcellijr/bookbridge/blob/main/src/sync_clients/abs_sync_client.py): `src/sync_clients/abs_sync_client.py`
- [KOReader sync](https://github.com/cporcellijr/bookbridge/blob/main/src/sync_clients/kosync_sync_client.py): `src/sync_clients/kosync_sync_client.py`
- [Storyteller sync](https://github.com/cporcellijr/bookbridge/blob/main/src/sync_clients/storyteller_sync_client.py): `src/sync_clients/storyteller_sync_client.py`
- [Tracker sync clients](https://github.com/cporcellijr/bookbridge/blob/main/src/sync_clients/sync_client_interface.py): `src/sync_clients/sync_client_interface.py`
- [Service APIs](https://github.com/cporcellijr/bookbridge/blob/main/src/api/api_clients.py): `src/api/api_clients.py`

### Alignment and media

- [Ebook parsing](https://github.com/cporcellijr/bookbridge/blob/main/src/utils/ebook_utils.py): `src/utils/ebook_utils.py`
- [Alignment maps](https://github.com/cporcellijr/bookbridge/blob/main/src/services/alignment_service.py): `src/services/alignment_service.py`
- [Audio transcription](https://github.com/cporcellijr/bookbridge/blob/main/src/utils/transcriber.py): `src/utils/transcriber.py`
- [Storyteller transcripts](https://github.com/cporcellijr/bookbridge/blob/main/src/utils/storyteller_transcript.py): `src/utils/storyteller_transcript.py`

### Matching and product features

- [Read-along generation](https://github.com/cporcellijr/bookbridge/blob/main/src/services/forge_service.py): `src/services/forge_service.py`
- [Library suggestions](https://github.com/cporcellijr/bookbridge/blob/main/src/services/suggestions_service.py): `src/services/suggestions_service.py`
- [Book matching](https://github.com/cporcellijr/bookbridge/blob/main/src/services/llm_matching.py): `src/services/llm_matching.py`
- [Annotation synchronization](https://github.com/cporcellijr/bookbridge/blob/main/src/services/annotation_sync_service.py): `src/services/annotation_sync_service.py`
- [Session summaries](https://github.com/cporcellijr/bookbridge/blob/main/src/services/reading_session_aggregator.py): `src/services/reading_session_aggregator.py`

### Web and state

- [Web dashboard](https://github.com/cporcellijr/bookbridge/blob/main/src/web_server.py): `src/web_server.py`
- [Book and progress data](https://github.com/cporcellijr/bookbridge/blob/main/src/db/models.py): `src/db/models.py`
- [Database service](https://github.com/cporcellijr/bookbridge/blob/main/src/db/database_service.py): `src/db/database_service.py`
- [User credentials](https://github.com/cporcellijr/bookbridge/blob/main/src/utils/user_config.py): `src/utils/user_config.py`
- [User context](https://github.com/cporcellijr/bookbridge/blob/main/src/utils/user_context.py): `src/utils/user_context.py`

### Other components

- **Readers and users**

## Connections

- Readers and users → Web dashboard: manages sync
- Sync manager → Sync client contract: uses contract (evidence: `src/sync_manager.py`)
- Audiobookshelf sync → Sync client contract: implements contract (evidence: `src/sync_clients/abs_sync_client.py`)
- KOReader sync → Sync client contract: implements contract (evidence: `src/sync_clients/kosync_sync_client.py`)
- Storyteller sync → Sync client contract: implements contract (evidence: `src/sync_clients/storyteller_sync_client.py`)
- Sync manager → Alignment maps: coordinates alignment (evidence: `src/sync_manager.py`)
- Sync manager → Storyteller transcripts: loads transcripts (evidence: `src/sync_manager.py`)
- Sync manager → Ebook parsing: extracts text (evidence: `src/sync_manager.py`)
- Sync manager → Book and progress data: reads book state (evidence: `src/sync_manager.py`)
- Alignment maps → Book and progress data: stores alignment (evidence: `src/services/alignment_service.py`)
- Alignment maps → Ebook parsing: uses ebook parsing (evidence: `src/services/alignment_service.py`)
- Alignment maps → Audio transcription: uses transcription (evidence: `src/services/alignment_service.py`)
- Audio transcription → Storyteller transcripts: reads transcript format (evidence: `src/utils/transcriber.py`)
- Read-along generation → Alignment maps: uses alignment (evidence: `src/services/forge_service.py`)
- Read-along generation → Storyteller transcripts: uses transcripts (evidence: `src/services/forge_service.py`)
- Library suggestions → Book matching: ranks candidates (evidence: `src/services/suggestions_service.py`)
- Library suggestions → Book and progress data: reads book data (evidence: `src/services/suggestions_service.py`)
- Service APIs → Ebook parsing: transfers ebook files
- Database service → Book and progress data: persists models (evidence: `src/db/database_service.py`)
- User credentials → User context: resolves user settings (evidence: `src/utils/user_config.py`)
- Annotation synchronization → Audiobookshelf sync: syncs annotations
- Session summaries → Book and progress data: summarizes activity (evidence: `src/db/database_service.py`)
- Sync manager → Service APIs: syncs services
- Readers and users → Sync manager: syncs reading state
