Document Format & Serialization
Relevant source files
The following files were used as context for generating this wiki page:
Graphite utilizes a procedural, nondestructive document format that treats artwork as data rather than static pixels. This approach allows the editor to remain lightweight, as documents primarily contain descriptions of operations (nodes) rather than heavy pixel data. By maintaining a clear separation between the document's structural description and the rendered output, Graphite enables infinite scalability and lossless editing.
The document format is currently evolving through several alpha stages. While the project aims for a stable document format by the end of its Alpha 4 milestone, current efforts focus on robustness and backward compatibility on a best-effort basis.
Sources: website/content/features.md, website/content/blog/2024-07-31-graphite-progress-report-q2-2024.md:213-214
Nondestructive Data-Driven Architecture
Graphite documents are built on a hybrid architecture that synchronizes a layer-based interface with an underlying node graph. In this system, every layer is essentially a visual representation of a node or a subgraph in the Graphene engine.
Data vs. Pixels
Unlike traditional editors that store destructive alterations to pixel data, Graphite documents contain only a description of the editing operations. This results in ultra-tiny document sizes, especially when source assets are linked externally. The artwork is treated as a set of mathematical instructions that the engine executes to render the final image at the current viewing resolution.
Sources: website/content/features.md, website/content/volunteer/guide/codebase-overview/_index.md
Structural Components
The document format encompasses several key data types:
- Vector Paths: Mathematically described curves that remain crisp at any zoom level.
- Node Metadata: Information regarding node positioning, display names, and category associations used by the editor's UI.
- Table-based Data: A planned feature to generalize graphical data into a structured table format for introspection and manipulation.
Sources: website/content/features.md, tools/node-docs/src/page_node.rs:16-18
The diagram shows how a Graphite document splits into descriptions of operations and UI metadata, with the node graph and layer stack providing dual views of the same logic.
Sources: website/content/features.md, website/content/volunteer/guide/codebase-overview/_index.md
Serialization and Communication
The serialization process is critical for both saving documents to disk and communicating state between the Rust-based editor backend and the TypeScript frontend.
Frontend/Backend Messaging
The editor uses a message-based system for synchronization. When a document is modified, the backend queues FrontendMessage objects. These are serialized from Rust data structures into JavaScript-compatible formats to update the web-based GUI.
Sources: website/content/volunteer/guide/codebase-overview/_index.md
Data Models for Nodes
During serialization of node-related documentation or state, the system extracts specific fields including input types, primary outputs, and context dependencies.
| Component | Description | Relevance to Serialization |
|---|---|---|
| NodeMetadata | Contains UI-specific data like display_name and category. | Serialized for cataloging and UI rendering. |
| TaggedValue | Represents concrete values (colors, gradients, etc.). | The primary format for serializing node parameters. |
| RegistryValueSource | Defines where a value originates (Default or Scope). | Determines how parameters are restored upon loading. |
Sources: tools/node-docs/src/page_node.rs:25-30, tools/node-docs/src/page_node.rs:90-100
Document Evolution and Compatibility
As the project is in alpha, the document format undergoes frequent changes. The team employs a "best-effort" backward compatibility strategy.
Migration and Stability
- Version Management: Planned features include node version management to handle updates to node logic without breaking existing documents.
- Persistence: State such as overlays, snapping settings, and grid configurations are persisted within the saved document format.
- Build Metadata: Documents can be associated with specific Git commit hashes, which can be viewed via Help > About Graphite... to aid in debugging format regressions.
Sources: website/content/blog/2024-07-31-graphite-progress-report-q2-2024.md:210-214, website/content/volunteer/guide/codebase-overview/debugging-tips.md:14-16
Procedural Generation Serialization
For features like "Instancer" nodes or procedural patterns, the document does not store the generated geometry but rather the seed and parameters required to re-generate the data at runtime. This ensures that "infinite generative vector patterns" remain small in the document file regardless of the complexity of the generated output.
Sources: website/content/features.md
The sequence diagram illustrates the flow of document state serialization during an interactive edit.
Sources: website/content/volunteer/guide/codebase-overview/_index.md
Future Roadmap: Alpha 4 and Beyond
The document format is slated for significant upgrades in the Alpha 4 milestone, focusing on performance and extensibility:
- Stable Document Format: Moving away from best-effort compatibility to a fixed specification.
- Expanded Imaging Model: A broader data format to support HDR, WCG, and advanced color handling.
- Document History Management: Serialization of the undo/redo stack within the document.
- CRDT Integration: Future plans for "Conflict-free Replicated Data Types" to allow for collaborative editing and offline resolution.
Sources: website/content/features.md