# kayanouriko/e-hentaiviewer architecture

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

- Interactive diagram: https://gitdiagram.com/kayanouriko/e-hentaiviewer
- Repository: https://github.com/kayanouriko/e-hentaiviewer

## Overview

##### Project type and purpose
- This is an iOS native client (“EHenTaiViewer”) for the e-hentai/exhentai web service.
- It uses Objective-C, Cocoa Touch, CoreData for persistence, and several third-party libraries via CocoaPods.
- It provides features like browsing galleries, viewing images, searching, tagging, commenting, bookmarking, and settings management.

##### File structure
- Top-level Xcode project and workspace files (`EHenTaiViewer.xcodeproj`, `EHenTaiViewer.xcworkspace`).
- An “EHenTaiViewer” directory containing:
- App entry (`main.m`, `AppDelegate.*`)
- Storyboards/XIBs & assets (`Base.lproj`, `Assets.xcassets`, various `.xib`)
- View controllers and custom views (`QJ*.h/.m`, `QJ*.xib`)
- Data models (`EhCoreData.xcdatamodeld`, `Gallery+CoreData*`, `Tag+CoreData*`)
- Networking/parsing (`QJNetworkTool`, `QJHenTaiParser`, `XPathQuery`, `TFHpple`)
- Managers (`QJMangaManager`, `QJBrowerCollectManager`, `QJPasteManager`, `QJProtectTool`)
- Utilities (extensions, `QJTool`, `Reachability`, `UIDevice+QJDevice`)
- Pods directory with frameworks: MagicalRecord (CoreData helpers), Masonry (Auto Layout DSL), YYCache/YYImage/YYWebImage (caching & image loading).

##### README for additional insights
- Confirms it’s a full-featured e-hentai/exhentai reader: login, gallery details, image viewing, bookmarks, comments, search, tags.
- Mentions CoreData (“EhCoreData.xcdatamodeld”), caching to improve performance, network parsing of HTML.

a. Main components
1. UI Layer
– Storyboards & XIBs
– View Controllers (Home, Gallery Detail, Image Viewer, Search, Comments, Settings, etc.)
– Custom Views / Cells (collection view cells, comment cells, search bars)
2. Domain / Business Logic
– Controllers & Managers (QJMangaManager, QJBrowerCollectManager, QJProtectTool, QJPasteManager, QJNetworkTool)
– Parsers (QJHenTaiParser, TFHpple, XPathQuery)
– Models (QJGalleryItem, QJMangaImageModel, QJTagModel)
3. Data Layer
– CoreData stack (EhCoreData.xcdatamodeld + MagicalRecord)
– On-disk & memory cache (YYCache)
4. Third-Party Frameworks
– Networking: Reachability
– Layout: Masonry
– Image: YYWebImage, YYImage
– Persistence helper: MagicalRecord
5. External Services
– HTTP(s) requests to e-hentai/exhentai web API

b. Relationships and interactions
- UI Layer → Domain Logic: user taps in a view controller → calls a Manager (e.g., QJMangaManager.fetchGalleryList).
- Domain Logic → Networking: Manager uses QJNetworkTool (and Reachability) to issue HTTP GET/POST.
- Networking → Parser: raw HTML/JSON response passed to QJHenTaiParser / TFHpple / XPathQuery.
- Parser → Domain Model: parser produces QJGalleryItem, QJCommentItem, etc.
- Domain Model → Data Layer: models saved/fetched via MagicalRecord into CoreData; image URLs cached in YYCache.
- Data Layer → UI Layer: view controllers fetch from CoreData or YYCache to display galleries/thumbnails.
- Image Loader: UI → YYWebImage for asynchronous image download & caching.

c. Architectural patterns & design principles
- MVC: View Controllers mediate between Views and Models/Managers.
- Singleton & Shared Instances: QJGlobalInfo, QJNetworkTool, QJMangaManager.
- Delegation & DataSource: UITableView/UICollectionView patterns.
- Separation of Concerns: Networking, Parsing, Data Persistence, UI rendering.

d. Key technologies & libraries
- Objective-C / Cocoa Touch
- CoreData via MagicalRecord
- CocoaPods packages: Masonry, YYWebImage/YYImage/YYCache, TFHpple, Reachability
- HTML/XML parsing: TFHpple / XPathQuery
- Layout & UI: Storyboards/XIBs, custom UIViews, Masonry

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% UI Layer
    subgraph "UI Layer" 
        direction TB
        MainStoryboard["Main.storyboard"]:::ui
        LaunchStoryboard["LaunchScreen.storyboard"]:::ui
        Assets["Assets.xcassets"]:::ui

        QJHomeVC["QJHomeViewController"]:::ui
        QJAllCommentCtrl["QJAllCommentController"]:::ui
        QJLoginVC["QJLoginViewController"]:::ui
        QJImageCell["QJImageCollectionViewCell"]:::ui
        QJTabBarCtrl["QJTabBarController"]:::ui
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        direction TB
        QJMangaMgr["QJMangaManager"]:::logic
        QJNetworkTool["QJNetworkTool"]:::logic
        QJBrowerCollectMgr["QJBrowerCollectManager"]:::logic
        QJPasteMgr["QJPasteManager"]:::logic
        QJProtectTool["QJProtectTool"]:::logic

        QJHenTaiParser["QJHenTaiParser"]:::logic
        QJMangaImageParser["QJMangaImageParser"]:::logic
        TFHpple["TFHpple"]:::logic
        XPathQuery["XPathQuery"]:::logic

        QJGalleryItem["QJGalleryItem"]:::logic
        QJMangaImageModel["QJMangaImageModel"]:::logic
        QJTagModel["QJTagModel"]:::logic
        GalleryCoreData["Gallery+CoreData"]:::logic
        TagCoreData["Tag+CoreData"]:::logic
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        CoreDataModel["EhCoreData Model"]:::data
        MagicalRecord["MagicalRecord"]:::data
        YYCache["YYCache"]:::data
        YYWebImage["YYWebImage / YYImage"]:::data
    end

    %% Utilities & Support
    subgraph "Utilities & Support"
        direction TB
        Reachability["Reachability"]:::util
        NJKWebProgress["NJKWebViewProgress"]:::util
        Masonry["Masonry"]:::util
        UIViewLayer["UIView+Layer"]:::util
        UITableCellExt["UITableViewCell+QJAddition"]:::util
    end

    %% App Entry
    subgraph "App Entry & Config"
        direction TB
        AppDelegate["AppDelegate"]:::util
        MainEntry["main.m"]:::util
        QJGlobalInfo["QJGlobalInfo"]:::util
    end

    %% External Services
    ExternalAPI["e-hentai/exhentai API"]:::external

    %% Relationships
    QJHomeVC -->|uses| QJMangaMgr
    QJAllCommentCtrl -->|uses| QJBrowerCollectMgr
    QJLoginVC -->|calls| QJPasteMgr
    QJHomeVC -->|navigates| QJTabBarCtrl
    QJHomeVC -->|loads images via| QJImageCell

    QJMangaMgr -->|requests| QJNetworkTool
    QJBrowerCollectMgr -->|requests| QJNetworkTool
    QJPasteMgr -->|requests| QJNetworkTool
    QJProtectTool -->|secures| QJNetworkTool

    QJNetworkTool -->|fetches| ExternalAPI

    QJNetworkTool -->|parses| QJHenTaiParser
    QJHenTaiParser -->|uses| TFHpple
    QJHenTaiParser -->|uses| XPathQuery
    QJMangaImageParser -->|uses| TFHpple

    QJHenTaiParser -->|produces| QJGalleryItem
    QJMangaImageParser -->|produces| QJMangaImageModel
    QJHenTaiParser -->|produces| QJTagModel

    QJGalleryItem -->|saved in| CoreDataModel
    QJTagModel -->|saved in| CoreDataModel
    CoreDataModel -->|wrapped by| MagicalRecord
    QJMangaImageModel -->|cached in| YYCache

    QJImageCell -->|loads via| YYWebImage
    YYWebImage -->|downloads| ExternalAPI
    YYWebImage -->|caches in| YYCache

    QJHomeVC -->|fetches| CoreDataModel
    QJAllCommentCtrl -->|fetches| CoreDataModel

    AppDelegate -->|initializes| QJGlobalInfo
    AppDelegate -->|launches| QJTabBarCtrl

    %% Click Events
    click MainStoryboard "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/Base.lproj/Main.storyboard"
    click LaunchStoryboard "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/Base.lproj/LaunchScreen.storyboard"
    click Assets "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/Assets.xcassets"
    click QJHomeVC "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/QJHomeViewController.h"
    click QJAllCommentCtrl "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/QJAllCommentController.h"
    click QJLoginVC "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/QJLoginViewController.h"
    click QJImageCell "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/QJImageCollectionViewCell.h"
    click QJTabBarCtrl "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/QJTabBarController.h"
    click QJMangaMgr "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/QJMangaManager.h"
    click QJNetworkTool "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/QJNetworkTool.h"
    click QJBrowerCollectMgr "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/QJBrowerCollectManager.h"
    click QJPasteMgr "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/QJPasteManager.h"
    click QJProtectTool "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/QJProtectTool.h"
    click QJHenTaiParser "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/QJHenTaiParser.h"
    click QJMangaImageParser "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/QJMangaImageParser.h"
    click TFHpple "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/TFHpple.h"
    click XPathQuery "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/XPathQuery.h"
    click QJGalleryItem "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/QJGalleryItem.h"
    click QJMangaImageModel "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/QJMangaImageModel.h"
    click QJTagModel "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/QJTagModel.h"
    click GalleryCoreData "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/Gallery+CoreDataClass.h"
    click TagCoreData "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/Tag+CoreDataClass.h"
    click CoreDataModel "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EhCoreData.xcdatamodeld/EhCoreData.xcdatamodel"
    click MagicalRecord "https://github.com/kayanouriko/e-hentaiviewer/tree/master/Pods/MagicalRecord"
    click YYCache "https://github.com/kayanouriko/e-hentaiviewer/tree/master/Pods/YYCache"
    click YYWebImage "https://github.com/kayanouriko/e-hentaiviewer/tree/master/Pods/YYWebImage"
    click Reachability "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/Reachability.h"
    click NJKWebProgress "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/NJKWebViewProgress.h"
    click Masonry "https://github.com/kayanouriko/e-hentaiviewer/tree/master/Pods/Masonry"
    click UIViewLayer "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/UIView+Layer.h"
    click UITableCellExt "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/UITableViewCell+QJAddition.h"
    click AppDelegate "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/AppDelegate.h"
    click MainEntry "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/main.m"
    click QJGlobalInfo "https://github.com/kayanouriko/e-hentaiviewer/blob/master/EHenTaiViewer/QJGlobalInfo.h"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef logic fill:#90EE90,stroke:#333,stroke-width:1px
    classDef data fill:#FFA500,stroke:#333,stroke-width:1px
    classDef external fill:#FF6347,stroke:#333,stroke-width:1px
    classDef util fill:#D3D3D3,stroke:#333,stroke-width:1px
```
