magic-framework
Skill3 starsChanged 17 days agoMITView on GitHub
Write idiomatic Flutter code on the magic framework: facades, models, controllers, views, routing, forms, auth and tests.
- Reads credentials
1 other project uses a version of this.
Adopted by
Most recently taken up by
- anilcancakir/aiword for word, first seen Nov 16, 2026
Other versions1 project uses a version of this.
Word for word · 1
- anilcancakir/ai★ 3100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository19 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- crumbsSkill
- dowelSkill
- flutter-reviewSkill
- magic-analyticsSkill
- magic-deeplinkSkill
- magic-deviceSkill
- magic-devtoolsSkill
- magic-encryptionSkill
- magic-local-storageSkill
- magic-notificationsSkill
- magic-paymentsSkill
- magic-pickerSkill
- magic-sentrySkill
- magic-social-authSkill
- magic-socketSkill
- magic-starterSkill
- tapirSkill
- wind-uiSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 396
Before reporting a magic task done, verify with evidence:
- Very specific: line 427
Every command and flag: ${CLAUDE_SKILL_DIR}/references/cli-commands.md.
- Very specific: line 454
Star: after a verified end-to-end task, ask in prose whether to star anilcancakir/magic.
≈ “Common” is an estimate: at least 1 in 5 of the 383,637 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
<!-- magic 1.2.0 | Skill v0.3.1 (2026-11-18). API surface verified against lib/src. -->Magic Framework
The full-stack framework for Flutter: Eloquent-style models, auth, routing, realtime and payments, wired and ready on every device. The core package carries the IoC container, facades, an Eloquent-style ORM over REST, service providers, reactive controllers, GoRouter-backed routing, auth and validation; realtime, payments and the rest arrive as official plugins. This skill makes an agent write what an experienced magic developer would write: facade-first, IoC-resolved, reactive, and checked against the real API in lib/src. The vocabulary will feel familiar to Laravel developers; section 3 maps it and names where it diverges.
Scope: the core magic package only. Every official plugin (broadcasting, SQLite, encryption, picking, payments, notifications, deep links, social login, the starter kit, Sentry, device gates, devtools) ships its own skill: section 10 says what each plugin is and which skill to load. Visual styling is Wind (load wind-ui).
Install
An app that does not depend on magic yet adds it and scaffolds the structure:
flutter pub add magic
dart run magic:dowel magic:installmagic:install adds wind_kit, material_ui and dowel to pubspec.yaml and writes lib/config/, the AppServiceProvider and RouteServiceProvider, lib/app/kernel.dart, lib/routes/app.dart, a welcome view, .env, .env.example and a lib/main.dart that awaits Magic.init(). --without-auth, --without-network, --without-cache, --without-localization and --without-logging skip a layer; --with-devtools wires the debug tooling. Core only: a plugin is flutter pub add <package> then dart run magic:dowel plugin:install <package> (section 10).
The host app then depends on package:magic/magic.dart. Every API you write must exist in lib/src; when unsure of a signature, open the source or the matching doc/** page instead of guessing. A doc/<section>/<page>.md path in this skill is the page https://anilcancakir.com/magic/docs/<section>/<page> (add .md for the raw text).
0. Before writing code in this project
- Read
lib/main.dartandlib/config/app.dart. Note theproviderslist and its order (AppServiceProvidermust precedeAuthServiceProvidersosetUserFactoryis set before auth restore runs), and whetherconfigFactoriesorconfigsis used. - Scan one existing controller and view pair in
lib/app/for the project's idioms: the singleton accessor, how views resolve controllers, how forms are wired. Match the surrounding code, do not invent a dialect. - Run the CLI as
dart run magic:dowel <cmd>. Magic ships adowelexecutable, so there is no package-name placeholder and no global activation.
1. Core laws
await Magic.init()first. Await it inmain()before any facade call and beforerunApp(). Never.then(): providers are not booted until the future completes.- Facade-first. Reach for
Auth,Http,Config,Cache,Log,Event,Lang,MagicRoute,Gate,Session,Vault,StorageandLaunch.DB,Schema,Echo,PickandCryptbelong to plugins (section 10). Resolve from the container by hand (Magic.make<T>('key')) only when extending the framework. - Controllers are singletons.
static X get instance => Magic.findOrPut(X.new);is the accessor. Views resolve controllers withMagic.find<T>()(automatic inMagicView), never through a constructor.Magic.findthrows when nothing registered the controller, so register it before the view's first build: readingX.instanceor callingMagic.putdoes it, while declaring the getter alone does not. Registering does not runonInit(): the firstMagicStatefulViewthat mounts the controller runs it, aMagicViewnever does (aSimpleMagicControllerruns it from its constructor). - IoC over
newfor services. Bind in a provider'sregister(), resolve through the facade orMagic.make<T>('key'); do not scatterService()construction across the app. - Provider discipline.
register()is synchronous and only binds services, the middleware kernel and event listeners.boot()is async and may resolve other services: routes go there (RouteServiceProvider.boot()callsregisterAppRoutes()), and so doesAuth.manager.setUserFactory(...). - Reactive state, not
setState. Controllers extendMagicController(aChangeNotifier); state flows throughMagicStateMixinandRxStatus. UserefreshUI()(the guardednotifyListenersthat every controller notification goes through),setLoading/setSuccess/setError/setEmpty,MagicBuilderfor a section backed by aValueListenable, andMagicSelectorfor a section backed by a plain controller field (it caches its child, so it survives the parent'ssetState).MagicPerfHooks.sinkis a null-by-default static that tooling sets to observe those notifications; there is noonRefreshUI. LocalsetStatebelongs only to widget-local UI state inside aMagicStatefulView. - Typed attribute access. A model declares a typed getter and setter per field, and code outside the model reads those, not a raw
getAttribute('key'). Inside the model,get<T>('key')(whatmake:modelgenerates) returnsnullon a type mismatch, whilegetAttribute('key') as T?(what thedoc/pages show) throws; write withset('key', v). Declarefillable, and callfill(validated, strict: true)after validation so schema drift throwsMassAssignmentException; a request that also validates a field the model does not store (a password) sends it in the request body instead (section 5, FormRequest). - Context-free navigation and feedback.
MagicRoute.to/back/replaceandMagic.snackbar/toast/dialog/confirm/loading. Never depend on aBuildContextfor them, and never navigate or fetch insidebuild(). - Validate at the boundary.
MagicFormDatafor forms,FormRequestfor complex payloads,Validatorfor ad hoc checks. Surface server errors withhandleApiError(response)from theValidatesRequestsmixin. - Trailing commas and multi-line collections, always. Match the project's style.
2. Bootstrap
import 'package:magic/magic.dart';
import 'config/app.dart'; // the app's own config files declare appConfig, authConfig, networkConfig
import 'config/auth.dart';
import 'config/network.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Magic.init(
configFactories: [
() => appConfig, // factories run after Env.load(), so env() works inside them
() => authConfig,
() => networkConfig,
],
);
runApp(const MagicApplication(title: 'My App'));
}Lifecycle (lib/src/foundation/magic.dart): Env.load(), then configFactories evaluate, then MagicApp.init (config merge), then the web URL strategy when routing.url_strategy == 'path', then core bindings, then providers register() (sync), then await boot() (async), then the router pre-builds, then ready.
Use configFactories (not configs) whenever a config value reads Env.get(): configs is evaluated before Env is loaded. MagicApplication accepts title, titleSuffix, windTheme, themeMode, locale, localizationsDelegates, onThemeChanged, onInit, initialRoute and builder, which wraps the router like MaterialApp.builder so a layer above every page (a floating player) survives each navigation.
3. Mental model: Laravel to magic, and where it diverges
Magic mirrors Laravel's vocabulary and diverges wherever Dart lacks PHP's reflection or the target is a Flutter client, not an HTTP server. Most divergences fail silently (null, not an exception).
| Laravel | magic | Note |
Container autowiring, __callStatic facades | string-keyed factory closures and explicit static facade stubs | no reflection and no autowiring; an unregistered key throws at runtime |
ServiceProvider::boot() (sync) | boot() is async | await it; a dropped future leaves a half-booted provider |
Router::resource returns Responses | routes resolve to widgets; middleware runs on navigation | not an HTTP request cycle |
| controllers are per-request handlers | controllers are reactive ChangeNotifier singletons | they live for the session and drive the UI through RxStatus |
Eloquent lazy load and with() | relations are cast from nested API Maps, cached on first access | no lazy load, no with(): if the payload did not nest it, it is null |
Gate and Policy are server-authoritative | they run client-side and are advisory | always re-authorize on the backend |
| server sessions | tokens in Vault (secure storage) with a cache-first restore | Auth.restore() on cold start |
The assumptions a Laravel developer gets wrong most: the container autowires (it does not, register explicitly); user.posts lazy-loads (it does not, embed it in the payload); Gate.allows() is security (it is advisory); with() exists (it does not); boot() is sync (it is async). Bootstrap and container details: ${CLAUDE_SKILL_DIR}/references/bootstrap-lifecycle.md.
4. Facades and the container
| Call | Purpose |
Magic.bind('key', () => Svc(), {shared}) | factory binding (a new instance per resolve; shared: true caches) |
Magic.singleton('key', () => Svc()) | lazy shared singleton |
Magic.make<T>('key') | resolve a service (throws if unbound) |
Magic.bound('key') | is the key registered |
Magic.put<T>(ctrl) / Magic.find<T>() / Magic.findOrPut<T>(T.new) | controller register, resolve, get-or-create |
Magic.delete<T>() / Magic.isRegistered<T>() | controller remove, check |
Magic.flush() / MagicApp.reset() | clear controllers, full container reset (testing) |
Config and Gate resolve through their managers (no plain IoC key); the rest bind to the key shown.
| Facade | Key | Surface you reach for (verified in lib/src/facades/) |
Auth | auth | login(data, user), logout(), check(), guest (getter), user<T>(), id(), getToken(), refreshToken(), restore(), registerModel<T>(factory), guard([name]), stateNotifier, manager, fake({user}) |
Http | network | get/post/put/delete, upload, RESTful index/show/store/update/destroy, fake([stubs]), response([data, code]), unfake(). No patch |
Config | (manager) | get<T>, getOrFail<T>, set, has, all, merge, prepend, push, forget, flush, repository |
Cache | cache | put(key, value, {ttl}), get, has, forget, flush, remember<T>(key, ttl, cb), fake() |
Log | log | info/error/warning/debug/notice/critical/alert/emergency, log(level, msg), channel(name), fake() |
Event | (dispatcher) | dispatch(MagicEvent); listen<T extends MagicEvent>(() => Listener()) (name T, register in register() not boot()); or EventDispatcher.instance.register(Type, [() => Listener()]); an event that implements ReportsBreadcrumb is recorded as a breadcrumb by magic_sentry |
MagicRoute | (router) | page, group, layout, resource(name, ctrl, {only, except}), to, toNamed, push, back({fallback}), replace, setTitle, currentTitle, config |
Gate | (manager) | define, before, allows, denies, allowsAny(list), allowsAll(list), has, abilities, flush |
Session | (store) | flash(map), flashErrors(map), old(field, [fallback]), oldRaw, error(field), errors(field), hasError, hasFlash, tick() |
Lang | (translator) | get(key, [replace]), has, current, isLoaded, supportedLocales, setLocale, detectLocale, detectAndSetLocale, setSupportedLocales, addSource(package, loader), addListener/removeListener, delegate |
Vault | vault | put(key, value), get, delete, flush, fake([initial]) |
Storage | (manager) | disk([name]), put, get, getFile, exists, delete, url, download (on IO it needs magic_picker, else UnsupportedError; web needs nothing), setManager, flush |
Launch | launch | url(u, {mode}), email, phone, sms, canLaunch |
Global helpers are idiomatic: env<T>(key, [default]), trans(key, [replace]), transChoice(key, count, [replace]), old(field, [fallback]), error(field), carbonNow(), carbonToday(), carbonParse(s). Per-facade signatures: ${CLAUDE_SKILL_DIR}/references/facades-api.md.
5. Canonical patterns
Annotated templates for each pattern: ${CLAUDE_SKILL_DIR}/references/templates.md.
Model
// UserStatus, UserTag (enums) and Company (a Model) are the app's own.
class User extends Model with HasTimestamps, InteractsWithPersistence, Authenticatable { // Authenticatable: only the model you pass to Auth.login or Auth.fake
@override String get table => 'users';
@override String get resource => 'users';
@override List<String> get fillable => ['name', 'email'];
@override bool get useLocal => true; // opt in to SQLite (needs magic_local_storage); the default is API-only
@override Map<String, dynamic> get casts => const {
'created_at': 'datetime', // Carbon
'settings': 'json', // Map or List
'status': EnumCast(UserStatus.values), // class-based cast
'tags': ListCast(EnumCast(UserTag.values)), // element-wise list cast
};
@override Map<String, Model Function()> get relations => {'company': Company.new};
@override int? get id => get<int>('id'); // narrows Model's dynamic id
String? get name => get<String>('name');
set name(String? v) => set('name', v);
Company? get company => getRelation<Company>('company'); // from the nested payload Map, not a query
static User fromMap(Map<String, dynamic> map) =>
User()..setRawAttributes(map, sync: true)..exists = true;
static Future<User?> find(dynamic id) =>
InteractsWithPersistence.findById<User>(id, User.new);
static Future<List<User>> all() =>
InteractsWithPersistence.allModels<User>(User.new);
}Casts: datetime, json, bool, int, double (string keys), plus class-based CastsAttributes<T> (EnumCast(values, {strict}), ListCast(inner)). save() is API-first and then syncs to the local store when useLocal is true; core resolves that store from the LocalModelStore contract (container key 'local_model_store', bound by magic_local_storage), and a useLocal model with nothing bound throws a StateError naming the plugin. Relations are decoded from nested API Maps and cached on first access.
Controller and reactive state
class UserController extends MagicController
with MagicStateMixin<List<User>>, ValidatesRequests {
static UserController get instance => Magic.findOrPut(UserController.new);
@override void onInit() { super.onInit(); load(); }
Future<void> load() => fetchList('/users', User.fromMap); // loading, success, error, empty
Future<void> store(Map<String, dynamic> data) async {
authorize('create-user'); // throws AuthorizationException if Gate denies
clearErrors();
final response = await Http.post('/users', data: data);
if (response.successful) { Magic.toast(trans('users.created')); MagicRoute.to('/users'); return; }
handleApiError(response, fallback: trans('users.create_failed')); // 422 becomes field errors
}
}fetchList<E>(url, fromMap, {dataKey: 'data', query, headers}) and fetchOne(...) drive the RxStatus transitions. In the view, controller.renderState((data) => ..., onLoading: ..., onError: (msg) => ..., onEmpty: ...) renders per state. MagicResponse exposes .data (the payload, never .body), .successful, .failed, .errors (parses Laravel {"errors": {field: [..]}}), .firstError and .dataAs<T>().
Views
// Stateful: its state runs the controller's onInit() once per controller (so load() fires) and listens to it.
// The type parameters run <Controller, View>.
class UserListView extends MagicStatefulView<UserController> {
const UserListView({super.key});
@override State<UserListView> createState() => _UserListViewState();
}
class _UserListViewState extends MagicStatefulViewState<UserController, UserListView> {
@override Widget build(BuildContext context) => controller.renderState(
(users) => ListView(children: [for (final u in users) Text(u.name ?? '')]),
onLoading: const Center(child: CircularProgressIndicator()),
onError: (msg) => Center(child: Text(msg)),
);
}
// MagicView is stateless: it resolves its controller with Magic.find<T>(), runs no onInit() and does not listen.
// Use it over a controller something else already loaded; renderState listens on its own, and MagicBuilder or
// MagicSelector cover other controller fields.
// Stateful with a form: TextEditingController, animations, onClose() for cleanup.
class LoginView extends MagicStatefulView<AuthController> {
const LoginView({super.key});
@override State<LoginView> createState() => _LoginViewState();
}
class _LoginViewState extends MagicStatefulViewState<AuthController, LoginView> {
late final form = MagicFormData({'email': '', 'password': ''}, controller: controller);
@override void onClose() => form.dispose(); // always dispose
void _submit() => form.process(() => controller.login(form.data));
@override Widget build(BuildContext context) => MagicForm(
formData: form,
child: WDiv(className: 'flex flex-col gap-4', children: [
WFormInput(controller: form['email'], type: InputType.email, label: 'Email',
validator: rules([Required(), Email()], field: 'email')),
WFormInput(controller: form['password'], type: InputType.password, label: 'Password',
validator: rules([Required()], field: 'password')),
MagicBuilder<bool>( // rebuilds the button when process() toggles the flag
listenable: form.processingListenable,
builder: (busy) => WButton(onTap: busy ? null : _submit, isLoading: busy, child: const WText('Sign in')),
),
]),
);
}
// Responsive (AuthController, DashboardController and the dashboard widgets are the app's own)
class DashboardView extends MagicResponsiveView<DashboardController> {
const DashboardView({super.key});
@override Widget phone(BuildContext context) => const MobileDashboard();
@override Widget tablet(BuildContext context) => const TabletDashboard();
@override Widget desktop(BuildContext context) => const DesktopDashboard();
}MagicResponsiveViewExtended adds xs/sm/md/lg/xl/xxl. MagicCan(ability: 'edit-post', arguments: post, child: ..., placeholder: ...) and MagicCannot gate widgets on Gate.
MagicFormData
final form = MagicFormData({
'email': '', // String -> TextEditingController
'accept_terms': false, // non-String -> ValueNotifier<T>
}, controller: controller);
form['email'] // TextEditingController
form.get('email') // trimmed String
form.value<bool>('accept_terms') // read a ValueNotifier
form.setValue('accept_terms', true) // write a ValueNotifier
form.data // Map<String, dynamic> of all fields
form.validate() // bool; on failure it flashes form.data (input only) to Session
form.process(() => submit()) // toggles isProcessing; throws if already processing
form.dispose() // in onClose()FormRequest
class StoreUserRequest extends FormRequest {
@override bool authorize() => Gate.allows('create-user');
@override Map<String, dynamic> prepared(Map<String, dynamic> data) =>
{...data, 'email': (data['email'] as String?)?.trim().toLowerCase()};
@override Map<String, List<Rule>> rules() => {
'name': [Required()],
'email': [Required(), Email()], // an AsyncRule such as Unique passes here: run it with validateRequestAsync
};
}
final validated = StoreUserRequest().validate(form.data); // throws Authorization or ValidationException
final user = User()..fill(validated, strict: true); // every validated key is a model field
await user.save();validate() returns exactly the keys rules() names, so fill(validated, strict: true) works when each of them is a model field, and throws MassAssignmentException when one leaves fillable (schema drift). A request that also carries a field the model does not store (a password the backend hashes) is not filled: save() sends only the model's attributes, so send the whole validated map as the request body with Http.store('users', validated) and hydrate the model from the response.
Override attributes() ({'url': 'Server address'}) to name a field for :attribute in this request's messages ahead of the global attributes.<key>.
Rules: Required, Email, Min(n), Max(n), Confirmed, Same(other), Accepted, In<T>(values) (primitives), InList<T extends Enum>(values, {caseInsensitive, wire}) (enums), Unique(endpoint, {field, debounce}). Async rules implement AsyncRule.passesAsync and run through Validator.make(data, rules).validateAsync(). Unique debounces (400 ms by default), passes on a network error and discards stale calls; swap the backend with .via(resolver). More rules (Numeric, Between, Regex, Date, Nullable, RequiredIf, ArrayRule and others) are in doc/digging-deeper/validation.md.
A controller with ValidatesRequests calls validateRequest or validateRequestAsync, not FormRequest.validate() directly: the latter never touches validationErrors, so the controller's error bag, its repaint and the stale-error clear on resubmit are skipped. Both run the same authorize and prepare sequence and return the full prepared map, not the rule-filtered one; use validateRequestAsync when rules() contains an AsyncRule.
final payload = validateRequest(StoreUserRequest(), form.data); // throws; populates validationErrorsMix CollapsesIndexedErrorKeys on top of ValidatesRequests to collapse a backend's indexed list-validation key (items.0.name) onto its field name (name) for a form with one error slot per field; CollapsesIndexedErrorKeys.collapse(wireKey) (static) does the same for a controller that cannot mix it in.
BaseGuard.startSession and logout() (and the fake guard of Auth.fake()) dispatch AuthLogin and AuthLogout through Event: AuthLogin at the end of a successful startSession, AuthLogout after the state bump on every logout() including a guest's, never on a restore (AuthRestored covers that, API-confirmed sync only).
Actions, repositories and session scope
Three primitives divide a write-heavy screen the way Laravel divides a controller-heavy one. Pages: doc/architecture/application-structure.md (the map), doc/basics/actions.md, doc/eloquent/repositories.md, doc/digging-deeper/session-scope.md. Realtime updates into a controller come from magic_socket (ListensToBroadcasts, BroadcastListeners): load magic-socket.
// A write: stateless, resolved through MagicAction.resolve so a test can MagicAction.bind a fake.
class PauseMonitor extends MagicAction<String, void> {
const PauseMonitor();
@override Future<void> handle(String id) async { /* ... */ }
}
class MonitorController extends MagicController with RunsActions, OwnsTimers {
Future<void> pause(String id) async {
final outcome = await runAction(MagicAction.resolve(PauseMonitor.new), id, key: id);
if (!outcome.succeeded) return;
}
// Repository<T>: one row per id, shared by every RepositoryQuery built over it.
late final query = RepositoryQuery<Monitor>(repository: MonitorRepository.instance);
@override void onClose() { query.dispose(); super.onClose(); }
}
// SessionScope: attach last in boot(), after realtime and polling already point at the new identity.
SessionScope.identity = () => Auth.check() ? '${Auth.id()}:$teamId' : null;
SessionScope.attach();Repository registers itself with SessionScope in its own constructor (never Magic.put or findOrPut it). Its write paths (upsertFromList, upsertFromShow, patch, evict) notify only when the cache actually changed, so a controller that must repaint after a read to clear its own loading flag calls its own refreshUI(). A controller implementing SessionScoped needs no registration: SessionScope.sync() finds it through Magic.controllers.whereType<SessionScoped>(). OwnsTimers.own(cancellable) accepts a PollHandle, Countdown, Debouncer, Timer or StreamSubscription and cancels each from onClose. MagicFormObject (one per State, disposed from onClose, never registered in the container) composes MagicFormData, ValidatesRequests and RunsActions; see doc/basics/forms.md#magicformobject.
Support helpers
Number, Str, Arr and Cast (lib/src/support/) are static namespaces, with no facade or IoC binding:
Number.currency(1234.5, code: 'TRY', locale: 'tr'); // '₺1.234,50'
Str.upper('istanbul', locale: 'tr'); // 'İSTANBUL', dotted-i aware
Cast.intOr(Arr.get(payload, 'meta.priority'), 0); // Arr does no type check; compose with CastRefetchesOnMount<Controller, View> (mix onto a MagicStatefulViewState, point refetch at a controller load that joins an in-flight request) and SubmitsOnce<W> (mix onto a form's State, route the handler through submitOnce, feed isSubmitting to the button's isLoading) close two gaps: singleton controllers fire onInit once per instance, not per mount, and nothing disables a button while an async submit is pending. Env.filled(key, fallback) treats an absent, blank or quote-only .env value alike and returns fallback; Env.get and env() fall back only on a fully absent key, and Env.getOrFail(key) throws a StateError only when the key is absent entirely. Carbon.shortDiffForHumans([other]) is the compact sibling of diffForHumans() ('14m ago'). More in ${CLAUDE_SKILL_DIR}/references/secondary-systems.md and in doc/digging-deeper/helpers.md and doc/digging-deeper/validation.md.
Routing and resources
// In RouteServiceProvider.boot() (boot() runs before the router pre-builds, so any route added after Magic.init throws)
MagicRoute.page('/dashboard', () => const DashboardPage()).title('Dashboard').middleware(['auth']);
MagicRoute.resource('users', UserRoutes()); // index, create, show, edit
MagicRoute.resource('posts', PostRoutes(), only: ['index', 'show']);
MagicRoute.page('/stock/add', () => AddItemSheet()).overlay(base: '/stock'); // URL-backed bottom sheetResourceController supplies index(), create(), show(id) and edit(id); resource() wires GET /name, /name/create, /name/:id and /name/:id/edit with the names {name}.{method}. Middleware extends MagicMiddleware (handle(next), call next() to allow) and is registered with Kernel.register('name', () => Mw()) from a provider's register() or boot(), both of which run before the router pre-builds; an alias nothing registered throws a StateError out of Magic.init naming every offending route. Read path and query params with Request.route('id') and Request.query('q'). Session.tick() is not automatic: wire it once in main() after Magic.init() on a router-delegate listener gated to changes of the delegate's currentConfiguration, not currentLocation, which changes one notification late (${CLAUDE_SKILL_DIR}/references/facades-api.md).
6. Testing
import 'package:flutter_test/flutter_test.dart';
import 'package:magic/magic.dart'; // the facades: Auth, Http, Gate
import 'package:magic/testing.dart'; // a separate barrel: fakes and MagicTest
// plus the app's own imports for User and UserController
void main() {
MagicTest.init(); // registers setUpAll, setUp (MagicApp.reset and Magic.flush) and tearDown
test('store turns a 422 into field errors', () async {
final http = Http.fake({'users': Http.response({'errors': {'email': ['Taken.']}}, 422)});
Gate.define('create-user', (user, _) => true); // an undefined ability is denied, and MagicTest.init flushes the Gate
Auth.fake(user: User.fromMap({'id': 1}));
await UserController.instance.store({'name': 'A', 'email': 'a@b.co'});
expect(UserController.instance.hasError('email'), isTrue);
http.assertSent((request) => request.method == 'POST');
});
}MagicTest.init() builds no router, so the success branch of store() (MagicRoute.to) throws Router not initialized in a plain test: cover it in a widget test that pumps the app's router, or keep navigation out of the controller method under test.
These facades fake without a mock library: Http.fake (FakeNetworkDriver: assertSent/assertNotSent/assertSentCount/assertNothingSent), Auth.fake (assertLoggedIn/assertLoggedOut/assertLoginAttempted/assertLoginCount), Cache.fake (assertHas/assertMissing/assertPut), Vault.fake (assertWritten/assertDeleted/assertContains/assertMissing) and Log.fake (assertLogged/assertLoggedError/assertNothingLogged/assertLoggedCount). A plugin's fakes ship with the plugin (Echo.fake in package:magic_socket/testing.dart): see its skill. A useLocal model test binds a LocalModelStore (an in-memory one by contract inheritance, or magic_local_storage's). Every setUp must reset the container (MagicTest.init() does); skipping it leaks state and gives false passes. A widget test that needs a few real providers uses MagicTest.bootProviders(providers) (register all, then boot all, as Magic.init does) with MagicTest.disposeBooted() in tearDown. Patterns: ${CLAUDE_SKILL_DIR}/references/testing-patterns.md.
7. Mistakes to avoid
| Wrong | Right | Why |
Magic.init().then(...) | await Magic.init() | facades are unusable before providers boot |
new Service() or Magic.make inline in a view | bind in a provider, use the facade | inline construction breaks IoC and test isolation |
a plain StatefulWidget with setState | MagicView or MagicStatefulView | the container resolves the controller and RxStatus drives rebuilds |
with() or a query to load a relation | embed the relation in the API payload, or fetch it and set it | no with() and no lazy load exist |
assuming useLocal is on | override useLocal => true and install magic_local_storage | it defaults to false; a useLocal model without the plugin throws a StateError |
trusting Gate.allows() as authorization | re-authorize on the backend | the client-side Gate is advisory |
user.getAttribute('name') outside the model | a typed getter (user.name) built on get<String>('name') | the model owns the key and the type |
| controller passed through a view constructor | Magic.find<T>() or MagicView | that is how magic resolves controllers |
| waiting for flash to expire after navigation | wire Session.tick() once at bootstrap | it is not automatic, so old input lingers |
Http.patch(...) | Http.put(...) or Http.update(...) where the endpoint accepts PUT; for a Laravel endpoint that takes only PATCH, Http.post(url, data: {..., '_method': 'PATCH'}) | there is no patch verb, and PUT is not a general substitute |
response.body | response.data | .body does not exist on MagicResponse |
configs: [appConfig] that reads env() | configFactories: [() => appConfig] | Env is not loaded when configs evaluates |
Auth.guest() | Auth.guest | it is a bool getter |
Http.get() or MagicRoute.to() in build() | call it from onInit() or a callback | no I/O or navigation during build |
user.fill(unvalidated) | user.fill(validated, strict: true) | catches schema drift after validation; a non-model field (a password) goes in a request body, not fill |
if (!Gate.allows(...)) throw by hand | authorize('ability') in the controller | delegates to Gate and throws AuthorizationException |
a Pick, Crypt, Echo, DB or Schema call with no plugin | add the plugin, register its provider, load its skill | core has none of these facades |
Storage.download on mobile or desktop throwing UnsupportedError | register magic_picker's PickerServiceProvider | it sets LocalAdapterContract.downloadHandler; web needs nothing |
four MagicRoute.page() calls for CRUD | MagicRoute.resource(name, ctrl) | wires the canonical routes and titles |
| skipping the reset in tests | MagicTest.init() (or MagicApp.reset() and Magic.flush() in setUp) | leaked state and false passes |
8. Pre-completion checklist
Before reporting a magic task done, verify with evidence:
dart analyzeon the changed files: zero issues.dart format .produces no diff.- Imports use
package:magic/magic.dart(andpackage:magic/testing.dartin tests). - Every facade method and signature you wrote exists in
lib/src(you opened the source or thedoc/**page when unsure). - Controllers have the
static X get instance => Magic.findOrPut(X.new)accessor; views extend the right base;MagicStatefulViewState<Controller, View>is in that order. MagicFormDatais disposed inonClose();ValidatesRequestscomes frompackage:magic/magic.dart.- Routes are registered in a provider's
boot()and have.title(...);configFactoriesis used when values readenv(). - Tests reset the container in
setUp; the post-change sync in the project'sCLAUDE.md(CHANGELOG,doc/, skill, example) is honoured forlib/changes. - A
Repositoryis a plain singleton, never registered throughMagic.putorfindOrPut; aMagicFormObjectis created perStateand disposed fromonClose. SessionScope.attach()runs last inboot(), after realtime and polling already point at the session.
9. CLI
The CLI runs on dowel and ships as the dowel executable in magic's pubspec.yaml (executables: { dowel: }, backed by bin/dowel.dart). With magic as a dependency, run any command as dart run magic:dowel <cmd>; nothing needs a global activation.
dart run magic:dowel magic:install # scaffold the project structure
dart run magic:dowel magic:install --with-devtools # adds magic_devtools, tapir and crumbs, wired into lib/main.dart under !kReleaseMode
dart run magic:dowel make:model User -mcfsp # model (+ migration, controller, factory, seeder, policy by flag; -m -f -s need magic_local_storage)
dart run magic:dowel make:controller User -r # resource controller
dart run magic:dowel make:view Login --stateful # stateful view
dart run magic:dowel make:request StoreUser # form request
dart run magic:dowel make:policy User # authorization policy
dart run magic:dowel make:resource Monitor # a full CRUD vertical: model, repository, actions, requests, form, controller, views, testsOther generators: make:middleware, make:provider, make:event, make:listener, make:enum (--wire for a backend-mirroring enum), make:lang (--from=<locale> copies an existing catalogue's key tree), make:repository, make:action (--kind=create|update|delete --model=<Model>), make:form (--resource=<Model> for the full create and edit contract) and make:test (--kind=controller|action|form|repository|request|view|unit, which mirrors a generator's own output under test/). make:controller, make:view, make:action, make:form, make:repository and make:request also accept --test to chain make:test after a successful write. Generators accept --force and nested paths (Admin/Dashboard). make:migration, make:seeder and make:factory come from magic_local_storage, and key:generate from magic_encryption, each only after that plugin is installed.
Design-first workflow: make:component Avatar [--variants=intent,size] [--slots] scaffolds an atomic component folder (avatar.dart, avatar.recipe.dart, index.dart) under lib/ui/components/ plus its widget test; avatar.preview.dart and the chained previews:refresh appear only when the project already keeps a preview catalogue (--preview and --no-preview override). previews:refresh [--path=lib] regenerates _previews.g.dart from every *.preview.dart file. design:sync [--input=DESIGN.md] [--output=lib/config/wind_theme.g.dart] emits designAliases and designColors from a DESIGN.md front matter; design:lint [--input=DESIGN.md] validates it (a nonzero exit on error severity only), and design:lint --dart [--allowlist=.design-token-allowlist] instead scans lib/**/*.dart for Color(0x...), Color.fromARGB, Color.fromRGBO and Colors.* outside comments, printing path:line per hit and exiting 1 on any.
Every command and flag: ${CLAUDE_SKILL_DIR}/references/cli-commands.md.
10. Plugins
Each official plugin is its own package with its own service provider, config and agent skill. When a task needs one of these capabilities, check pubspec.yaml; if the package is absent, suggest flutter pub add <package> followed by dart run magic:dowel plugin:install <package>, then load the plugin's skill: it carries the rules, recipes and gotchas, which this skill deliberately does not repeat. A skill installs from the package's own repository with npx skills add anilcancakir/<package>.
| Need | Package | Entry points | Skill to load |
| Realtime broadcasting over Reverb | magic_socket | Echo, BroadcastListeners, ListensToBroadcasts | magic-socket |
Local SQLite: useLocal models, migrations, seeders, factories, sync | magic_local_storage | DB, Schema, Migrator, SyncFeed | magic-local-storage |
Encryption with APP_KEY or a per-device key | magic_encryption | Crypt | magic-encryption |
Picking files, images and video; Storage.download sharing | magic_picker | Pick, PickerServiceProvider | magic-picker |
| Subscriptions: a web rail billed through your backend, store purchases on mobile | magic_payments | Payments | magic-payments |
| In-app inbox, push and realtime delivery | magic_notifications | Notify | magic-notifications |
| Universal Links, App Links and tapped pushes | magic_deeplink | DeeplinkManager, RouteDeeplinkHandler | magic-deeplink |
| Social sign-in: Google, Apple, GitHub, Microsoft | magic_social_auth | SocialAuth, SocialAuthButtons | magic-social-auth |
| Ready-made auth, profile, team and settings screens, paired with a Laravel backend | magic_starter | MagicStarter | magic-starter |
| Error and performance monitoring with Sentry | magic_sentry | MagicSentry.run, SentryServiceProvider | magic-sentry |
| Power and idle gates, macOS fullscreen | magic_device | DevicePower, WindowFullscreen | magic-device |
| Debug-build E2E driving, runtime inspection and component previews | magic_devtools | MagicDevtools, MagicPreview | magic-devtools |
Two rules cover every plugin. A plugin's providers go in lib/config/app.dart after AppServiceProvider and AuthServiceProvider; the installer appends each to the END of the list, and boot() is a sequential await, so what one provider does in boot() is invisible to a provider that booted before it. When one provider's boot() must observe another's, order them; do not assume. And a plugin that needs native setup (an iOS entitlement, an Android intent filter) fails silently without it: finish the manual steps its own skill or installation page names. The five install steps, provider-order failures and the devtools wiring: ${CLAUDE_SKILL_DIR}/references/plugins.md.
11. Community: star and issue (optional, consent-first)
Two opt-in prompts the agent may raise after a fully completed magic task. Neither runs without an explicit user "yes", and at most once per session. Skip on short sessions, mid-task and after failures. The full flow (preflight, exact gh commands, URL fallback, diagnostics, a body skeleton, dedupe, spam brakes) is in ${CLAUDE_SKILL_DIR}/references/community.md; load it before acting on either.
- Star: after a verified end-to-end task, ask in prose whether to star
anilcancakir/magic. Only on a "yes" rungh api --method PUT /user/starred/anilcancakir/magic; otherwise print the URL. - Issue: only for a genuine magic-side bug (an exception thrown from inside
package:magic, a documented facade method behaving wrongly). Not for documented behaviour: the advisory client-side Gate,useLocaldefaulting to false, nowith()or lazy load, a manualSession.tick(),Auth.guestas a getter, noHttp.patch, provider-order andsetUserFactoryrequirements,configFactoriesversusconfigs. Gather diagnostics, draft the body, show it verbatim, and rungh issue create -R anilcancakir/magic --label bugonly after the user confirms.
12. Reference index
references/ paths are relative to this skill's directory, ${CLAUDE_SKILL_DIR}; a doc/ path is a site page (see the top of this file).
| File | Load when |
references/bootstrap-lifecycle.md | app bootstrap, the IoC API, ServiceProvider, Env and Config, the Laravel mapping and its divergences |
references/facades-api.md | any facade method signature or return type |
references/eloquent-orm.md | models, casts, relations, mass assignment, hybrid persistence and the LocalModelStore contract |
references/controllers-views.md | controllers, MagicStateMixin, RxStatus, views, MagicBuilder, MagicSelector, MagicCan |
references/forms-validation.md | MagicFormData, FormRequest, ValidatesRequests, rules, async validation, Session flash |
references/routing-navigation.md | routes, resource(), middleware, params, back gestures, bottom-sheet (overlay) routes, URL strategy, titles, Session.tick wiring |
references/http-network.md | Http, MagicResponse, MagicNetworkInterceptor, configureDriver, network config, MagicPaginator, MagicPage, MagicPaginatedListView |
references/auth-system.md | Auth, guards, Gate, policies, authorize(), Vault |
references/secondary-systems.md | Cache, Event, Log, Lang, Storage, Launch, MagicFile, Carbon, and the map of the layers that moved to plugins |
references/testing-patterns.md | MagicTest, facade fakes, fetch helpers, testing controllers, models and middleware |
references/cli-commands.md | the make:* generators, magic:install, make:component, previews:refresh, design:sync, design:lint |
references/templates.md | copy-paste templates: Model, Controller, View, FormData, Provider, Middleware |
references/plugins.md | installing a plugin, provider order, the devtools wiring |
references/community.md | the star and issue flow (load before raising either) |
doc/architecture/application-structure.md | how controllers, actions, form objects, repositories, SessionScope and broadcast listeners divide a screen |
doc/basics/actions.md | MagicAction, RunsActions, MagicAction.bind, resolve, flush |
doc/eloquent/repositories.md | Repository, RepositoryQuery, showOnlyKeys, session-reset behaviour |
doc/digging-deeper/session-scope.md | SessionScope, SessionScoped, the identity resolver, attach and detach |
doc/digging-deeper/perf-hooks.md | MagicPerfHooks.sink, the MagicPerfEvent kinds, MagicNotifyCause, pairing HTTP by MagicResponse.id |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

