English
Repository structure and layers
Moodiary is a layered pub workspace monorepo: the pubspec.yaml at the root only coordinates the workspace and Melos, the app itself lives in mobile/, and the shared code sits under packages/, split into four layers along the direction of dependency.
Top-level structure
moodiary/
├── tool/ # task runner, layer and generated-code checks
├── mobile/ # Flutter app (pub name moodiary_mobile, Android + iOS)
│ └── lib/
│ ├── app/ # composition layer: DI, routing, shell, lifecycle, settings
│ └── main.dart
├── packages/
│ ├── foundation/ # layer 1: shared primitives and native libraries
│ ├── core/ # layer 2: domain-agnostic infrastructure
│ ├── feature_base/ # layer 3: reusable domain foundations
│ └── feature/ # layer 4: feature modules, independent of one another
└── pubspec.yaml # workspace + Melos config, no app codeThe four dependency layers
Dependencies flow strictly in one direction: foundation → core → feature_base → feature → apps.
foundation
Most packages here have no internal dependencies; the six fast_* packages use the shared rust_hook build package.
| Package | Responsibility |
|---|---|
moodiary_lint | Shared analyzer rules |
moodiary_logging | Logging; the disk path is injected by the composition root |
moodiary_utils | Pure helper functions and platform-independent utilities |
mui | The design system, complementing material_ui |
flutter_tiptap | Native Flutter rich-text editor compatible with TipTap JSON |
fast_core | HTTP client/server, WebDAV/S3 sync, LLM, graph layout |
fast_image | Image pipeline (thumbnails, region decoding, tiled viewing) |
fast_press | Typeset export to PDF / DOCX |
fast_tokenizer | Tokenization with jieba + HF tokenizer |
fast_crypto | AES-256-GCM + Argon2id |
fast_zip | Compression and extraction (with per-entry AES) |
rust_hook | Shared build hooks for the six Rust packages |
core
Domain-agnostic infrastructure, ordered into intra-layer tiers (a package may only depend on an earlier tier):
- Tier 0:
moodiary_i18n(slang translations and lookup entry points),moodiary_router(typed routes overgo_router),moodiary_native(Pigeon APIs for Kotlin / Swift integrations),moodiary_http,moodiary_storage(MMKV and secure KV) - Tier 1:
moodiary_platform(directories, biometrics, network state, one-shot location, device info) - Tier 2:
moodiary_files(file layout, media pipeline, and file picker port) - Tier 3:
moodiary_theme(color schemes, fonts,ThemeData),moodiary_ml(on-device ML on ONNX Runtime)
core knows nothing about domain types — Diary, Category and Font do not exist at this layer.
feature_base
Reusable domain foundations, also ordered into intra-layer tiers:
- Tier 0:
moodiary_models(Freezed domain models and DTOs),moodiary_content(diary document and media markup converters) - Tier 1:
moodiary_data(drift SQLite database, repositories, controllers) - Tier 2:
moodiary_components,moodiary_migration(one-off migrations and stranded legacy data guard),moodiary_preferences,moodiary_semantic(semantic indexing and chunking) - Tier 3:
moodiary_tools(diary tools shared by the assistant and MCP),moodiary_editor(native diary editor with autosave, toolbar, media, and metadata chrome)
feature
Feature packages that never reference each other: moodiary_diary, moodiary_sync, moodiary_export, moodiary_assistant, moodiary_media, moodiary_lock, moodiary_mcp, and moodiary_reminder.
Anything that combines features belongs in mobile/lib/app (mobile media pickers also live in mobile/lib/app/picker/, wired into shared packages through ports).
How the layering is enforced
pub can only guarantee that there are no cycles, not that dependencies point the right way. tool/check_layers.dart performs a static check against the baseline in tool/layer_baseline.txt and rejects:
- a lower layer depending on a higher one;
- same-layer dependencies outside the allowed
core/feature_basetier order and the shared Rust hook; - product code importing
materialdirectly (it has to go throughpackage:mui/mui.dart); - manual
ProviderContainerorUncontrolledProviderScopeconstruction in productionlib/.
CI runs this check in the Dart job when the PR paths affect it.
App composition and native code
mobile/lib contains app/, generated assets in gen/, and main.dart. Shared domain and feature code lives in packages/. The composition root mounts a single Riverpod 3 ProviderScope in mobile/lib/main.dart, binding platform/mobile ports via mobile/lib/app/di/overrides.dart, and wires routes.
Custom Kotlin / Swift integrations belong in moodiary_native and use Pigeon. fast_core exposes separate HTTP, sync, LLM and graph facades; their owners are defined in tool/check_layers.dart. The database uses external sqlite3_simple and sqlite3_vec packages for full-text and vector search.
Deciding where code goes
- Features never reference each other. If two of them need the same logic, push it down a layer.
- Logic that combines features goes into
mobile/lib/app. - When you add a third-party dependency, add it to the package in the layer it belongs to rather than to
mobile/.