# nodrm/dedrm_tools architecture

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

- Interactive diagram: https://gitdiagram.com/nodrm/dedrm_tools
- Repository: https://github.com/nodrm/dedrm_tools

## Overview

##### Project Type and Purpose
- The project is a collection of DRM removal tools for ebooks that interface primarily as Calibre plugins. Two main plugins, DeDRM (for Amazon, Adobe, Barnes & Noble, and legacy formats) and Obok (for Kobo DRM), are at the core.
- The README clarifies that this is a fork of an earlier project with a focus on supporting multiple Calibre versions and a variety of DRM schemes. Complementary “Other_Tools” exist for additional DRM key processing or patching.

##### Analyzing the File Structure
- At the root, you see general project files (README.md, CHANGELOG.md, make_release.py, etc.) and configuration directories (.github) for CI/CD workflows.
- The project is divided into major directories:
– DeDRM_plugin: Contains the bulk of the DRM removal logic. This directory includes initialization (__init__.py), compatibility modules, DRM-specific modules (adobekey.py, androidkindlekey.py, kfxdedrm.py, etc.), scripts for standalone usage, configuration handling, and utility functions.
– Obok_plugin: The second plugin focused on removing Kobo DRM, including similar structure with initialization, configuration, dialogs, and localized translations.
– Other_Tools: A collection of ancillary scripts and patches (for Barnes & Noble, Adobe Digital Editions, Kindle variants, etc.), which support extra functionalities or legacy formats. They include both JavaScript-based tools and Python scripts.
- The presence of separate directories for GitHub workflows and ISSUE_TEMPLATE signifies a robust development process with automated tests or builds.

##### Main Components and Their Relationships
- User Interface/Calibre Integration: The entry point is the Calibre plugin interface. When installed, Calibre calls the appropriate plugin (DeDRM or Obok) based on the ebook format.
- DeDRM Plugin Core: This component includes various modules that detect the DRM type (e.g., Adobe, Kindle, Mobipocket) and call specialized routines (like adobekey libraries for Adobe DRM or androidkindlekey for Kindle on Android). It links to key retrieval, decryption, and file conversion modules.
- Obok Plugin: Similarly, this plugin manages Kobo-specific DRM, handling user dialogs, configuration, and utility functions to process Kobo ebooks.
- Other DRM Key Scripts/Tools: These act as support tools that can operate independently from Calibre. They provide DRM key extraction, version-specific patches, and additional functionality.
- External Dependencies & Environment: Integration with different Calibre versions (Python 2 & Python 3), supported by conditional compatibility layers and external workflows for releases (github workflows, release candidate publishing).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface Layer"
        UI["User/Calibre Interface"]:::ui
    end

    %% Calibre Plugin Integration
    subgraph "Calibre Plugin Integration"
        PI1["DeDRM Plugin Import"]:::ui
        PI2["Obok Plugin Import"]:::ui
    end

    %% Plugins Layer
    subgraph "Plugins Layer"
        subgraph "DeDRM Plugin"
            dedrmCore["DRM Removal Core (Adobe, Kindle, KFX, etc.)"]:::plugin
            dedrmStand["Standalone Utilities"]:::plugin
        end
        subgraph "Obok Plugin"
            obokConf["Configuration & Initialization"]:::plugin
            obokDialogs["Dialogs & UI"]:::plugin
            obokTrans["Translations"]:::plugin
        end
    end

    %% Auxiliary Tools
    subgraph "Auxiliary Tools"
        otherTools["Other DRM Key Scripts/Tools"]:::tools
    end

    %% DevOps & CI/CD
    subgraph "DevOps & CI/CD"
        ci_cd["CI/CD Workflows"]:::dev
    end

    %% Connections
    UI --> PI1
    UI --> PI2
    PI1 --> dedrmCore
    PI2 --> obokConf
    PI2 --> obokDialogs
    PI2 --> obokTrans
    dedrmCore --> dedrmStand
    dedrmCore --> otherTools
    obokConf --> otherTools
    otherTools --> ci_cd

    %% Click Events
    click dedrmCore "https://github.com/nodrm/dedrm_tools/tree/master/DeDRM_plugin"
    click dedrmStand "https://github.com/nodrm/dedrm_tools/tree/master/DeDRM_plugin/standalone"
    click obokConf "https://github.com/nodrm/dedrm_tools/tree/master/Obok_plugin"
    click obokDialogs "https://github.com/nodrm/dedrm_tools/tree/master/Obok_plugin"
    click obokTrans "https://github.com/nodrm/dedrm_tools/tree/master/Obok_plugin/translations/"
    click otherTools "https://github.com/nodrm/dedrm_tools/tree/master/Other_Tools"
    click ci_cd "https://github.com/nodrm/dedrm_tools/blob/master/.github"
    click PI1 "https://github.com/nodrm/dedrm_tools/blob/master/DeDRM_plugin/plugin-import-name-dedrm.txt"
    click PI2 "https://github.com/nodrm/dedrm_tools/blob/master/Obok_plugin/plugin-import-name-obok_dedrm.txt"

    %% Styles
    classDef ui fill:#f9e79f,stroke:#b7950b,stroke-width:2px;
    classDef plugin fill:#aed6f1,stroke:#2471a3,stroke-width:2px;
    classDef tools fill:#abebc6,stroke:#138d75,stroke-width:2px;
    classDef dev fill:#f5b7b1,stroke:#c0392b,stroke-width:2px;
```
