This page maps the current owners and dependency boundaries. For user-visible translation behavior, read the pipeline guide ; for state, checkpoints and recovery, read the pipeline contracts .
Core does not import CLI or HTTP frameworks. The orchestrator assembles services and owns routing and lock scopes; it does not call domain functions directly or own thread pools. Agents do not depend on pipeline orchestration or concrete state stores. Shared markup and style policy do not depend on LLMs or a particular writer. BabelDOC remains an external HTTP service, not an AGPL dependency of Core.
Core paths below are relative to packages/core/wenyi_core/ ; app and package paths are relative to the repository root.
Web and Desktop behavior, not project state or infrastructure. Web uses PostgreSQL and Redis/Arq; Desktop owns a SQLite catalog, per-project SQLite stores, and a local runner. Desktop does not read or migrate CLI/Web state. The shared backend does not import platform packages, and the shared UI receives native capabilities rather than importing an app. The Web Docker image installs only Web and shared runtime dependencies; the Desktop sidecar is built in a separate environment without PostgreSQL, Redis, or Arq libraries.
Every app, worker and thread callback retains its own backend context. HTTP routes and scheduler/composition bindings resolve that context; routers/dependencies.py binds HTTP requests to explicit service inputs. Execution, project, job-admission and source-view services do not discover dependencies through ambient context or dynamic DAL forwarding. Admission and compensation are complete port operations with platform-owned transactions.
UI hosts use explicit @wenyi/ui exports and configure platform services before mounting. Shared schema generation is offline and does not start production services. See frontend conventions for imports, routes, loading and cross-host tests, and Web development for schema generation and transport contracts.
Application diagnostics belong to Desktop. Shared components provide optional observation hooks, not a global logging backend. Collection, privacy filtering and native publication are covered in Desktop development ; user instructions live in the Desktop guide .
Domain services persist through Storage and ArtifactStorage , not by opening local SQLite databases or writing file-backed state directly. Artifact keys are run-relative, use / on every platform and support bounded prefix queries. storage/run_store.py owns the file-backed ledger; it does not import pipeline services. File adapters expose explicit members rather than forwarding arbitrary attributes to the ledger.
The Storage properties run_dir , source_dir and reviews_dir remain a compatibility gap for path-based consumers. They are not permission for new domain-level filesystem writes. Prefer identity-based storage operations for new work; changing an existing path consumer requires coordinated adapter and contract-test changes. Do not assume every adapter supports file-specific helpers outside the declared protocol.
The creator of a per-operation Storage instance closes it on success and failure. Read routes use explicit close scopes; runners register cleanup immediately after each resource acquisition, including failures while starting telemetry.
Cross-process file locks
Local stores serialize workflow-critical sections with cross-process advisory file locks ( packages/core/wenyi_core/storage/locks.py ). Two interchangeable backends satisfy one contract ( packages/core/tests/test_locks_contract.py ): the optional wenyi-locks native library loaded through ctypes and a pure-Python fallback. The backend is probed once per process:
WENYI_LOCKS_BACKEND selects auto (default), rust or python . auto and rust prefer the native library; python always uses the fallback. Unknown values raise ValueError .
WENYI_LOCKS_LIB names an explicit shared library ( wenyi_locks.dll , libwenyi_locks.dylib or libwenyi_locks.so ) and is tried first; if it fails to load, the override is ignored with an error log and the continues. Without it the loader probes the PyInstaller bundle directory, $CARGO_TARGET_DIR/{release,debug} and the repository-root target/{release,debug} — native crates the root Cargo workspace, so a checkout build is found without an override.
WENYI_LOCKS_MODE decides what a failed native load means: warn (default) logs one warning naming the tried paths and keeps the Python fallback, error fails lock acquisition with those reasons, and silent keeps the fallback without the warning. Unknown values raise ValueError .
Build the library with cargo build -p wenyi-locks (or --release ); how release packaging bundles it is described in Desktop releases .
Saved settings reconstruction
Reconstruction is separate from book-state or ledger migration. It runs when CLI configuration is loaded and when each Web repository or Desktop catalog starts. The pure reconstruction functions preserve valid supplied fields, discard invalid ones, and validate the resulting effective configuration without aliasing retired names. Unsupported default templates and invalid saved strategies reset to current defaults instead of being interpreted on read. New setting writes use strict validation.
CLI takes a per-file upgrade lock, rechecks the current bytes, publishes an exact content-addressed backup, then atomically replaces the YAML. Web and Desktop insert the original document and discarded paths into configuration_backups in the same transaction as the replacement. A null project_id identifies global settings, including their revision and default-template metadata; a project ID identifies a backup containing that project's config and strategy . Unchanged documents produce no writes. Backup or replacement failure preserves the original document; each project's transaction is independent, so a later failure does not undo earlier upgrades.
Web uses the settings advisory lock and project row locks. Desktop uses short catalog write transactions, with no credential access, model requests or filesystem work inside them. Neither path modifies project state, usage or frozen jobs. Backup locations and user-visible fallback behavior are documented in the configuration reference .
Execution and publication
The supervisor claims a durable run before starting its writer, so a duplicate delivery cannot stop or replace that writer. The project run lock covers recovery and domain work. Before unlocking, the writer records its outcome on the running job. After exit, the supervisor commits job and project status in one catalog transaction, updating the project only for its latest workflow. This does not require opening the project directory. Recovery uses the same transaction and honors a recorded outcome. See the shared cancellation contract for how committed checkpoints survive a forced stop.
Export coordination holds one export lock through claim, render and publication; rendering never publishes. The catalog commits the published artifact and its job's successful status together. Retired history is hidden at that commit; reclaiming its files afterward cannot change publication status.
Pause admission checks the latest non-export run and active status in one catalog transaction. Source replacement commits preview-cache invalidation before publishing the new source reference. A failed invalidation rolls back; an uncertain catalog commit retains the complete candidate file rather than risking deletion of a published source. These boundaries do not provide a cross-store transaction or automatic orphan-file cleanup.
Initialization commits the manifest last; publication uses a recoverable index before changing formal targets. Stable segment identities, consistent export snapshots, and once-only usage accounting apply across storage backends. Detailed checkpoint, language policy and prompt-resource rules live in pipeline development .
The crate lives in packages/core/rust/ . src/lib.rs is the PyO3 boundary; src/epub/ contains the engine, with ingest.rs and extract.rs for reading, export.rs , generate.rs and html.rs for writing, and shared modules for the archive, DOM, tokenizers, links and worker budget.
Core's private PyO3 extension opens the ZIP, reads OPF and NAV/NCX, builds XHTML trees, extracts paragraphs and notes, and groups them into logical chapters. The XHTML and tolerant HTML tokenizers both run in Rust. The engine returns the same chapter, anchor and annotation state consumed by translation and resume.
Template export checks saved anchors and source text against the original resource. It reuses the in-memory tree for translations, note placement and presentation. When rendering an original EPUB from a frozen snapshot, the writer consumes one independent copy of each chapter without caching another in the export view. Chapters with no saved targets skip translation-only processing, not source validation. Bilingual export allocates source IDs for all pages before rewriting cross-file links; it does not serialize and reparse the trees. The writer copies unchanged members in compressed form and inserts the optional page in the same pass. For EPUB-to-HTML export, Rust extracts the rendered bodies and embeds referenced media using ZIP-only lookup; Python supplies the common HTML shell. For other source formats, Python supplies rendered chapters and resolved assets to Rust to generate the EPUB 3 package.
The extension releases the Python GIL. A process-wide admission slot bounds simultaneous book-sized trees, and an ordered pool of up to six threads processes books with at least twelve resources. Python still owns storage snapshots, language policies and atomic replacement; native workers never access application state.
The same extension hosts text.rs (plain-text and Markdown sections, paragraphs and export formatting) and fb2.rs (FictionBook XML and resource references). The Python adapters keep the strict legacy-encoding policy.
docx/ handles WordprocessingML import and reconstruction, including the package parts, paragraph and run properties, table merges and list numbering. Python applies export language policy and supplies one snapshot chapter at a time. Rust projects style ranges, merges continuations and orders bilingual paragraphs. python-docx is used for independent test fixtures, not by the installed engine.
For standalone HTML with an explicit canonical shell and text-only paragraphs and headings, html/ingest.rs builds chapters, anchors and templates in one pass. Other inputs retain the tolerant HTML parser and the same persisted identities. html.rs plans prose regions, normalizes annotation offsets, backfills text and attributes, updates canonical document shells and rewrites local media references. For canonical HTML, Rust can also emit both bilingual orders and restore simple annotations with verified offsets. Complex link rewrites, nested or stale placements and noncanonical inputs use the Python compatibility renderer. Large MinerU PDFs are split in a private directory using pdf/ , with pypdf page cloning for unsupported page features. Each upload attempt streams from a fresh file handle, and result ZIPs stream to the private directory rather than buffering whole archives in memory. The directory needs space for all split PDF chunks and downloaded ZIPs and is removed when conversion exits. Python reads the Content List V2 ZIPs in order, closing each archive after reading its JSON and referenced images and before opening the . The combined markup and image resources still accumulate in memory while building converted.epub ; rendering does not have a constant memory bound for the whole book.
New runs use the regular EPUB reader and writer. The manifest binds the original PDF hash and the derived EPUB hash; fmt remains pdf for the project and its previews. Template-aware operations use the derived EPUB, not the uploaded file. Exports never request another conversion from MinerU.
Core reports MinerU failures using local categories and controlled fields, such as the request stage, HTTP status, retry count, or missing field name. Never copy service messages, response excerpts, batch IDs, or signed URLs into exceptions or logs: task history and live progress reuse the error message. HTTP client traces are suppressed only during MinerU requests. Local guidance, such as freeing temporary disk space or adding an OCR text layer to an image-only PDF, remains visible without exposing local paths.
To inspect an existing MinerU result bundle, use the same renderer offline:
The converter uses only Content List V2 and referenced local assets, not the Markdown or HTML export. It retains the recorded block order, page footnotes, figures, captions and reference entries, while omitting running page headers, footers and numbers. It emits MathML with visible equation numbers and uses an available formula crop when display math cannot be rendered. In mixed prose and math paragraphs it fills missing spaces to Latin letters and digits and uses start alignment to avoid stretching the words before wrapped formulas. Neither adjustment changes the LaTeX. Code listing text keeps its whitespace; algorithm prose and captions are translatable, with inline formulas protected. Generated source editions mark each explicit TOC heading as a logical chapter boundary, including nested headings. The NAV document is not in the reading order. This preserves the TOC tree without changing chapter selection for ordinary EPUBs. Only links present in the JSON are carried over.
PDF layout extraction and fillback remain in the separate BabelDOC bridge. For image-only detection and bookmarks, Core first inspects the PDF natively; ambiguous text, named destinations and unusual outlines use a shared pypdf reader. Core projects translations, row ranges and annotation placements from the same saved paragraphs. It streams the HTTP response to a private file and uses pdf/ to compose bilingual spreads and remap links before atomic publication. Supported page content is written into the spread itself, so ordinary page text stays visible to pypdf's layout extractor. The Python composer remains the fallback for unsupported features such as encrypted inputs or non-link annotations.
Boundary verification
Run packages/core/tests/test_architecture_boundaries.py for dependency changes and test_orchestrator_contract.py for pipeline assembly changes.
For storage changes, also run test_storage_injection.py and the affected adapter tests.
For shared UI changes, verify both hosts and run pnpm test:frontend-boundaries after both builds. Schema changes need pnpm check:schema .
Use the repository guide for the complete safety constraints and the contribution guide for test commands.
The full story
This article is one source in a clustered incident — the cluster page carries the summary, timeline and every other outlet covering it.
