How zekfad/nhentai_dart works
Project type and purpose
• This is a Dart client‐library (“package:nhentai”) that provides a typed wrapper over the undocumented nhentai.net REST API.
• It exposes a high‐level API for fetching “books,” images, tags, comments, users, etc., handling HTTP, JSON parsing, host configuration, proxies, and platform differences (native vs. web).
File structure
• Top‐level:
• pubspec.yaml, build.yaml → package metadata and build configuration
• lib/ → library source, subdivided into:
– before_request_add_cookies.dart, data_model.dart, nhentai.dart (facade API)
– src/api*.dart → API interface, RESTful implementation, exceptions
– src/hosts → host strategies (api_host, image_host, thumbnail_host, selected_hosts)
– src/models → domain models + mapper and hook extensions for JSON serialization
– src/platform → IO / JS / stub proxies
• example/ → sample usage illustrating how to import and call API methods.
• No backend, database, or UI components—this is pure client library.
README
• Describes features, usage, platform caveats (CORS, XHR limitations, proxy unsupported on web), and how to get a random book, search, override user‐agent, cookies, custom HTTP client injection.
Main components to surface
a. Consumer code (example.dart or any Dart/Flutter app)
b. Facade API (class API in nhentai.dart)
c. API core → ApiRestfulImplementation (makes HTTP calls)
d. HTTP client abstraction (package:http.Client or custom Client, or fetch_client on web)
e. Platform layer (IO vs JS implementations, proxy config, cookie helpers)
f. Hosts subsystem (ApiHost, ImageHost, ThumbnailHost, SelectedHosts) – constructs correct URIs for assets
g. Remote nhentai.net REST endpoints
h. JSON responses → Model mappers and hooks → Domain objects (Book, Tag, Image, SearchResult, etc.)
i. Consumer receives typed models and uses host helpers to build image URLs
Relationships and interactions
• Consumer → calls API methods → API forwards to ApiRestfulImplementation
• Implementation → uses HTTP client + host URIs → sends HTTP request to nhentai.net (or mirror)
• Response JSON → passed into mapper layer → instantiated Dart model objects
• Models may invoke hooks for custom parsing (dates, user avatars, encoded images)
• Consumer → inspects models → uses Hosts subsystem to get final image URIs
• All HTTP calls pass through Platform layer for proxy, user agent, cookies adaptation
Architectural patterns and design principles
• Facade pattern: API class hides internal details
• Strategy pattern: multiple Host strategies and Platform implementations selected at runtime
• Separation of concerns: HTTP + parsing + hosts + domain models → independent modules
• Dependency injection: custom http.Client can be plugged in
• Code generation / mapping: mapper classes (.mapper.dart) and hooks for JSON ↔ Dart model conversion
Technologies and frameworks
• Dart language
• package:http or package:fetch_client (web)
• Build runner/code‐generation for mappers (implied by build.yaml)
• Custom JSON mapping library via mapper_container_extension
Final advice
• Every layer: facade, core, adapters, mappers, hosts, external.