zakariaf/flutter-skills/service-boundary-and-native
Claude Code and agent skill by zakariaf/flutter-skills
- community
Checking that the SKILL.md file is still in the repository.
Wires every side effect and native channel as an injectable interface behind a Provider that throws UnimplementedError until the composition root overrides it, with one live impl per flavor, value-typed signatures returning typed results, hand-written contract-honouring fakes over mocks, MethodChannel quarantined to one lib/native/ directory, and versioned cross-language contracts edited on both sides in one commit. Use when adding or changing a ShareService/AnalyticsService/RemoteConfigService or any side-effect port, injecting a Clock (package:clock) via clockProvider, a MethodChannel/platform channel or native widget bridge, a flavor entrypoint (main_*.dart) or per-flavor provider override, a shared-file/JSON contract mirrored in Kotlin/Swift, replacing a stray DateTime.now() or direct SDK call inside a widget/notifier/repository, or wiring a fake via ProviderScope(overrides:) in tests.
Install
npx vskill@latest install zakariaf/flutter-skills/service-boundary-and-nativeSKILL.md
The same SKILL.md was published earlier as zakariaf/flutter-skills/service-boundary-and-native.
Service boundary and native
Every platform capability — reading "now", sharing, logging an event, fetching remote flags, calling a MethodChannel — crosses the app's layers as an injected interface. The interface names value types only; the concrete SDK lives in exactly one class; the composition root (main) wires one live impl; tests wire a deterministic fake. Abstract exactly what cannot run in a test — nothing more. This is the seam that keeps features pure, SDKs swappable, and the whole app testable headlessly.
Read the reference for the task at hand:
references/service-interface.md— typed outcomes vs bool/throw, exhaustiveness,@useResult, hand-written env-fakes, the arrow-callback Future-drop hole, single write path.references/native-channels.md— MethodChannel placement, the cross-language contract ownership table, versioned-file-vs-shared_preferencestraps, native-fast-path independence, the round-tripintegration_test.references/multi-flavor.md— line-for-line composition roots, build flavors over runtime detection, per-flavor plugin pins, the banned-dependency CI graph gate.
Run scripts/check-service-boundaries.sh and scripts/check-flavor-graph.sh before a PR.
Non-negotiable rules
- Every side effect is an injected interface, never a concrete SDK at the call site. Features, Notifiers, and repositories depend on the interface; the app imports the real SDK in exactly one live-impl class. WHY: one seam to swap, one place to quarantine platform quirks, zero SDK reach into pure code.
- Abstract only what cannot run in `flutter test`. One interface + one real impl + one fake = justified. One interface + one impl + no fake = delete the interface. WHY: interfaces "for symmetry" are dead weight that hide where the real risk (untestable I/O) is.
- Interface signatures reference value types only. Name a
DateTime, a domain value object, a sealed outcome — never a plugin type, never adart:iosymbol. WHY: keeps the interface nameable from any layer and the SDK confined to one class. - Every method returns a typed result — failure is control flow, not a swallowed exception. Model a cancel, an empty fetch, an unavailable target as a sealed outcome or
Result<T, F extends Failure>, never a thrown-and-forgotten exception. WHY: Dart requires nothrowsdeclaration, so an unhandled failure silently vanishes. Seeerror-handling-typed-resultsfor theResult/Failurespine. - The provider throws `UnimplementedError` until overridden — the provider IS the DI. No
get_it, no service locator, no second container, no business logic in the provider body. WHY: a forgotten wiring becomes a loud startup failure instead of silent null data or a live SDK opening at import. - Wire exactly one live impl per interface at the composition root.
main(per flavor) is the only place a live SDK is constructed;app.dartand every widget below are wiring-blind. WHY: the composition root is the single seam where the real world is chosen. - Tests install a hand-written fake that honours the contract — fakes over mocks. The fake's failure path must be reachable; a fake that always succeeds is a happy-path lie.
implements(notextends) so a new interface method breaks the build. WHY: a passing test must reflect real behaviour, including the failure it exists to guard. - The clock is injected via `clockProvider` (a `Clock` from `package:clock`) — "now" has exactly one source. No
DateTime.now()/math.Random()reachable from a view, Notifier, repository, or pure core; feature code readsref.read(clockProvider).now(), pure core takes aClockor the ambientclock. Never a bespokeClockService/SystemClock. WHY: this is what makes date/streak/expiry logic deterministic by overriding withClock.fixed(...). Seevalue-objects-money-and-unitsfor the injectedClock. - A mutating service feeds the single write path — persist before publish. A service that changes durable state is consumed by a repository method that commits (one transaction) before any state republishes. WHY: a crash mid-flow must never leave "acknowledged but not durable".
- Every MethodChannel lives under one `lib/native/` directory; nothing else creates one. A channel born inside a widget, repository, or Notifier is a defect regardless of how well it works. WHY: platform channels are the least testable code in the app and must be found in one place.
- A cross-language shared format is a versioned contract with one owner per side, edited on both sides in the same commit, and proven by an `integration_test`. WHY: no compiler, analyzer, or unit test catches a renamed key across the language boundary — only a real round-trip does.
The interface and its provider (Riverpod DI)
The interface is small, value-typed, and returns a typed outcome. The provider is a thin throwing wire.
The canonical smallest boundary is time — read everywhere, DateTime.now() nowhere. The one time type is `Clock` from `package:clock`, injected via clockProvider. Unlike an SDK-backed port, the clock provider safely defaults to the real thing (const Clock() opens no I/O and reaches no SDK), so it needs no override to run; tests override it with Clock.fixed(...). Do NOT define a bespoke ClockService/SystemClock.
One live impl at the composition root
main is the only place a live SDK is constructed. The concrete SDK import appears only inside the live-impl class.
When multi-package (workspace): the interface lives in a shared foundation package; the live impl andmainlive in the app package. In a single-package app all three are folders underlib/. Seeproject-structure-and-packages.
When multi-flavor: ship one thinmain_<flavor>.dartper flavor over a single flavor-blindapp.dart. Eachmainoverrides the same provider list in the same order — only the impl on each right-hand side changes — so the two files diff line-for-line. Real build flavors (Android product flavors + iOS schemes), never runtime detection. Seereferences/multi-flavor.md.
Fakes over mocks
A hand-written fake that implements the interface and models the ways the world breaks. No mock framework; no codegen.
The clock needs no hand-written fake — package:clock supplies Clock.fixed(...) (and withClock for pure code):
The native boundary
A MethodChannel is quarantined to lib/native/, wrapped by a thin `Gateway`, and exposed through the same injectable-interface seam. (A Gateway names a thin wrapper over a specific plugin/SDK or a MethodChannel; a Service names a capability interface you define — see naming-conventions.) Keep the native side able to run without the Dart engine alive where latency demands it.
Every write path that changes a mirrored value republishes as part of the write, never as a follow-up someone remembers — a delete/clear republishes exactly as hard as a save. See references/native-channels.md for the ownership table, the shared_preferences traps, and the round-trip test that proves the mirror.
Anti-patterns
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/service-boundary-and-native/SKILL.md
Popularity
- Repository stars
- 22
- Repository forks
- 4
- 7-day trend score
- 16
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/zakariaf/flutter-skills/service-boundary-and-native)