# aerkalov/ebooklib architecture

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

- Interactive diagram: https://gitdiagram.com/aerkalov/ebooklib
- Repository: https://github.com/aerkalov/ebooklib

## Overview

EbookLib is a Python library for programmatically reading and writing EPUB2/EPUB3 files. The main workflow uses the public `ebooklib.epub` API to read an EPUB into a mutable book model, or to create and populate that model and write it back as an EPUB. The model covers items, metadata, navigation and spine; reader and writer handle archive parsing and serialization. Plugins provide extensible processing hooks, though the excerpts do not show how the reader or writer dispatches them. Edges reflect README statements or shown source references; uncertain plugin dispatch is omitted.

Main entry points: [`ebooklib/reader.py`](https://github.com/aerkalov/ebooklib/blob/master/ebooklib/reader.py) (EPUB Reader), [`ebooklib/writer.py`](https://github.com/aerkalov/ebooklib/blob/master/ebooklib/writer.py) (EPUB Writer), [`ebooklib/utils.py`](https://github.com/aerkalov/ebooklib/blob/master/ebooklib/utils.py) (Format Utilities), [`ebooklib/epub.py`](https://github.com/aerkalov/ebooklib/blob/master/ebooklib/epub.py) (EPUB API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Public API"]
  node_api["EPUB API<br/>[epub.py]"]
end

subgraph group_model["Book Model"]
  node_book["Book Model<br/>[book.py]"]
  node_items["Content Items<br/>[items.py]"]
  node_toc["TOC Links<br/>[toc.py]"]
  node_constants["EPUB Constants<br/>[consts.py]"]
  node_exceptions["EPUB Errors<br/>[exceptions.py]"]
end

subgraph group_format["EPUB Processing"]
  node_reader["EPUB Reader<br/>[reader.py]"]
  node_writer["EPUB Writer<br/>[writer.py]"]
  node_utils["Format Utilities<br/>[utils.py]"]
end

subgraph group_plugins["Plugin Processing"]
  node_pluginbase["Plugin Hooks<br/>[base.py]"]
  node_standard["Standard Plugin<br/>[standard.py]"]
  node_booktype["Booktype Plugins<br/>[booktype.py]"]
  node_sourcecode["Sourcecode Plugin<br/>[sourcecode.py]"]
  node_tidyhtml["Tidy HTML Plugin<br/>[tidyhtml.py]"]
end

node_user(("Library User"))
node_epubfile["EPUB File"]

node_user -->|"uses"| node_api
node_api -->|"exposes reading"| node_reader
node_api -->|"exposes writing"| node_writer
node_reader -->|"reads"| node_epubfile
node_writer -->|"writes"| node_epubfile
node_reader -->|"populates"| node_book
node_reader -->|"creates items"| node_items
node_reader -->|"parses navigation"| node_toc
node_reader -->|"uses"| node_utils
node_reader -->|"uses"| node_constants
node_reader -->|"raises"| node_exceptions
node_writer -->|"serializes"| node_book
node_writer -->|"serializes"| node_items
node_writer -->|"serializes"| node_toc
node_writer -->|"uses"| node_utils
node_writer -->|"uses"| node_constants
node_book -->|"manages"| node_items
node_book -->|"uses"| node_constants
node_items -->|"uses"| node_constants
node_items -->|"uses"| node_utils
node_standard -->|"extends"| node_pluginbase
node_standard -->|"uses"| node_utils
node_standard -->|"uses"| node_api
node_booktype -->|"extends"| node_pluginbase
node_booktype -->|"uses"| node_utils
node_booktype -->|"uses"| node_api
node_sourcecode -->|"extends"| node_pluginbase
node_sourcecode -->|"uses"| node_utils
node_tidyhtml -->|"extends"| node_pluginbase

click node_api "https://github.com/aerkalov/ebooklib/blob/master/ebooklib/epub.py"
click node_book "https://github.com/aerkalov/ebooklib/blob/master/ebooklib/book.py"
click node_items "https://github.com/aerkalov/ebooklib/blob/master/ebooklib/items.py"
click node_toc "https://github.com/aerkalov/ebooklib/blob/master/ebooklib/toc.py"
click node_constants "https://github.com/aerkalov/ebooklib/blob/master/ebooklib/consts.py"
click node_exceptions "https://github.com/aerkalov/ebooklib/blob/master/ebooklib/exceptions.py"
click node_reader "https://github.com/aerkalov/ebooklib/blob/master/ebooklib/reader.py"
click node_writer "https://github.com/aerkalov/ebooklib/blob/master/ebooklib/writer.py"
click node_utils "https://github.com/aerkalov/ebooklib/blob/master/ebooklib/utils.py"
click node_pluginbase "https://github.com/aerkalov/ebooklib/blob/master/ebooklib/plugins/base.py"
click node_standard "https://github.com/aerkalov/ebooklib/blob/master/ebooklib/plugins/standard.py"
click node_booktype "https://github.com/aerkalov/ebooklib/blob/master/ebooklib/plugins/booktype.py"
click node_sourcecode "https://github.com/aerkalov/ebooklib/blob/master/ebooklib/plugins/sourcecode.py"
click node_tidyhtml "https://github.com/aerkalov/ebooklib/blob/master/ebooklib/plugins/tidyhtml.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_api,node_user toneBlue
class node_book,node_items,node_toc,node_constants,node_exceptions toneAmber
class node_reader,node_writer,node_utils toneMint
class node_pluginbase,node_standard,node_booktype,node_sourcecode,node_tidyhtml toneRose
class node_epubfile toneIndigo
```

## Components

### Public API

- [EPUB API](https://github.com/aerkalov/ebooklib/blob/master/ebooklib/epub.py): `ebooklib/epub.py`

### Book Model

- [Book Model](https://github.com/aerkalov/ebooklib/blob/master/ebooklib/book.py): `ebooklib/book.py`
- [Content Items](https://github.com/aerkalov/ebooklib/blob/master/ebooklib/items.py): `ebooklib/items.py`
- [TOC Links](https://github.com/aerkalov/ebooklib/blob/master/ebooklib/toc.py): `ebooklib/toc.py`
- [EPUB Constants](https://github.com/aerkalov/ebooklib/blob/master/ebooklib/consts.py): `ebooklib/consts.py`
- [EPUB Errors](https://github.com/aerkalov/ebooklib/blob/master/ebooklib/exceptions.py): `ebooklib/exceptions.py`

### EPUB Processing

- [EPUB Reader](https://github.com/aerkalov/ebooklib/blob/master/ebooklib/reader.py): `ebooklib/reader.py`
- [EPUB Writer](https://github.com/aerkalov/ebooklib/blob/master/ebooklib/writer.py): `ebooklib/writer.py`
- [Format Utilities](https://github.com/aerkalov/ebooklib/blob/master/ebooklib/utils.py): `ebooklib/utils.py`

### Plugin Processing

- [Plugin Hooks](https://github.com/aerkalov/ebooklib/blob/master/ebooklib/plugins/base.py): `ebooklib/plugins/base.py`
- [Standard Plugin](https://github.com/aerkalov/ebooklib/blob/master/ebooklib/plugins/standard.py): `ebooklib/plugins/standard.py`
- [Booktype Plugins](https://github.com/aerkalov/ebooklib/blob/master/ebooklib/plugins/booktype.py): `ebooklib/plugins/booktype.py`
- [Sourcecode Plugin](https://github.com/aerkalov/ebooklib/blob/master/ebooklib/plugins/sourcecode.py): `ebooklib/plugins/sourcecode.py`
- [Tidy HTML Plugin](https://github.com/aerkalov/ebooklib/blob/master/ebooklib/plugins/tidyhtml.py): `ebooklib/plugins/tidyhtml.py`

### Other components

- **Library User**
- **EPUB File**

## Connections

- Library User → EPUB API: uses (evidence: `README.md`)
- EPUB API → EPUB Reader: exposes reading (evidence: `ebooklib/epub.py`)
- EPUB API → EPUB Writer: exposes writing (evidence: `ebooklib/epub.py`)
- EPUB Reader → EPUB File: reads (evidence: `README.md`)
- EPUB Writer → EPUB File: writes (evidence: `README.md`)
- EPUB Reader → Book Model: populates (evidence: `ebooklib/reader.py`)
- EPUB Reader → Content Items: creates items (evidence: `ebooklib/reader.py`)
- EPUB Reader → TOC Links: parses navigation (evidence: `ebooklib/reader.py`)
- EPUB Reader → Format Utilities: uses (evidence: `ebooklib/reader.py`)
- EPUB Reader → EPUB Constants: uses (evidence: `ebooklib/reader.py`)
- EPUB Reader → EPUB Errors: raises (evidence: `ebooklib/reader.py`)
- EPUB Writer → Book Model: serializes (evidence: `ebooklib/writer.py`)
- EPUB Writer → Content Items: serializes (evidence: `ebooklib/writer.py`)
- EPUB Writer → TOC Links: serializes (evidence: `ebooklib/writer.py`)
- EPUB Writer → Format Utilities: uses (evidence: `ebooklib/writer.py`)
- EPUB Writer → EPUB Constants: uses (evidence: `ebooklib/writer.py`)
- Book Model → Content Items: manages (evidence: `ebooklib/book.py`)
- Book Model → EPUB Constants: uses (evidence: `ebooklib/book.py`)
- Content Items → EPUB Constants: uses (evidence: `ebooklib/items.py`)
- Content Items → Format Utilities: uses (evidence: `ebooklib/items.py`)
- Standard Plugin → Plugin Hooks: extends (evidence: `ebooklib/plugins/standard.py`)
- Standard Plugin → Format Utilities: uses (evidence: `ebooklib/plugins/standard.py`)
- Standard Plugin → EPUB API: uses (evidence: `ebooklib/plugins/standard.py`)
- Booktype Plugins → Plugin Hooks: extends (evidence: `ebooklib/plugins/booktype.py`)
- Booktype Plugins → Format Utilities: uses (evidence: `ebooklib/plugins/booktype.py`)
- Booktype Plugins → EPUB API: uses (evidence: `ebooklib/plugins/booktype.py`)
- Sourcecode Plugin → Plugin Hooks: extends (evidence: `ebooklib/plugins/sourcecode.py`)
- Sourcecode Plugin → Format Utilities: uses (evidence: `ebooklib/plugins/sourcecode.py`)
- Tidy HTML Plugin → Plugin Hooks: extends (evidence: `ebooklib/plugins/tidyhtml.py`)
