English
Coding conventions
These conventions are what keep more than 30 packages consistent as they evolve. Please read through them before you open a PR.
Layers and imports
- Respect the
foundation → core → feature_base → feature → appsdirection;tool/check_layers.dartwill catch violations. - Import Material APIs through
package:mui/mui.dart, which exportsmaterial_ui; avoid directpackage:flutter/material.dartimports except for the picker compatibility shim. muicomplements Material rather than replacing it: use Material when it is enough, and only add tomui(with anMprefix) when it is not.- Themes are constructed in exactly one place,
buildMuiTheme()inmui; read values fromColorScheme/TextThemeandMuiTokens.
Barrel exports and visibility
- Package barrels use bare exports (no
show). - Prefix anything you do not want to share with
_. - Mark symbols that are needed inside the package but should not be public with
@internal, andhidethem in the barrel. - Mark test-only symbols with
@visibleForTesting. - Reserve
showfor the cases where it genuinely cannot be avoided (FRB output, third-party re-exports, picker skins).
Dependency injection and state: Riverpod 3
- Use generated
@riverpod/@Riverpodproviders for DI and state. mobile/lib/main.dartmounts a singleProviderScope(retry: (_, _) => null, overrides: buildMobilePortOverrides()).- Shared packages declare unimplemented keepAlive port providers (such as file picking, HEIF decoding, notification permissions, sharing, and video playback); bind them in
mobile/lib/app/di/overrides.dart. - Process-level facades such as
AppLogger,PlatformService,KVStore/SecureKVStore,Fast*Runtime, andLegacyDatabaseGuardremain outside Riverpod. tool/check_layers.dartforbids manualProviderContainer/UncontrolledProviderScopeconstruction in productionlib/.- After changing provider definitions, run
fvm dart tool/task.dart build-runnerand commit the generated files.
Routing: go_router + extra
- Route classes all live in
moodiary_router, and each route holds alocationandparams. - The app does not target the web, so path and query parameters are not used; parameters are passed through
extrawith snake_case keys. - Keep
paramsto JSON scalars (ids, booleans and so on) — objects get snapshotted and go stale when state is restored. - Every page provides a
factory X.fromRoute(GoRouterState).
Internationalization: slang
- Use
context.l10n.xxxfor copy (it refreshes when the language changes); use the top-levell10n.xxxin services and callbacks. - Pass parameters by name and spell keys out in full — local aliases make the analyzer report keys as dead.
- App strings live in
i18n/flutter; mui strings live in its ownlib/src/i18n. After editing a*.i18n.json, runfvm dart tool/task.dart i18nand commit the generated files. - Text aimed at models (prompts, tool descriptions) is hardcoded in English and stays out of i18n.
muiships its own separate slang output (context.muiL10n).
KV storage
IKVStorage.set / remove / clearare synchronous and returnvoid.- Keys only support
int / bool / double / String / List<String>. - Widgets watch
kvValueProvider(key)orkvValueOrProvider(key, fallback)inmoodiary_storage; secrets (PINs, API keys) live inMoodiarySecureKVsand are watched viasecretKvProvider(key)(invalidate after writes). - The app lock passcode always goes through
AppLockPin— never read or writepassworddirectly.
Rust and native libraries
- Every native package owns its crate, native library, build hook,
rust-toolchain.tomlandCargo.lock. [workspace.dependencies]is not used: shared crates are pinned separately in each package, andtool/check_generated.dartverifies that the versions match.- After changing
rust/src/apiyou must runfvm dart tool/task.dart gen-rust. - Opaque handles (such as
CancelToken) cannot cross.soboundaries: each library constructs its own, after initializing that library's runtime. - Use each package's runtime entry point; images initialize at startup through
FastImageRuntime.init(), while other runtimes useensureInitialized()(crypto initializes through its facade). - Custom Kotlin / Swift integrations use Pigeon in
moodiary_native; regenerate them withfvm dart tool/task.dart pigeon. - New iOS native frameworks need privacy-manifest coverage: check
mobile/ios/scripts/embed_framework_privacy_manifests.shandmobile/ios/PrivacyManifests/(fast*frameworks userust.xcprivacy).
Commits and versions
- Commit and PR titles follow Conventional Commits, which are used for PR labels and CHANGELOG generation.
- To keep a PR out of the CHANGELOG, add
Changelog: skipin the commit body or use a skipped scope (chore(deps|readme|pr|pull)); seecliff.tomlfor the exact rules. - Keep dependency versions pinned, including melos in the root
pubspec.yaml, and align shared native pins across packages.