How dstark5/openlib works
Project type and purpose
• This is a cross-platform mobile/desktop/web client application built with Flutter.
• Its purpose is to let users search, download, and read books from Anna’s Archive (a “shadow library”) by scraping web responses, parsing them, and presenting them in an in-app reader.
File structure
• Top-level directories for each supported platform: android/, ios/, linux/, macos/, windows/, web/
• Core Dart code under lib/, subdivided into:
• services/ – networking, parsing, file I/O, database wrappers, share integration
• state/ – global or scoped state management
• ui/ – pages, widgets, theme definitions, built-in EPUB/PDF viewers
• pubspec.yaml declaring Flutter SDK, dependencies
• android/app, ios/Runner, etc. contain native host entry points and configuration
README for additional insights
• No backend server—purely a client that scrapes Anna’s Archive HTML, extracts mirror links, downloads files, and stores them locally.
• Features listed: trending, search/filter/sort, in-app viewer (EPUB/PDF), external reader share.
Main components and how to model them
A. Presentation Layer (Flutter UI)
• Pages (e.g., HomePage, SearchPage, BookInfoPage, MyLibraryPage, SettingsPage)
• Reusable components (Widget library under ui/components)
• In-app viewers (EpubViewer, PdfViewer, WebviewPage)
B. State Management
• A central “State” object or BLoC/Provider mix (lib/state/state.dart)
• Exposes methods/events to fetch data, trigger downloads, update UI
C. Services Layer
• NetworkService:
• annas_archive.dart – sends HTTP GET to Anna’s Archive search/mirror pages & parses HTML
• goodreads.dart & open_library.dart – optional metadata enrichment via public APIs
• DownloadService (download_file.dart) – handles HTTP file downloads, resumable if in roadmap
• DatabaseService (database.dart) – local metadata store (SQLite, Hive, or similar)
• FileService (files.dart) – read/write files to device storage, enforce storage path
• ShareService (share_book.dart) – platform share plugin integration
D. Data Storage & File System
• Local database (e.g., Hive/SQLite) for bookmarks, download state, user settings
• File system directories under app sandbox for downloaded ePub/PDF files
E. External Systems
• Anna’s Archive web servers (shadow library)
• (Optional) Goodreads / Open Library public APIs
• Native OS file viewers (when user opts to open in external reader)
F. Platform Host & Flutter Engine
• Android (MainActivity.kt), iOS (AppDelegate.swift), Windows, Linux, macOS host code loading Flutter engine
• Plugins auto-registered (generated_plugin_registrant)
Relationships & data flow
• UI invokes State methods to initiate actions (e.g., search, download)
• State dispatches calls to Services
• NetworkService fetches/parses remote HTML or API JSON, returns domain models (Book, MirrorLink, etc.)
• State stores results in DatabaseService and notifies UI to rebuild
• DownloadService writes files via FileService; on completion, State updates UI progress/status
• In-app viewer reads file via FileService and renders it in UI
• ShareService invokes platform APIs to share file or link
• All user preferences go through DatabaseService or Flutter’s SharedPreferences plugin
Architectural patterns & design principles
• Layered/Clean Architecture:
• Separation of concerns between UI, state management, service (data) layer
• Domain models independent of UI
• Single source of truth: the State class represents app state
• Dependency inversion: UI depends on abstracted services rather than concrete HTTP or file code
• Plugin isolation: platform-specific code is confined to android/, ios/, etc., everything else remains Dart