Skip to main content

Backend

The backend is a Rust Cargo workspace. The root Cargo.toml declares the members and centralizes shared dependency versions under [workspace.dependencies].

[workspace]
members = ["src-tauri", "crates/shared", "crates/show", "crates/ocr", "crates/classify"]

src-tauri — the app shell​

src-tauri/ is the Tauri application crate (package nque). It owns:

  • tauri.conf.json — product name, window definitions, bundle config.
  • build.rs and generate_context!() — never move these out of src-tauri.
  • capabilities/ — Tauri 2 capability (permission) definitions.
  • src/lib.rs — builds the app, registers plugins (opener, dialog), registers the invoke_handler, and implements window management (open_display_window).
  • src/commands.rs — the import_pdf_show command that wires the OCR and show pipelines together.

Keep src-tauri thin. It should resolve dialogs, marshal arguments, move CPU-heavy work onto spawn_blocking, and emit events. It should not contain pipeline logic.

The domain crates​

shared​

Small, pure, dependency-light utilities used across crates.

ocr — ingest​

Turns PDF bytes into a text document.

  • extract.rs — native text extraction and the scanned-PDF detection heuristic.
  • pdf.rs — renders PDF pages to images with PDFium.
  • ocr.rs — wraps the ocrs/rten engine with bundled models.
  • pipeline.rs — extract_text(): probe, then extract or render + OCR.

The OCR models are downloaded by crates/ocr/scripts/download-models.sh and embedded via include_bytes!. See OCR ingest.

classify​

Turns a line of text into a LineKind (Heading, StageDirection, Dialog, Noise) with a confidence score, and headings into a HeadingKind (Act, Scene, Division). Rule-based, in rules.rs. See Classify.

show — construct, filter, persist​

  • pipeline.rs — build_show_from_text: classify → construct → filter.
  • parse.rs — TextParseConfig and cue splitting.
  • filter.rs — filter_show and FilterConfig.
  • types.rs — Show, Section, Cue.
  • file.rs — the ShowFile envelope.
  • schema.rs — JSON Schema validation.
  • commands.rs — save_show, save_show_as, load_show, confirm_discard_changes.

Conventions​

  • Register every Tauri command in the invoke_handler in src-tauri/src/lib.rs.
  • Prefer client-agnostic logic in crates/shared (or a new domain crate) over src-tauri.
  • Centralize dependency versions in [workspace.dependencies].
  • The ocrs and rten packages are compiled with release-level optimization even in the dev profile (see Cargo.toml), because they are unusably slow under debug settings.
  • Add new crates under crates/ and register them in the members list.