This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
cargo run # Run in development mode
cargo build --release # Build for release
cargo test # Run tests
cargo test --lib <test_name> # Run a specific testcd web
npm install # Install dependencies
npm run serve # Development server
npm run build # Production build
npm run lint # Lint codeConfiguration is loaded from environment variables. Default values are defined in src/app/config.rs. Key settings:
SERVER_HOST/SERVER_PORT- Server binding (default:0.0.0.0:8080)DATABASE_URL- SQLite path (default:sqlite:storage/reader.db?mode=rwc)WEB_ROOT- Static web files directory (default:../reader/web)STORAGE_DIR/ASSETS_DIR- Storage pathsLOG_LEVEL- Logging verbosity (default:info)REQUEST_TIMEOUT_SECS- HTTP request timeout (default: 15)
Environment variable separator is __ (double underscore).
This is a Rust implementation of "阅读3.0" (Reader 3.0) - a book reading API server. It provides book source management, search, chapter retrieval, and content parsing.
-
src/api/- HTTP handlers and routing (axum)router.rs- Route definitions for all/reader3/*endpointshandlers/- Request handlers by domain (book, bookmark, rss, user, etc.)AppState- Shared application state (config, services)
-
src/service/- Business logic layerbook_service.rs- Book search, info, chapters, contentbook_source_service.rs- CRUD for book sources (stored in SQLite)user_service.rs- User management and authentication
-
src/parser/- Content extraction enginerule_engine.rs- Main entry point, auto-detects content typehtml.rs- CSS selector parsing (using scraper crate)jsonpath.rs- JSONPath queries (using jsonpath_lib)js.rs- JavaScript execution (rquickjs) forjs:prefixed rules
-
src/crawler/- HTTP fetchinghttp_client.rs- Configurable reqwest client with compression supportfetcher.rs- Page fetching with URL resolution
-
src/model/- Data structuresbook_source.rs- Book source JSON schema with rule definitionsrule.rs- SearchRule, BookInfoRule, TocRule, ContentRule types
-
src/storage/- Persistencedb/- SQLite via sqlx, withBookSourceRepocache/- File-based chapter content cache (MD5 key)fs/- Filesystem operations for storage/assets
api/handlers/receives HTTP request- Handler calls
service/layer - Service fetches remote content via
crawler/http_client.rs - Content is parsed using
parser/rule_engine.rswith rules fromBookSource - Results returned as JSON
Book sources define parsing rules in JSON. The RuleEngine auto-detects parsing mode:
- CSS selectors - Default for HTML (
.class,#id,tag) - JSONPath - Auto-detected for JSON content (
$.data.list) - XPath - Lines starting with
/or./ - JavaScript - Rules prefixed with
js:or@js: - Regex - Rules starting with
:
Rule prefixes can be explicit: @css:, @json:, @xpath:, @regex:.
Book sources are JSON objects containing:
bookSourceUrl/bookSourceName- Source identitysearchUrl/exploreUrl- Search/discovery URLs with${key}placeholdersruleSearch/ruleBookInfo/ruleToc/ruleContent- Parsing rules for each stage- Each rule has fields like
bookList,name,author,bookUrl, etc.
The web/ directory contains a Vue 2 frontend (阅读3.0 web client). It connects to the Rust backend API. Build output goes to web/dist/, which the backend serves as static files.