Skip to main content
Consistent code style makes AppFlowy’s codebase easier to read, maintain, and contribute to. This guide covers style conventions for both Dart/Flutter and Rust code.

Dart/Flutter Code Style

Dart Style Guide

AppFlowy follows the official Dart Style Guide.

Analysis Options

Linting rules are configured in analysis_options.yaml:

Formatting

1

Use dartfmt

Format code with dartfmt (built into flutter format):
2

Enable format on save

In VS Code (settings.json):

Key Conventions

Naming

Use UpperCamelCase for class names:

Trailing Commas

Always use trailing commas for better formatting:

Prefer Final

Use final for variables that don’t change:

Return Types

Always declare return types explicitly:

BLoC Pattern

AppFlowy uses the BLoC pattern for state management:
Key principles:
  • Events are immutable and describe actions
  • States are immutable and describe UI state
  • BLoCs handle business logic, not UI

Widget Structure

Organize widgets consistently:

File Organization

1

One class per file

Each file should contain one main public class.
2

File naming

Use snake_case for file names:
3

Import ordering

Order imports as follows:

Comments and Documentation

Use /// for public API documentation:

Rust Code Style

Rust Style Guide

AppFlowy follows the official Rust Style Guide.

Rustfmt Configuration

Formatting is configured in rust-lib/rustfmt.toml:

Formatting

1

Use rustfmt

Format code with rustfmt:
2

Check formatting

3

Enable format on save

In VS Code (settings.json):

Clippy Linting

Use Clippy for additional linting:
CI/CD pipelines enforce Clippy warnings. Fix all warnings before submitting PRs.

Key Conventions

Naming

Use UpperCamelCase for types:

Error Handling

Use Result for fallible operations:

Option Handling

Prefer combinators over pattern matching:

Struct Organization

Module Organization

1

File naming

Use snake_case for module files:
2

Module declaration

In lib.rs or mod.rs:
3

Import ordering

Comments and Documentation

Use /// for public API documentation:

Async Code

Use async/await for asynchronous operations:

Testing

Organize tests clearly:

General Best Practices

Keep Functions Small

Functions should do one thing well. Aim for under 50 lines.

Avoid Deep Nesting

Use early returns and helper functions to reduce nesting.

Write Tests

Test new code and maintain existing test coverage.

Document Public APIs

All public functions and types should have documentation.

Pre-commit Checks

Before committing, run:

CI/CD Enforcement

The following checks run automatically on all PRs:
  • Code formatting (Dart and Rust)
  • Linting (dartanalyzer, Clippy)
  • Unit tests
  • Integration tests
  • Build verification
PRs that fail these checks will not be merged. Fix all issues before requesting review.

Next Steps

Testing

Learn about testing practices

Contributing

Contribute to AppFlowy

Architecture

Understand the architecture

Building

Build AppFlowy from source