# tyx-editor/tyx architecture

> Architecture diagram of the GitHub repository tyx-editor/tyx, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tyx-editor/tyx
- Repository: https://github.com/tyx-editor/tyx

## Overview

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: [`src/components/Editor.tsx`](https://github.com/tyx-editor/tyx/blob/main/src/components/Editor.tsx) (Editor core), [`src-tauri/src`](https://github.com/tyx-editor/tyx/tree/main/src-tauri/src) (Tauri shell), [`crates/tyx-converters`](https://github.com/tyx-editor/tyx/tree/main/crates/tyx-converters) (Converter core), [`src/App.tsx`](https://github.com/tyx-editor/tyx/blob/main/src/App.tsx) (App shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend app"]
  node_src_app["App shell<br/>React entry<br/>[App.tsx]"]
  node_src_editor["Editor core<br/>Editor surface<br/>[Editor.tsx]"]
  node_src_plugins["Editor plugins<br/>Plugin layer"]
  node_src_models["Domain models<br/>Document model"]
  node_src_policy["Policy layer<br/>Formatting/state<br/>[format.ts]"]
  node_src_backend["Backend bridge<br/>Platform adapter"]
  node_src_ui["UI panels<br/>Controls and modals"]
  node_src_resources["Playground assets<br/>Embedded resources"]
end

subgraph group_native["Native runtime"]
  node_tauri_shell["Tauri shell<br/>Native app"]
  node_tauri_caps["Capabilities<br/>Permissions"]
  node_android_gen["Android target<br/>Mobile packaging"]
end

subgraph group_converters["Conversion core"]
  node_conv_typst_to_tyx["Typst to TyX<br/>Converter crate"]
  node_conv_tyx_to_typst["TyX to Typst<br/>Converter crate"]
  node_conv_core["Converter core<br/>Shared conversion"]
  node_conv_wasm["WASM bridge<br/>WebAssembly"]
end

subgraph group_schema["Schema and bindings"]
  node_schema_crate["Schema crate<br/>Generated schema"]
  node_schema_files["JSON schemas<br/>Schema artifacts"]
  node_version_crate["Version crate<br/>Version metadata"]
  node_python_pkg["Python package<br/>Bindings"]
end

subgraph group_tooling["Docs and automation"]
  node_docs_site["Docs site<br/>Documentation"]
  node_automation["Build automation<br/>Scripts and CI"]
end

node_src_app -->|"hosts"| node_src_editor
node_src_app -->|"assembles"| node_src_ui
node_src_editor -->|"extends via"| node_src_plugins
node_src_editor -->|"edits"| node_src_models
node_src_editor -->|"applies"| node_src_policy
node_src_backend -->|"uses"| node_src_models
node_src_backend -->|"bridges to"| node_tauri_shell
node_src_backend -->|"serves"| node_src_app
node_src_ui -->|"binds"| node_src_models
node_src_resources -->|"supports"| node_src_app
node_tauri_shell -->|"governs"| node_tauri_caps
node_tauri_shell -->|"packages for"| node_android_gen
node_tauri_shell -->|"invokes"| node_conv_core
node_conv_core -->|"imports"| node_conv_typst_to_tyx
node_conv_core -->|"exports"| node_conv_tyx_to_typst
node_conv_core -->|"shared with"| node_conv_wasm
node_schema_crate -->|"generates"| node_schema_files
node_schema_crate -->|"feeds"| node_python_pkg
node_version_crate -->|"used by"| node_automation
node_docs_site -->|"references"| node_schema_files
node_automation -->|"builds"| node_schema_crate
node_automation -->|"publishes"| node_docs_site

click node_src_app "https://github.com/tyx-editor/tyx/blob/main/src/App.tsx"
click node_src_editor "https://github.com/tyx-editor/tyx/blob/main/src/components/Editor.tsx"
click node_src_plugins "https://github.com/tyx-editor/tyx/tree/main/src/components/plugins"
click node_src_models "https://github.com/tyx-editor/tyx/tree/main/src/models"
click node_src_policy "https://github.com/tyx-editor/tyx/blob/main/src/format.ts"
click node_src_backend "https://github.com/tyx-editor/tyx/tree/main/src/backend"
click node_src_ui "https://github.com/tyx-editor/tyx/tree/main/src/components"
click node_src_resources "https://github.com/tyx-editor/tyx/tree/main/src/resources"
click node_tauri_shell "https://github.com/tyx-editor/tyx/tree/main/src-tauri/src"
click node_tauri_caps "https://github.com/tyx-editor/tyx/tree/main/src-tauri/capabilities"
click node_android_gen "https://github.com/tyx-editor/tyx/tree/main/src-tauri/gen/android"
click node_conv_typst_to_tyx "https://github.com/tyx-editor/tyx/tree/main/crates/typst-to-tyx"
click node_conv_tyx_to_typst "https://github.com/tyx-editor/tyx/tree/main/crates/tyx-to-typst"
click node_conv_core "https://github.com/tyx-editor/tyx/tree/main/crates/tyx-converters"
click node_conv_wasm "https://github.com/tyx-editor/tyx/tree/main/crates/tyx-converters-wasm"
click node_schema_crate "https://github.com/tyx-editor/tyx/tree/main/crates/tyx-schema"
click node_schema_files "https://github.com/tyx-editor/tyx/tree/main/schemas"
click node_version_crate "https://github.com/tyx-editor/tyx/tree/main/crates/tyx-version"
click node_python_pkg "https://github.com/tyx-editor/tyx/tree/main/python/src/tyx_schema"
click node_docs_site "https://github.com/tyx-editor/tyx/tree/main/docs"
click node_automation "https://github.com/tyx-editor/tyx/tree/main/scripts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_src_app,node_src_editor,node_src_plugins,node_src_models,node_src_policy,node_src_backend,node_src_ui,node_src_resources toneBlue
class node_tauri_shell,node_tauri_caps,node_android_gen toneAmber
class node_conv_typst_to_tyx,node_conv_tyx_to_typst,node_conv_core,node_conv_wasm toneMint
class node_schema_crate,node_schema_files,node_version_crate,node_python_pkg toneRose
class node_docs_site,node_automation toneIndigo
```

## Components

### Frontend app

React/Vite editor UI, domain model, and browser/native backend adapters.

- [App shell](https://github.com/tyx-editor/tyx/blob/main/src/App.tsx): React entry · Main UI bootstrap and top-level application shell. · `src/App.tsx`
- [Editor core](https://github.com/tyx-editor/tyx/blob/main/src/components/Editor.tsx): Editor surface · Primary editing component and central document interaction surface. · `src/components/Editor.tsx`
- [Editor plugins](https://github.com/tyx-editor/tyx/tree/main/src/components/plugins): Plugin layer · Modular editor behaviors such as math, images, RTL, tables, keyboard maps, and toolbar integration. · `src/components/plugins`
- [Domain models](https://github.com/tyx-editor/tyx/tree/main/src/models): Document model · Content, document, settings, functions, and values used by the app. · `src/models`
- [Policy layer](https://github.com/tyx-editor/tyx/blob/main/src/format.ts): Formatting/state · Document formatting, configuration, shortcuts, functions, and shared editor state. · `src/format.ts`
- [Backend bridge](https://github.com/tyx-editor/tyx/tree/main/src/backend): Platform adapter · Shared contracts plus web and Tauri implementations for platform-dependent behavior. · `src/backend`
- [UI panels](https://github.com/tyx-editor/tyx/tree/main/src/components): Controls and modals · Document tabs, settings, save dialogs, status bar, command buttons, and related editor UI. · `src/components`
- [Playground assets](https://github.com/tyx-editor/tyx/tree/main/src/resources): Embedded resources · 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](https://github.com/tyx-editor/tyx/tree/main/src-tauri/src): Native app · Rust entrypoints, command handling, CLI, and PDF/system utilities. · `src-tauri/src`
- [Capabilities](https://github.com/tyx-editor/tyx/tree/main/src-tauri/capabilities): Permissions · Native permission and platform configuration for desktop/mobile integration. · `src-tauri/capabilities`
- [Android target](https://github.com/tyx-editor/tyx/tree/main/src-tauri/gen/android): Mobile packaging · 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](https://github.com/tyx-editor/tyx/tree/main/crates/typst-to-tyx): Converter crate · Rust crate for importing Typst into TyX document structures. · `crates/typst-to-tyx`
- [TyX to Typst](https://github.com/tyx-editor/tyx/tree/main/crates/tyx-to-typst): Converter crate · Rust crate for exporting TyX documents back to Typst. · `crates/tyx-to-typst`
- [Converter core](https://github.com/tyx-editor/tyx/tree/main/crates/tyx-converters): Shared conversion · Shared converter logic, fixtures, and snapshot-tested conversion behavior. · `crates/tyx-converters`
- [WASM bridge](https://github.com/tyx-editor/tyx/tree/main/crates/tyx-converters-wasm): WebAssembly · 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](https://github.com/tyx-editor/tyx/tree/main/crates/tyx-schema): Generated schema · Generated TyX schema code and build-time schema generation entrypoint. · `crates/tyx-schema`
- [JSON schemas](https://github.com/tyx-editor/tyx/tree/main/schemas): Schema artifacts · Checked-in JSON schema outputs for documents and settings validation. · `schemas`
- [Version crate](https://github.com/tyx-editor/tyx/tree/main/crates/tyx-version): Version metadata · Centralized version information used across build and release flows. · `crates/tyx-version`
- [Python package](https://github.com/tyx-editor/tyx/tree/main/python/src/tyx_schema): Bindings · 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](https://github.com/tyx-editor/tyx/tree/main/docs): Documentation · MkDocs/ReadTheDocs documentation, configuration guides, and command reference. · `docs`
- [Build automation](https://github.com/tyx-editor/tyx/tree/main/scripts): Scripts and CI · Schema generation scripts, changelog extraction, and GitHub workflows. · `scripts`

## Connections

- 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.
