Skip to main content
The AppFlowy Rust backend provides high-performance business logic, data persistence, and collaborative features through a modular workspace architecture.

Workspace Structure

The Rust codebase is located in frontend/rust-lib/ and organized as a Cargo workspace:

Core Modules

dart-ffi - FFI Bridge

The FFI layer bridges Dart/Flutter with Rust:

Purpose

Exposes Rust functions to Dart through C-compatible FFI

Crate Type

Compiled as staticlib (macOS/iOS) or cdylib (Windows/Linux/Android)
Key responsibilities:
  • Receives events from Flutter through FFI
  • Marshals data between Dart and Rust
  • Routes events to the dispatch system
  • Sends responses back to Flutter

flowy-core - Central Coordinator

The core module orchestrates all other modules:
Responsibilities:
  • Application lifecycle management
  • Module initialization and dependency injection
  • Configuration and environment setup
  • Cross-module coordination

flowy-user - User Management

Handles authentication and user profiles:
1

Authentication

  • Email/password login
  • OAuth integration (Google, GitHub)
  • Anonymous sessions
2

User Profile

  • Profile management
  • User preferences
  • Session management
3

Authorization

  • Permission checking
  • Role-based access control

flowy-folder - Workspace & Folders

Manages workspace hierarchy and organization:
Features:
  • Workspace creation and management
  • Folder hierarchy with nesting
  • View organization and ordering
  • Trash and restore functionality
  • Favorites and recent items

flowy-document - Document Editor

Rich text editing with collaborative features:

CRDT-based

Uses Yrs (Yjs in Rust) for conflict-free collaborative editing

Block-based

Document is composed of blocks (paragraphs, headings, lists)
Supported blocks:
  • Paragraph, headings (H1-H6)
  • Lists (bulleted, numbered, toggle)
  • Checkboxes and to-do lists
  • Code blocks with syntax highlighting
  • Images and embeds
  • Tables and dividers

flowy-database2 - Database Views

Provides multiple views over structured data:
Spreadsheet-like table view with cells, rows, and columns
Features:
  • Multiple field types (text, number, date, select, etc.)
  • Filters and sorts
  • Grouping and aggregation
  • Cell editing and validation
  • Real-time updates

flowy-ai - AI Services

Integrates AI capabilities:
  • AI chat interface
  • Text generation and completion
  • Document summarization
  • Translation and rewriting
  • Integration with OpenAI, local LLMs

flowy-storage - File Storage

Manages file uploads and storage:
  • Local file caching
  • Cloud storage integration
  • Image optimization
  • File download and upload

flowy-search - Search Functionality

Full-text search powered by Tantivy:

Infrastructure Modules

lib-dispatch - Event Dispatch System

The event dispatch system is the backbone of the architecture:
1

Event Registration

Each module registers its events and handlers:
2

Event Routing

Events are routed to the appropriate handler based on event type
3

Request Processing

Handlers process requests asynchronously and return results
4

Response Delivery

Results are sent back to the caller through the FFI layer
Event structure:

lib-infra - Infrastructure

Shared infrastructure utilities:
  • Async runtime utilities
  • Error handling and result types
  • Serialization helpers
  • Platform detection

lib-log - Logging

Structured logging across all modules:

Data Layer

SQLite Integration

flowy-sqlite provides database access:

Database Schema

Each module maintains its own tables:

Collaborative Features

CRDT Integration

AppFlowy uses the collab crates for CRDT support:
These are built on Yrs (Yjs in Rust).

Sync Protocol

1

Local changes

User edits are applied to the local CRDT state
2

Generate updates

CRDT generates binary updates representing the changes
3

Send to server

Updates are sent to AppFlowy Cloud via WebSocket
4

Apply remote updates

Remote updates are applied to the local state automatically
CRDT ensures that concurrent edits from multiple users are merged without conflicts.

Build System

Cargo Workspace

All crates are part of a single workspace:

Shared Dependencies

Common dependencies are defined at the workspace level:

Platform Compilation

Target Platforms

Feature Flags

Compile-time features control functionality:

Testing

Unit Tests

Integration Tests

Some tests require the Rust backend to be built with the dart feature.

Code Style

Rust code follows the rustfmt.toml configuration:
Format code with:

Next Steps

Setup Environment

Set up your development environment

Building Desktop

Build the Rust backend for desktop