# ajmalbuv/typst_flutter architecture

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

- Interactive diagram: https://gitdiagram.com/ajmalbuv/typst_flutter
- Repository: https://github.com/ajmalbuv/typst_flutter

## Overview

typst_flutter embeds the Typst compiler in Flutter through a Rust FFI bridge. The main workflow initializes a compiler, supplies markup and optional virtual files, fonts, and inputs, then compiles to an opaque document handle for querying or exporting/rendering. Flutter widgets provide live previews and can reuse a shared compiler. The graph also shows diagnostics and package resolution. Dart implementation details and several README-described capabilities are not excerpted, so those links are documented relationships rather than claims of inspected call sites.

Main entry points: [`lib/src/compiler.dart`](https://github.com/ajmalbuv/typst_flutter/blob/main/lib/src/compiler.dart) (Compiler API), [`rust/src/api/typst.rs`](https://github.com/ajmalbuv/typst_flutter/blob/main/rust/src/api/typst.rs) (Typst Engine API), [`lib/src/document.dart`](https://github.com/ajmalbuv/typst_flutter/blob/main/lib/src/document.dart) (Document Handle), [`rust/src/world/mod.rs`](https://github.com/ajmalbuv/typst_flutter/blob/main/rust/src/world/mod.rs) (Compiler World)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_flutter["Flutter API"]
  node_compiler["Compiler API<br/>[compiler.dart]"]
  node_document["Document Handle<br/>[document.dart]"]
  node_files["Virtual Files<br/>[files.dart]"]
  node_fonts["Font Inputs<br/>[fonts.dart]"]
  node_provider["Compiler Provider"]
  node_viewer["Document Viewer"]
  node_view["Typst View<br/>[typst_view.dart]"]
end

subgraph group_bridge["FFI Bridge"]
  node_bridge_dart["Dart Bridge<br/>[typst.dart]"]
  node_bridge_rust["Generated Bridge<br/>[frb_generated.rs]"]
end

subgraph group_engine["Rust Compiler"]
  node_api["Typst Engine API<br/>[typst.rs]"]
  node_doc_core["Compiled Document<br/>[typst.rs]"]
  node_world["Compiler World<br/>[mod.rs]"]
end

subgraph group_support["Compiler Support"]
  node_diagnostics["Diagnostics<br/>[mod.rs]"]
  node_packages["Package Resolver<br/>[mod.rs]"]
end

node_app(("Flutter App"))
node_registry["Typst Registry"]
node_typst["Typst Runtime"]

node_app -->|"provides markup"| node_compiler
node_compiler -.->|"calls"| node_bridge_dart
node_bridge_dart -.->|"bridges calls"| node_bridge_rust
node_bridge_rust -->|"dispatches"| node_api
node_api -->|"configures"| node_world
node_api -->|"maps errors"| node_diagnostics
node_world -->|"resolves files"| node_packages
node_world -.->|"supplies inputs"| node_typst
node_api -->|"compiles to"| node_doc_core
node_doc_core -->|"renders document"| node_typst
node_packages -->|"downloads packages"| node_registry
node_compiler -->|"accepts files"| node_files
node_compiler -->|"accepts fonts"| node_fonts
node_compiler -->|"returns handle"| node_document
node_document -.->|"exports and queries"| node_bridge_dart
node_provider -->|"shares engine"| node_compiler
node_viewer -->|"reuses compiler"| node_provider
node_viewer -->|"previews pages"| node_document
node_view -->|"reuses compiler"| node_provider
node_view -.->|"renders preview"| node_document

click node_compiler "https://github.com/ajmalbuv/typst_flutter/blob/main/lib/src/compiler.dart"
click node_document "https://github.com/ajmalbuv/typst_flutter/blob/main/lib/src/document.dart"
click node_files "https://github.com/ajmalbuv/typst_flutter/blob/main/lib/src/files.dart"
click node_fonts "https://github.com/ajmalbuv/typst_flutter/blob/main/lib/src/fonts.dart"
click node_provider "https://github.com/ajmalbuv/typst_flutter/blob/main/lib/src/widgets/typst_compiler_provider.dart"
click node_viewer "https://github.com/ajmalbuv/typst_flutter/blob/main/lib/src/widgets/typst_document_viewer.dart"
click node_view "https://github.com/ajmalbuv/typst_flutter/blob/main/lib/src/widgets/typst_view.dart"
click node_bridge_dart "https://github.com/ajmalbuv/typst_flutter/blob/main/lib/src/rust/api/typst.dart"
click node_bridge_rust "https://github.com/ajmalbuv/typst_flutter/blob/main/rust/src/frb_generated.rs"
click node_api "https://github.com/ajmalbuv/typst_flutter/blob/main/rust/src/api/typst.rs"
click node_doc_core "https://github.com/ajmalbuv/typst_flutter/blob/main/rust/src/api/typst.rs"
click node_world "https://github.com/ajmalbuv/typst_flutter/blob/main/rust/src/world/mod.rs"
click node_diagnostics "https://github.com/ajmalbuv/typst_flutter/blob/main/rust/src/diag/mod.rs"
click node_packages "https://github.com/ajmalbuv/typst_flutter/blob/main/rust/src/package/mod.rs"

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_compiler,node_document,node_files,node_fonts,node_provider,node_viewer,node_view toneBlue
class node_bridge_dart,node_bridge_rust toneAmber
class node_api,node_doc_core,node_world toneMint
class node_diagnostics,node_packages toneRose
class node_app,node_registry,node_typst toneIndigo
```

## Components

### Flutter API

- [Compiler API](https://github.com/ajmalbuv/typst_flutter/blob/main/lib/src/compiler.dart): `lib/src/compiler.dart`
- [Document Handle](https://github.com/ajmalbuv/typst_flutter/blob/main/lib/src/document.dart): `lib/src/document.dart`
- [Virtual Files](https://github.com/ajmalbuv/typst_flutter/blob/main/lib/src/files.dart): `lib/src/files.dart`
- [Font Inputs](https://github.com/ajmalbuv/typst_flutter/blob/main/lib/src/fonts.dart): `lib/src/fonts.dart`
- [Compiler Provider](https://github.com/ajmalbuv/typst_flutter/blob/main/lib/src/widgets/typst_compiler_provider.dart): `lib/src/widgets/typst_compiler_provider.dart`
- [Document Viewer](https://github.com/ajmalbuv/typst_flutter/blob/main/lib/src/widgets/typst_document_viewer.dart): `lib/src/widgets/typst_document_viewer.dart`
- [Typst View](https://github.com/ajmalbuv/typst_flutter/blob/main/lib/src/widgets/typst_view.dart): `lib/src/widgets/typst_view.dart`

### FFI Bridge

- [Dart Bridge](https://github.com/ajmalbuv/typst_flutter/blob/main/lib/src/rust/api/typst.dart): `lib/src/rust/api/typst.dart`
- [Generated Bridge](https://github.com/ajmalbuv/typst_flutter/blob/main/rust/src/frb_generated.rs): `rust/src/frb_generated.rs`

### Rust Compiler

- [Typst Engine API](https://github.com/ajmalbuv/typst_flutter/blob/main/rust/src/api/typst.rs): `rust/src/api/typst.rs`
- [Compiled Document](https://github.com/ajmalbuv/typst_flutter/blob/main/rust/src/api/typst.rs): `rust/src/api/typst.rs`
- [Compiler World](https://github.com/ajmalbuv/typst_flutter/blob/main/rust/src/world/mod.rs): `rust/src/world/mod.rs`

### Compiler Support

- [Diagnostics](https://github.com/ajmalbuv/typst_flutter/blob/main/rust/src/diag/mod.rs): `rust/src/diag/mod.rs`
- [Package Resolver](https://github.com/ajmalbuv/typst_flutter/blob/main/rust/src/package/mod.rs): `rust/src/package/mod.rs`

### Other components

- **Flutter App**
- **Typst Registry**
- **Typst Runtime**

## Connections

- Flutter App → Compiler API: provides markup (evidence: `README.md`)
- Compiler API → Dart Bridge: calls
- Dart Bridge → Generated Bridge: bridges calls
- Generated Bridge → Typst Engine API: dispatches (evidence: `rust/src/frb_generated.rs`)
- Typst Engine API → Compiler World: configures (evidence: `rust/src/api/typst.rs`)
- Typst Engine API → Diagnostics: maps errors (evidence: `rust/src/api/typst.rs`)
- Compiler World → Package Resolver: resolves files (evidence: `rust/src/world/mod.rs`)
- Compiler World → Typst Runtime: supplies inputs
- Typst Engine API → Compiled Document: compiles to (evidence: `rust/src/api/typst.rs`)
- Compiled Document → Typst Runtime: renders document (evidence: `rust/src/api/typst.rs`)
- Package Resolver → Typst Registry: downloads packages (evidence: `rust/src/package/mod.rs`)
- Compiler API → Virtual Files: accepts files (evidence: `README.md`)
- Compiler API → Font Inputs: accepts fonts (evidence: `README.md`)
- Compiler API → Document Handle: returns handle (evidence: `README.md`)
- Document Handle → Dart Bridge: exports and queries
- Compiler Provider → Compiler API: shares engine (evidence: `README.md`)
- Document Viewer → Compiler Provider: reuses compiler (evidence: `README.md`)
- Document Viewer → Document Handle: previews pages (evidence: `README.md`)
- Typst View → Compiler Provider: reuses compiler (evidence: `README.md`)
- Typst View → Document Handle: renders preview
