Flutter 3.47 moved Material and Cupertino out of the SDK into material_ui and cupertino_ui, which ship weekly. The SDK imports are deprecated from the November 2026 stable release and removed in 2027, and the strict pre-push check would block every push then. The app's one Material import now comes from material_ui ^1.5.0, so everything built from here on uses the new import. Packages that still import package:flutter/material.dart (Serverpod's Flutter packages, later the rich-text editor) see the app's theme and localizations only through MaterialUiCompatibilityBridge, set in MaterialApp.builder. The bridge is deprecated on purpose, as a reminder to remove it, so its use carries a documented ignore until those packages have moved. google_fonts is removed: it was unused, and by default it downloads fonts from Google at runtime, which sends every user's IP address to Google. AGENTS.md: Material comes from material_ui. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
12 KiB
Flutter & Serverpod project
This project is a Flutter app (frontend) backed by a Serverpod server (backend). Always build the app's backend with Serverpod.
Build for multiple users, use Serverpod's built-in authentication, which is already set up in lib/server.dart.
The user starts the server and Flutter app with serverpod start. There is no need to check if the server is running: make the changes and call the serverpod MCP tools as needed. If the server is not running, an informative error message will be received from the MCP server. Then STOP and ask the user to start it. NEVER start the server yourself. The Flutter app is started along with it, or can be launched from the MCP tool spawn_flutter_app.
While running, serverpod start watches for file changes to run incremental code generation and hot reload both the server and the Flutter app.
Calling serverpod generate directly is not needed, but might be useful to troubleshoot when an incremental generation fails.
ALWAYS use the MCP server instead of the command line. Use the MCP server to:
create_migrationandapply_migrationsfor database (after you change data models).create_repair_migrationif the database has drifted out of sync with the migrations.tail_server_logsto read logs from the server.tail_flutter_logsto read the raw stdout/stderr of the Flutter app.hot_reload/hot_restartto reload or restart the server and the Flutter app. ALWAYS callhot_restartafter doing changes in the Flutter app that may not work with normal hot reload (which is automatically applied).spawn_flutter_appto start a Flutter app declared underserverpod: flutter_apps:in the serverpubspec.yaml.get_flutter_app_dtd(Dart tooling daemon) for connecting to the app through thedartMCP.
NEVER edit generated code. The server's lib/src/generated/ directory and the whole halkyon_learn_client package are rewritten by the code generator. Change the .spy.yaml models, the endpoints, or lib/server.dart instead.
Migrations are a narrow exception: the migration.sql of a generated migration MAY be edited by hand when the generated SQL would lose data — to add a data transformation, or to reach a destructive change through non-destructive steps. Never touch the other files in the migration directory, and keep the schema the SQL ends up with identical to definition.sql — new databases are created from that file and never run migration.sql.
Only when the server cannot be started at all, fall back to the CLI in the server package:
serverpod generateto regenerate the client and the generated server code.serverpod create-migrationafter changing a model with atable(add--forcefor destructive changes). It only writes the migration;serverpod startapplies pending migrations when it boots the server.
Tests need no Docker. config/test.yaml sets database.dataPath, so Serverpod starts and manages the test database (an embedded PostgreSQL) itself. Just run dart test in the server package.
Checklist after doing changes, in this order:
dart format(CLI) on the files you changedcreate_migrationandapply_migrations(MCP - only if necessary)tool/check.sh(CLI): format check,dart analyze --fatal-infos, server tests. The pre-push hook runs the same script, so a push only goes through when it passes.- Do
serverpodMCPhot_restartif required (hot reload is done automatically). Will also hot restart Flutter app - Check
serverpodMCPtail_server_logsandtail_flutter_logsfor any issues.
If the user asks you to test the app:
- Use
get_flutter_app_dtd(serverpodMCP) to get the Flutter app's DTD - Pass the DTD to
connect_dart_tooling_daemon(dartMCP) to connect to the app - Use
flutter_driver(dartMCP) to navigate through the app
The app is launched from halkyon_learn_flutter/lib/driver.dart, which starts the Flutter driver extension with text entry emulation turned off so the app stays usable by hand. To let the driver type, set enableTextEntryEmulation: true there and hot_restart the app.
Halkyon Learn
A spaced-repetition learning app: studysets of flashcards, reviewed on an FSRS schedule. Content is rich text (appflowy_editor documents) everywhere. Targets: Linux, Windows, macOS, Android, iOS. There is no web build.
- Packages:
halkyon_learn_server(endpoints, models, migrations),halkyon_learn_client(generated, never edited),halkyon_learn_flutter(the app, IDapp.halkyon.learn). - Instances: anyone may run one. The app takes the server URL from
--dart-define=SERVER_URL=…, so never hard-code a host. - Working notes: if
NEXT.mdexists in the repository root, read it first. It holds the current step, the plan and the reasoning behind each decision. It is local and never committed.
How work is done here
- The agent implements; the developer decides. Put every decision to the developer before building (design choices, alternatives, framework defaults kept or changed). The first time a new pattern appears (e.g. the first repository/gateway pair, the first synced model, the first endpoint with its denial tests), walk through it in detail with the developer; afterwards, implement exceedingly similar cases directly and point out only deviations.
- Tests come first and state the specification. Every access rule gets a test that asserts denial, not only permission.
- Explain every migration's SQL.
- Before keeping a framework default, name the alternatives and recommend one, especially where a choice becomes expensive once users or data exist.
- Every decision carries its reason (in
NEXT.mdor an ADR underdocs/adr/). - Commits are GPG-signed and carry a DCO
Signed-off-bytrailer (git commit -s; a localprepare-commit-msghook adds it automatically). - Pushes pass
tool/check.shfirst, through a localpre-pushhook (in a fresh clone:ln -s ../../tool/check.sh .git/hooks/pre-push). - Lints: LeanCode's strict set (
leancode_lint), configured once in the rootanalysis_options.yaml, which also enables its analyzer plugin. Plugins can only be enabled at the root of a pub workspace and only reach packages whose options include that file, so the server and the app include it; the generated client doesn't. Every// ignore:gets a comment saying why (document_ignores).
App architecture
- Feature-first. App:
lib/src/core/holds infrastructure shared by features,lib/src/feature/<name>/everything a user would name. Server:lib/src/<feature>/holds that feature's.spy.yamlmodels and endpoints. Code moves intocore/only once a second feature needs it. Why: a feature is added, changed or removed in one place. - Four layers per app feature, dependencies pointing strictly downward:
widget/(UI; reads bloc state, sends events) →bloc/(UI state; orchestrates repositories) →data/(repositories and gateways) →model/(immutable domain types; pure Dart, no Flutter, no I/O). A widget never calls a gateway; a model never imports a bloc. - Generated protocol classes are not domain models. They carry the envelope (
payloadas bytes);model/holds the decoded content. Mapping between them happens indata/. - Gateway / repository. A gateway is a thin boundary to one backend (e.g. the Serverpod client's endpoints) behind an
abstract interface class. A repository is what features use: it composes gateways and holds the logic. Blocs depend on repositories, never on gateways or the raw client. Why: gateways are the seams tests fake, and adding the offline layer later becomes a new local gateway, not a rewrite of every feature. - Manual dependency injection. One
Dependenciesobject is the composition root, built at startup and exposed through anInheritedWidgetscope. No service locator, no DI framework, no globals (the scaffold's globalclientmoves into it). Why: every dependency is a typed, greppable field, and nothing is resolved by magic. - One graph per context. The dependency graph belongs to one instance and one signed-in person; when either changes, a
KeyedSubtreedisposes the whole subtree and rebuilds it. Why: nothing from one person's session (blocs, streams, caches) can leak into another's. - State:
flutter_bloc, uniformly. Blocs fold repository streams into immutable states with value equality, are provided as close to their consumer as possible, and log through one globalBlocObserver. Why: the data layer is stream-shaped, event → state machines test without widgets, and one pattern everywhere is itself the point. - Time comes from
clock.now()(package:clock), neverDateTime.now(), in server and app. Why: scheduling, streaks and expiry are deterministic under test (withClock,fakeAsync), and because Serverpod itself readsclock.now()(e.g. session expiry),withClockcontrols its behaviour too. - UTC for storing and sending, local time for display and day boundaries. Serverpod sends
DateTimeas UTC and stores it intimestamp without time zonecolumns. Compare and compute in UTC; call.toLocal()only to display. "Due today", streaks and daily goals use the learner's local calendar day, computed on the client; the server never needs day boundaries. - Build configuration comes from
--dart-define. The client holds no secrets, ever. - Material comes from
package:material_ui(Cupertino frompackage:cupertino_ui), never frompackage:flutter/material.dart, which Flutter deprecates from its November 2026 release on. Packages still on the SDK's copy get the app's theme and localizations throughMaterialUiCompatibilityBridgeinMaterialApp.builder; remove it once they have moved.
Testing
- By layer: models with plain unit tests; repositories against fake gateways; blocs by asserting the emitted state sequence; widgets pumped in isolation, presentation widgets fed with ready-made data.
- Server endpoints are tested for real against the embedded Postgres (
withServerpod,dart testin the server package), including the denial tests. - Test dependencies come from a test factory (e.g.
Dependencies.test(...)filling in fakes by default), so a new dependency changes one place. Don't make dependencies nullable to spare tests: that moves null checks into production code. - Shared fakes live in
test/support/; fakes pre-stub their streams so an incidental subscription doesn't fail the test. - Editor in widget tests: host
AppFlowyEditorin a scrollable body with a fixed-height slot (an over-constrainedExpandedhangs the test), andpump(const Duration(seconds: 1))after editor changes to flush its timers. Test the document ↔ JSON round-trip as plain unit tests. - Layout-sensitive widget tests set
tester.view.physicalSizeexplicitly, so a responsive branch isn't missed for the wrong reason.
Rules the code relies on
- Authentication: server-side sessions (
ServerSideSessionsConfigFromPasswords), not JWT, for immediate revocation. Scopes are copied onto the session row, so changing a person's scopes means updating their session rows too. - Identity:
AuthUseris the person; identity providers (anonymous, GitHub) attach to it. Content referencesAuthUser, never a provider account. - Authorization lives in endpoint code; Serverpod has no row-level security. Load content filtered by the session's
authUserId, never by an owner ID the client sends. A row another person owns must be indistinguishable from a missing one. Features involving other people require theidentifiedscope, declared viarequiredScopes, never checked ad hoc. - Content envelope: content tables carry
audience,keyId(null = not yet encrypted),payload(ByteData) andnonce. Content fields live insidepayload, so the server can't sort or search by them. - Session logs are not persisted (
persistentEnabled: falsein every run mode) for privacy. Don't re-enable them. - Secrets live in
halkyon_learn_server/config/passwords.yaml(git-ignored). Never changeserverSideSessionKeyHashPepper: it would sign everyone out, and anonymous accounts can't sign back in. - Linux builds need
libwebkit2gtk-4.1-devandlibsecret-1-dev. If a Linux build tries to install to/usr/local, the CMake cache is stale: deletebuild/linux.