How luoyacheng/legado-e works
1. Overall shape
- This is an Android reading app, built mainly in Kotlin with a large single app module plus three supporting modules: modules/book for EPUB/UMD parsing, modules/rhino for JavaScript rule execution, and modules/web for the companion browser-based editor/admin UI.
- The app is not “just UI”: a lot of product logic lives in reusable engine layers under help/, model/, lib/, and web/.
2. Primary user-facing surfaces
- The main Android shell is MainActivity with tabbed fragments for bookshelf, explore, RSS, and personal/config areas.
- From there, the app branches into specialized experiences: book search, reading, manga reader, audio read-aloud, video player, source editing/debugging, file management, and settings.
3. Core domain model
- The persistent domain is centered on books, chapters, book sources, RSS sources, replace rules, dictionaries, HTTP TTS configs, bookmarks, read records, cache, and groups.
- Rule objects are first-class: book source rules, RSS rules, content rules, search rules, TOC rules, and replace rules are stored as entities and moved through the UI, engines, and editor tools.
4. Local data layer
- AppDatabase is a Room database with many DAOs and a long migration history, so schema evolution is a significant architectural concern.
- The database holds both content metadata and operational state such as bookmarks, history, caches, cookies, search keywords, server configs, and source definitions.
- JSON schema snapshots under app/schemas indicate Room auto-migration/verification is part of the build discipline.
5. Rule-driven content pipeline
- The app’s most important boundary is between “user-defined rule source” and “normalized app model.”
- Fetching a book/article goes through rule analyzers (model/analyzeRule) that can interpret HTML, XPath, regex, JSoup, and JSONPath rules.
- The output is converted into app-specific models like book lists, chapter lists, content pages, and RSS articles for display and storage.
6. Script/runtime layer
- modules/rhino embeds a Rhino JavaScript engine so user rules and source scripts can run inside the app safely.
- This layer is used by source/login/debug workflows and by various rule-extension helpers in help/js* and model/SharedJsScope.
- That makes scripting an architecture boundary, not just a utility: the app executes user-authored logic to adapt to arbitrary websites.
7. Networking and fetch stack
- The app uses an HTTP abstraction centered on OkHttp, with optional Cronet integration for alternative networking behavior.
- Cookie management, SSL handling, decompression, interceptors, and response wrappers live in help/http and related helpers.
- WebView-backed interactions are also used for login, source verification, and in-app browsing; this is important because some content flows require browser-like execution rather than plain HTTP.
8. Reading engines
- Text reading is implemented as a dedicated rendering pipeline under ui/book/read/page, with page factories, layout providers, and multiple page delegates for scroll, slide, simulation, cover, and no-animation modes.
- Manga has a separate rendering path under ui/book/manga, with its own recycler/layout logic and image transformations.
- Audio read-aloud and video playback are separate subsystems, each with dedicated services, activities, and player helpers.
9. Local file ingestion
- Local book support is a distinct pipeline: TXT, EPUB, MOBI, PDF, and UMD parsing are handled through model/localBook plus the modules/book library.
- Import flows scan storage, normalize files into books/chapters, and then hand them off to the bookshelf and reader layers.
- This is a classic ingest → parse → persist → read flow, separate from online source-based reading.
10. Remote and sync-like capabilities
- The app supports remote books and WebDAV-based storage/access through model/remote and lib/webdav.
- Backup/restore, old-data import, and direct-link upload are adjacent but separate storage workflows.
- These features connect local state to external file/network services without collapsing into the core reading pipeline.
11. Embedded web server and web editors
- app/web contains a local HTTP/WebSocket server plus socket endpoints for source debugging and book search.
- modules/web is a separate Vue-based front-end used for bookshelf/source editing views, implying the Android app can serve or synchronize with a browser UI.
- This creates a clear split: Android native UI for end-user reading, web UI for power-user editing/debugging.
12. Background services and receivers
- Services handle long-running work such as downloads, caching, source checks, exporting, HTTP/TTS read-aloud, audio playback, video playback, and web serving.
- Broadcast receivers react to media buttons, connectivity changes, time/battery events, and shared-intent style entry points.
- The app therefore has both foreground interactive flows and background orchestration around content, media, and network state.
13. Configuration and customization
- User customization is extensive: themes, reading styles, source configs, backup configs, cover rules, TTS configs, and welcome/other preferences are all first-class.
- Many dialog and preference helper classes in lib/prefs, lib/theme, and ui/*/config show that settings are part of the product’s core behavior, not a minor side screen.
14. Non-UI infrastructure
- The repo includes many reusable helpers for caching, coroutines, lifecycle, permissions, crypto, image loading, file utilities, markdown/web rendering, and custom widgets.
- Several third-party libraries materially shape the architecture: Room, OkHttp, Glide, ExoPlayer/GSY video tooling, NanoHTTPD, WebView, and epublib.
- CI/CD under .github/workflows and release scripts support app release, testing, and a web build/deploy path, but the runtime architecture remains primarily Android-centric with embedded scripting and local server capabilities.
Main entry points: analyzeRule Rule pipeline · MainActivity.kt Main shell · AppDatabase.kt App database · rule Rule model
Components 20
Android app
Native Android application shell, UI, data, services, and embedded web/server layers.
- Main shell · App launch, bottom tabs, and top-level navigation across bookshelf, explore, RSS, and personal areas.
app/src/main/java/io/legado/app/ui/main/MainActivity.kt - Bookshelf · Bookshelf home and book collection presentation, including alternate shelf styles.
app/src/main/java/io/legado/app/ui/main/bookshelf - Explore and RSS · Discovery and feed surfaces for exploring sources and reading RSS content.
app/src/main/java/io/legado/app/ui/main/explore - Reader stack · Text reading pipeline with page layout, chapter flow, and reading controls.
app/src/main/java/io/legado/app/ui/book/read - Manga reader · Separate image-based reading path with custom recycler, transforms, and chapter handling.
app/src/main/java/io/legado/app/ui/book/manga - Audio and video · Read-aloud, audio playback, and video player subsystems with dedicated activities and services.
app/src/main/java/io/legado/app/ui/book/audio - Source tools · Editing, debugging, login, and verification workflows for book and RSS rules.
app/src/main/java/io/legado/app/ui/book/source - Rule model · First-class rule entities for book sources, RSS sources, content, search, TOC, replace, dict, and TTS configs.
app/src/main/java/io/legado/app/data/entities/rule - Rule pipeline · Normalizes user-defined rules into app models via HTML, XPath, regex, JSoup, and JSONPath analyzers.
app/src/main/java/io/legado/app/model/analyzeRule - App database · Room database, DAOs, entities, and migrations for books, sources, bookmarks, history, caches, and settings state.
app/src/main/java/io/legado/app/data/AppDatabase.kt - HTTP stack · OkHttp-centered fetch layer with cookie, SSL, decompression, interceptor, and Cronet support.
app/src/main/java/io/legado/app/help/http - WebView layer · WebView-backed login, browsing, and scripted browser-like interactions used where plain HTTP is insufficient.
app/src/main/java/io/legado/app/help/webView - Embedded web · Local HTTP/WebSocket server exposing search and source-debug endpoints and serving the companion UI.
app/src/main/java/io/legado/app/web - Import and sync · Local book ingest, remote/WebDAV books, backup/restore, and data migration workflows.
app/src/main/java/io/legado/app/model/localBook - Background services · Long-running services for downloads, caching, source checks, export, read-aloud, playback, and web serving.
app/src/main/java/io/legado/app/service - Config system · Themes, reading style, source settings, backup, cover rules, TTS, and welcome/configuration screens.
app/src/main/java/io/legado/app/ui/config - Shared helpers · Cross-cutting helpers for caching, coroutines, crypto, permissions, theming, image loading, file utilities, and custom widgets.
app/src/main/java/io/legado/app/help
Supporting modules
Reusable EPUB/UMD parsing, JavaScript runtime, and browser editor module.
- Book module · Standalone EPUB and UMD parsing/writing library used for local book ingestion and document handling.
modules/book/src/main/java/me/ag2s/epublib - Rhino module · Embedded Rhino JavaScript runtime used to execute user-authored source rules and helpers safely.
modules/rhino/src/main/java/com/script - Web module · Browser-based bookshelf and source editor/admin UI synchronized with the Android app.
modules/web/src
Connections 24
- Main shell → Bookshelf: opens · Main navigation enters the bookshelf surface.
- Main shell → Explore and RSS: routes to · Main navigation switches to exploration and RSS areas.
- Main shell → Reader stack: launches · From collections or search results into the text reader.
- Main shell → Manga reader: launches · Opens manga reading when the content type requires it.
- Main shell → Audio and video: launches · Starts audio read-aloud or video playback experiences.
- Bookshelf → App database: persists · Bookshelf state and book metadata are read from Room.
- Explore and RSS → Rule pipeline: queries · Discovery and feed screens resolve source rules into content.
- Source tools → Rule model: edits · Source editors manipulate stored rule entities.
- Source tools → Rule pipeline: debugs · Debug and login flows execute rules against live targets.
- Rule model → App database: stored in · Rule entities and operational state live in the database.
- Rule pipeline → HTTP stack: fetches via · Analyzers rely on the network stack for page retrieval.
- Rule pipeline → WebView layer: falls back to · Browser-based execution supports login and verification flows.
- Rule pipeline → Rhino module: executes in · User-authored JavaScript rules run in the embedded Rhino runtime.
- Rule pipeline → Shared helpers: uses · Parsing and rule helpers are shared across the app.
- Import and sync → Book module: parses with · Local book import relies on EPUB/UMD library code.
- Import and sync → App database: persists · Imported books, remote book state, and backup data are stored locally.
- Reader stack → App database: reads · Reader state, bookmarks, history, and chapter data come from Room.
- Audio and video → Background services: runs through · Playback and read-aloud depend on long-running services.
- Embedded web → Web module: serves · The embedded server exposes the companion browser UI.
- Embedded web → Rule pipeline: exposes · WebSocket endpoints drive source and search debugging.
- Background services → HTTP stack: fetches via · Background work uses the same HTTP stack for downloads and checks.
- Config system → App database: stores · User preferences and app configuration are persisted locally.
- Config system → Shared helpers: uses · Theme, dialog, and preference infrastructure is shared.
- Web module → Rule model: edits · Browser UI supports source and bookshelf editing flows.