# dvgamerr-app/hentai-downloader architecture

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

- Interactive diagram: https://gitdiagram.com/dvgamerr-app/hentai-downloader
- Repository: https://github.com/dvgamerr-app/hentai-downloader

## Overview

##### Main System Components

a. Electron Application Structure:
- Main Process (Backend)
- Renderer Process (Frontend)
- Preload Scripts (Bridge)

b. External Services:
- E-hentai.org API
- Exhentai.org API
- File System Integration

##### Component Organization

Frontend Layer:
- Svelte-based UI components
- Clipboard monitoring system
- Queue management interface

Middleware Layer:
- Preload scripts that handle IPC communication
- Security context bridges

Backend Layer:
- Plugin system for different manga sources
- Download management system
- Configuration management
- File system operations

##### Specific Implementation Details

Key features:
- Cookie/Session management for exhentai.org
- Download queue system
- Manga parsing and processing
- File management and naming system

##### Data Flow Representation

- URL input flow from clipboard to parser
- Authentication flow for protected content
- Download queue processing
- File saving workflow

##### Component Relationships

- IPC communication between main and renderer
- Plugin interaction with external APIs
- File system interaction paths
- Event system flow

**[User Interface Layer]**

- Svelte Components
- Clipboard Monitor
- Queue Display
- Settings Interface

- v
**[Preload Bridge]**

- IPC Communications
- Security Contexts

- v
**[Main Process]**

- Plugin System
- E-hentai Plugin
- Exhentai Plugin
- Config Manager

- Download Manager
- Queue Handler
- File Writer

- External Services
- API Clients
- Cookie Manager

Key Considerations:

##### Security Flow
- How authentication data is handled
- Secure communication paths
- Trusted and untrusted boundaries

##### Error Handling
- Retry mechanisms
- Error reporting paths
- Validation points

##### State Management
- Configuration storage
- Session management
- Persistent storage points

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph UI["User Interface Layer"]
        direction TB
        SvelteApp["Svelte App"]:::ui
        Components["UI Components"]:::ui
        ClipMon["Clipboard Monitor"]:::ui
        QueueDisp["Queue Display"]:::ui
        Settings["Settings Interface"]:::ui
    end

    subgraph Bridge["Preload Bridge Layer"]
        direction TB
        IPC["IPC Communications"]:::bridge
        SecContext["Security Context"]:::bridge
    end

    subgraph Main["Main Process Layer"]
        direction TB
        MainProc["Main Process"]:::core

        subgraph PluginSys["Plugin System"]
            direction TB
            Config["Configuration Manager"]:::plugin
            Events["Event System"]:::plugin
            
            subgraph Sources["Source Plugins"]
                direction TB
                EH["E-hentai Plugin"]:::plugin
                EX["Exhentai Plugin"]:::plugin
            end

            subgraph Lib["Library Components"]
                direction TB
                Parser["Manga Parser"]:::lib
                ImgProc["Image Processor"]:::lib
                ReqHandler["HTTP Request Handler"]:::lib
            end
        end

        subgraph DL["Download System"]
            direction TB
            Queue["Queue Handler"]:::download
            FileOps["File Operations"]:::download
        end

        subgraph Auth["Authentication"]
            direction TB
            Login["Login Handler"]:::auth
            Session["Session Manager"]:::auth
        end
    end

    %% Connections
    SvelteApp --> Components
    Components --> ClipMon
    Components --> QueueDisp
    Components --> Settings

    UI --> Bridge
    Bridge --> MainProc
    MainProc --> PluginSys
    MainProc --> DL
    
    Sources --> Lib
    Sources --> Auth
    Auth --> ReqHandler
    
    EH --> Parser
    EX --> Parser
    Parser --> ImgProc
    ImgProc --> Queue
    Queue --> FileOps

    %% Styles
    classDef ui fill:#9370DB
    classDef bridge fill:#4169E1
    classDef core fill:#1E90FF
    classDef plugin fill:#3CB371
    classDef lib fill:#20B2AA
    classDef download fill:#FFA500
    classDef auth fill:#DC143C

    %% Click Events
    click MainProc "https://github.com/dvgamerr-app/hentai-downloader/blob/main/src/main/index.js"
    click PluginSys "https://github.com/dvgamerr-app/hentai-downloader/tree/main/src/main/plugins/"
    click Config "https://github.com/dvgamerr-app/hentai-downloader/blob/main/src/main/plugins/config.js"
    click EH "https://github.com/dvgamerr-app/hentai-downloader/blob/main/src/main/plugins/ehentai.js"
    click EX "https://github.com/dvgamerr-app/hentai-downloader/tree/main/src/main/plugins/ex/"
    click Events "https://github.com/dvgamerr-app/hentai-downloader/blob/main/src/main/plugins/events.js"
    click Parser "https://github.com/dvgamerr-app/hentai-downloader/blob/main/src/main/plugins/lib/parse-manga.js"
    click ImgProc "https://github.com/dvgamerr-app/hentai-downloader/blob/main/src/main/plugins/lib/parse-image.js"
    click ReqHandler "https://github.com/dvgamerr-app/hentai-downloader/blob/main/src/main/plugins/lib/request.js"
    click SvelteApp "https://github.com/dvgamerr-app/hentai-downloader/blob/main/src/renderer/src/App.svelte"
    click Components "https://github.com/dvgamerr-app/hentai-downloader/tree/main/src/renderer/src/components/"
    click IPC "https://github.com/dvgamerr-app/hentai-downloader/blob/main/src/preload/index.js"
    click Login "https://github.com/dvgamerr-app/hentai-downloader/blob/main/src/main/plugins/ex/login.js"
    click Session "https://github.com/dvgamerr-app/hentai-downloader/blob/main/src/main/plugins/ex/gallery.js"
```
