Core concepts
What is a portal?
A portal represents a book source (website or service) from which books can be downloaded. Each portal:- Has a unique identifier (code)
- Implements standardized interfaces
- Manages its own authentication
- Handles book metadata and content fetching
- Provides dynamic configuration UI
Portal interface
Defined inre_ucm_core/lib/models/portal/portal.dart:3:
T represents portal-specific settings (authentication, preferences, etc.).
Portal service interface
Defined inre_ucm_core/lib/models/portal/portal_service.dart:3:
Implementation example: Author.Today
Portal implementation
Location:re_ucm_author_today/lib/re_ucm_author_today.dart:6
Service implementation
Location:re_ucm_author_today/lib/author_today_service.dart:11
The service handles all business logic:
Settings management
Dynamic UI schema
The portal generates its own settings UI dynamically (author_today_service.dart:28):
- Authorized: Show logout button with user ID
- Not authorized: Show web login and token login options
URL parsing
Extract book ID from various URL formats (author_today_service.dart:149):
https://author.today/work/12345https://author.today/reader/12345
Book metadata fetching
Location:author_today_service.dart:161
Book model.
Content fetching
Location:author_today_service.dart:171
Chapter objects.
Portal registration
Portals must be registered at app startup inre_ucm_app/lib/core/di.dart:32:
PortalFactory
Location:re_ucm_lib/lib/portals/portal_factory.dart:3
Provides central registry and lookup:
Portal session
Location:re_ucm_lib/lib/portals/portal_session.cg.dart:7
Wraps a portal with reactive state management:
- Observable settings - UI automatically reacts to auth state changes
- Persistence callback - Automatically saves settings to storage
- Settings change handler - Portal can trigger updates (e.g., token refresh)
Session lifecycle
Created bySettingsService on app init (re_ucm_lib/lib/settings/settings_service.dart:37):
Portal settings system
Settings base class
Location:re_ucm_core/lib/models/portal/portal_settings.dart:3
Dynamic UI schema
Location:re_ucm_core/lib/models/portal/portal_settings_schema.dart:3
Defines UI elements that portals can use:
PortalSettingSectionTitle - Section header
Authentication patterns
Web-based authentication
Used by Author.Today (author_today_service.dart:43):
- Open browser -
PortalSettingWebAuthButtonopens in-app browser to login page - User authenticates - User logs in via portal’s website
- Cookie capture - App monitors navigation and captures cookie on success URL
- Token exchange -
onCookieObtainedcallback exchanges cookie for API token - Settings update - New token saved to settings and persisted
Token-based authentication
Alternative method for Author.Today (author_today_service.dart:57):
- Enable token input - User clicks “Вход с помощью токена”
- Show text field -
PortalSettingTextFieldappears - Submit token - User pastes token and submits
- Validate -
onSubmitcallback validates token with API - Settings update - Valid token saved to settings
Token refresh
Automatic token refresh (author_today_service.dart:129):
Creating a new portal
Step 1: Create package structure
Step 2: Implement Portal interface
Step 3: Implement PortalService
Step 4: Define settings model
Step 5: Register portal
Add tore_ucm_app/lib/core/di.dart:32:
Best practices
Error handling
- Throw
ArgumentErrorfor invalid URLs ingetIdFromUrl() - Throw descriptive exceptions from service methods
- Handle network errors gracefully
- Provide user-friendly error messages
Settings persistence
- Only persist essential data in
toMap() - Use temporary flags for UI state (not persisted)
- Call
onSettingsChangedwhen credentials are refreshed - Validate settings before saving
Authentication
- Support multiple auth methods when possible
- Implement token refresh for long-lived sessions
- Clear sensitive data on logout
- Use secure storage for tokens (handled by SettingsService)
API integration
- Use Retrofit for type-safe API clients
- Handle rate limiting
- Support pagination for large book lists
- Cache metadata when appropriate
Testing
- Unit test URL parsing logic
- Mock API responses for service tests
- Test authentication flows
- Verify settings persistence
Portal capabilities
The portal system supports:- Multiple auth methods - Web OAuth, tokens, API keys
- Dynamic settings UI - Portals control their own configuration interface
- Reactive state - UI updates automatically with MobX observers
- Persistent sessions - Settings saved and restored across app launches
- Independent development - Portals are isolated packages
- Extensible schema - Add new UI components without breaking existing portals