Core architectural principles
Modular portal system
ReUCM is built around a portal-based architecture where each book source (like Author.Today) is implemented as an independent, pluggable module. This design allows:- Easy addition of new book sources without modifying core code
- Clear separation between platform-specific logic and shared functionality
- Independent development and testing of portal modules
Layer separation
The architecture follows a clear layered approach:Key components
Core models (re_ucm_core/)
The core library defines fundamental interfaces and models: Portal interface -re_ucm_core/lib/models/portal/portal.dart:3
re_ucm_core/lib/models/portal/portal_service.dart:3
re_ucm_core/lib/models/book/book.dart:3
Contains metadata like title, authors, annotation, genres, series, chapters, and portal reference.
Chapter model - re_ucm_core/lib/models/book/chapter.dart:3
Simple structure containing chapter title and HTML content.
Shared services (re_ucm_lib/)
Provides common services used across the application: PortalFactory -re_ucm_lib/lib/portals/portal_factory.dart:3
- Registry for all portal implementations
- Lookup by code or URL
- Initialized at app startup in
re_ucm_app/lib/core/di.dart:32
re_ucm_lib/lib/portals/portal_session.cg.dart:7
- MobX-powered reactive state management for portal instances
- Manages settings, authorization state, and data fetching
- Handles settings persistence
re_ucm_lib/lib/recent_books/recent_books_service.cg.dart:10
- Tracks recently accessed books
- Observable list for reactive UI updates
- Persisted to local storage using Sembast
re_ucm_lib/lib/settings/settings_service.dart:7
- Manages app-wide settings
- Download path templates
- Portal sessions and credentials
- Persisted using Sembast database
Main application (re_ucm_app/)
The Flutter application layer implementing the user interface and application logic. Dependency injection -re_ucm_app/lib/core/di.dart:8
Uses Flutter’s InheritedWidget pattern to provide services throughout the widget tree:
re_ucm_app/lib/features/
Each feature is self-contained:
book/- Book viewing and downloadingbrowser/- In-app web browser for authenticationconverters/- Format conversion (HTML to FB2)home/- Main screen with portal list and recent booksota/- Over-the-air updatesportals/- Portal configuration UIsettings/- App settings managementshare_receiver/- Handle shared URLs from other apps
Data flow
Book download flow
- URL parsing - User shares a book URL to the app
- Portal identification -
PortalFactory.fromUrl()identifies the correct portal - ID extraction - Portal’s
getIdFromUrl()extracts book ID - Metadata fetch -
PortalSession.getBook(id)retrieves book metadata - User interaction - Book details displayed, user initiates download
- Content fetch -
PortalSession.getText(id)fetches all chapters - Conversion -
convertToFB2()converts HTML chapters to FB2 format (runs in isolate) - Image processing - Downloads and embeds images in base64
- Export - User can share or save the generated FB2 file
re_ucm_app/lib/features/book/presentation/book_page_controller.cg.dart:24 for the controller implementation.
Authentication flow
- Portal settings - User navigates to portal settings
- Settings schema - Portal generates dynamic UI via
buildSettingsSchema() - Web auth - Opens in-app browser to portal login page
- Cookie extraction - Captures authentication cookie on success
- Token exchange - Portal service exchanges cookie for API token
- Persistence - Settings service saves credentials to local database
- Session update - PortalSession updates with new authenticated state
re_ucm_author_today/lib/author_today_service.dart:101 for the Author.Today implementation.
State management
ReUCM uses MobX for reactive state management:- PortalSession - Observable settings and authorization state
- RecentBooksService - Observable list of recent books
- BookPageController - Observable download progress and book data
- User authenticates with a portal
- Book metadata is fetched
- Download progress changes
- Recent books list is modified
File conversion
The conversion system (re_ucm_app/lib/features/converters/fb2/converter.dart:18) uses Isolates for heavy processing:
- Spawn isolate to avoid blocking UI
- Parse HTML chapters to FB2 XML elements
- Download images in parallel with progress tracking
- Build complete FB2 XML document
- Encode to UTF-8 bytes
- Send result back to main isolate
SendPort to update the UI in real-time.
Platform-specific considerations
Cross-platform support
ReUCM targets:- Android
- iOS
- Windows (requires WebView2)
- macOS
- Linux
Storage strategy
- Sembast - NoSQL database for settings and recent books
- path_provider - Platform-appropriate storage locations
- File system - Direct file operations for book exports
Permissions
- External storage (Android) -
re_ucm_app/lib/features/book/presentation/book_page_controller.cg.dart:141 - Share capability - Platform-specific implementations via
share_plus
Extension points
The architecture provides clear extension points:Adding new portals
- Create new package (e.g.,
re_ucm_new_portal/) - Implement
Portal<T>interface - Implement
PortalService<T>for business logic - Define
T extends PortalSettingsfor portal-specific settings - Register in
re_ucm_app/lib/core/di.dart:32
Adding new export formats
Add converter inre_ucm_app/lib/features/converters/ following the FB2 converter pattern.
Adding new features
Create feature folder inre_ucm_app/lib/features/ with presentation, domain, and data layers.