How tyx-editor/tyx works
TyX is a multi-target editor repository centered on a shared document model and a browser-based editor UI, with native shell capabilities added through Tauri. The architecture splits cleanly into frontend application code, Rust-native conversion/runtime code, schema/package generation, and supporting docs/tooling.
1. Primary user-facing app
- The main UI lives in src/ as a React + Vite application.
- src/App.tsx, src/main.tsx, and src/index.css form the app entry and global shell.
- The app is an editor-centric product, not a generic website: most UI is composed of editor controls, command palettes, modals, document tabs, settings, and status/toolbar components.
2. Editor subsystem and plugin architecture
- src/components/Editor.tsx is the core editing surface.
- src/components/plugins/ contains a large plugin layer for editor behavior: math input, images, RTL handling, code highlighting, keyboard maps, table commands, nested editors, toolbar integration, and local-storage persistence.
- This indicates a modular editor pipeline where features are injected as plugins rather than hardcoded into one monolith.
3. Document and domain model boundary
- src/models/ defines the app’s domain objects: content, documents, settings, functions, and values.
- src/format.ts, src/functions.ts, src/config.ts, src/shortcuts.ts, and src/state.ts provide the policy layer around how documents are represented, edited, and configured.
- The editor UI talks to these models rather than directly to low-level Typst/TyX syntax everywhere.
4. Frontend/backend adapter layer
- src/backend/ is the platform abstraction boundary.
- common.ts likely defines shared contracts, while web.tsx and tauri.ts adapt those contracts to browser and native desktop environments.
- This is the key seam for architecture diagrams: the same React app can run as a web editor or as a Tauri app, with native features swapped in by backend implementation.
5. Native shell and system integration
- src-tauri/ contains the Rust-side Tauri application.
- src-tauri/src/main.rs, lib.rs, cli.rs, cmds.rs, pdf.rs, and utils.rs indicate native commands for app startup, command handling, CLI functionality, PDF-related work, and utility operations.
- src-tauri/capabilities/ and tauri.conf.json define what native permissions and integrations the frontend can use.
6. Document conversion core
- The repository includes Rust crates dedicated to converting between TyX and Typst representations:
- crates/typst-to-tyx
- crates/tyx-to-typst
- crates/tyx-converters
- These are the main data-flow engines for import/export and round-tripping documents.
- Integration fixtures in crates/tyx-converters/src/fixtures/ show snapshot-tested conversion behavior, especially for .typ inputs.
7. WASM bridge for converters
- crates/tyx-converters-wasm packages converter logic for WebAssembly.
- This is the boundary that likely enables converter execution in browser-like contexts or shared JS/runtime contexts without requiring the native Rust binary.
8. Schema and versioning packages
- crates/tyx-schema contains generated schema code plus a build.rs, suggesting schema generation is part of the build pipeline.
- JSON schema outputs are checked into schemas/ for TyX document/settings validation and external tooling.
- crates/tyx-version centralizes version information for the project and likely feeds packaging/release metadata.
9. Python bindings for schema access
- python/ exposes tyx_schema as a Python package.
- This is not the core app runtime, but it is an external-integration surface for tooling that needs to read or validate TyX schemas from Python.
- python/tests/test_examples.py suggests the package is validated against example inputs or generated artifacts.
10. Documentation and distribution
- docs/ contains the published documentation site, getting-started material, configuration, and command references.
- mkdocs.yml, .readthedocs.yaml, and docs/requirements.txt show a docs-as-code publishing pipeline.
- The repo also includes an examples/ directory for sample TyX documents.
11. Build, CI, and release automation
- .github/workflows/lint.yml and publish.yml handle validation and publishing.
- Scripts in scripts/ generate schemas and changelog content, linking source code, docs, and release metadata.
- bun.lock, Cargo.lock, Vite/TS configs, and Rust build scripts show a polyglot build where JS, Rust, and generated artifacts are coordinated.
12. Platform targets
- The presence of src-tauri/gen/android/ and mobile icons indicates mobile packaging support in addition to desktop and web.
- This repository is therefore a cross-platform editor codebase, with shared UI logic and platform-specific shells/adapters.
13. Test strategy
- Frontend/e2e coverage exists under test/specs/ using Webdriver-style test infrastructure.
- Rust-side conversion behavior is tested with fixture snapshots.
- The test boundary mirrors the architecture: UI behavior on one side, conversion correctness on the other.
Overall, the most important diagram boundary is: React editor UI + domain models on top, platform adapters in the middle, and Rust conversion/native services underneath. The conversion crates and schema packages are the core non-UI subsystems; the Tauri shell and backend adapters are what make the same editor run across web, desktop, and mobile packaging targets.
Main entry points: Editor.tsx Editor core · src Tauri shell · tyx-converters Converter core · App.tsx App shell
Components 21
Frontend app
React/Vite editor UI, domain model, and browser/native backend adapters.
- App shell · Main UI bootstrap and top-level application shell.
src/App.tsx - Editor core · Primary editing component and central document interaction surface.
src/components/Editor.tsx - Editor plugins · Modular editor behaviors such as math, images, RTL, tables, keyboard maps, and toolbar integration.
src/components/plugins - Domain models · Content, document, settings, functions, and values used by the app.
src/models - Policy layer · Document formatting, configuration, shortcuts, functions, and shared editor state.
src/format.ts - Backend bridge · Shared contracts plus web and Tauri implementations for platform-dependent behavior.
src/backend - UI panels · Document tabs, settings, save dialogs, status bar, command buttons, and related editor UI.
src/components - Playground assets · Playground support code and styling resources used by the editor UI.
src/resources
Native runtime
Tauri shell and Rust-side commands, PDF, and platform integration.
- Tauri shell · Rust entrypoints, command handling, CLI, and PDF/system utilities.
src-tauri/src - Capabilities · Native permission and platform configuration for desktop/mobile integration.
src-tauri/capabilities - Android target · Generated Android wrapper, activity, and Gradle build integration for Tauri.
src-tauri/gen/android
Conversion core
Rust crates that convert documents and expose shared conversion logic.
- Typst to TyX · Rust crate for importing Typst into TyX document structures.
crates/typst-to-tyx - TyX to Typst · Rust crate for exporting TyX documents back to Typst.
crates/tyx-to-typst - Converter core · Shared converter logic, fixtures, and snapshot-tested conversion behavior.
crates/tyx-converters - WASM bridge · WASM packaging for converter logic in browser-like or shared JS runtimes.
crates/tyx-converters-wasm
Schema and bindings
Generated schemas, versioning, and Python access to schema data.
- Schema crate · Generated TyX schema code and build-time schema generation entrypoint.
crates/tyx-schema - JSON schemas · Checked-in JSON schema outputs for documents and settings validation.
schemas - Version crate · Centralized version information used across build and release flows.
crates/tyx-version - Python package · Python access to TyX schema data and example-based validation.
python/src/tyx_schema
Docs and automation
Documentation, examples, scripts, and CI/release support.
- Docs site · MkDocs/ReadTheDocs documentation, configuration guides, and command reference.
docs - Build automation · Schema generation scripts, changelog extraction, and GitHub workflows.
scripts
Connections 22
- App shell → Editor core: hosts · Top-level app renders the editor surface.
- App shell → UI panels: assembles · App composes command, modal, tab, and status UI.
- Editor core → Editor plugins: extends via · Editor behavior is layered through plugins.
- Editor core → Domain models: edits · Editor operates on shared document and value models.
- Editor core → Policy layer: applies · Formatting, shortcuts, and state policy shape editor behavior.
- Backend bridge → Domain models: uses · Platform adapters exchange model data with the UI.
- Backend bridge → Tauri shell: bridges to · Tauri adapter connects browser UI to native capabilities.
- Backend bridge → App shell: serves · Web adapter supports running the same app in the browser.
- UI panels → Domain models: binds · Panels and dialogs read and update document/settings state.
- Playground assets → App shell: supports · Embedded playground assets are consumed by the frontend.
- Tauri shell → Capabilities: governs · Native shell is constrained by capability configuration.
- Tauri shell → Android target: packages for · Tauri project includes generated Android target support.
- Tauri shell → Converter core: invokes · Native commands can use conversion services.
- Converter core → Typst to TyX: imports · Shared converter stack includes Typst-to-TyX path.
- Converter core → TyX to Typst: exports · Shared converter stack includes TyX-to-Typst path.
- Converter core → WASM bridge: shared with · Core converter logic is packaged for WASM use.
- Schema crate → JSON schemas: generates · Build-time schema generation produces checked-in JSON schemas.
- Schema crate → Python package: feeds · Schema data is exposed to Python bindings.
- Version crate → Build automation: used by · Version metadata feeds release and changelog automation.
- Docs site → JSON schemas: references · Documentation and external tools rely on published schemas.
- Build automation → Schema crate: builds · Scripts and CI regenerate schema artifacts.
- Build automation → Docs site: publishes · Automation supports docs generation and release workflows.