magic 1.0.0
magic: ^1.0.0 copied to clipboard
A Laravel-inspired Flutter framework with Eloquent ORM, routing, and MVC architecture.
Magic
Build Flutter apps with the structure you know from Laravel.
An IoC container, facades, service providers, Eloquent-style models over your REST API, routing without BuildContext, auth, validation and test fakes, with a generator for each piece.
Documentation · pub.dev · Issues
At a glance #
| Fact | Value |
|---|---|
| Package | magic |
| Install | flutter pub add magic, then dart run magic:dowel magic:install |
| Import | package:magic/magic.dart (package:magic/testing.dart in tests) |
| Entry points | Magic.init(), the facades (Auth, Cache, Config, Event, Gate, Http, Lang, Launch, Log, MagicRoute, Session, Storage, Vault), Model, MagicController, ServiceProvider, dart run magic:dowel make:* |
| Platforms | Wherever Flutter runs, web included. Vault keeps secrets in the platform's secure storage. |
| Requires | Dart >=3.13, Flutter >=3.47 |
| Dependencies | wind_kit, material_ui, dowel, dio, go_router, flutter_secure_storage and a few more, see Dependencies |
| License | MIT |
Install #
flutter pub add magic
dart run magic:dowel magic:install
Magic ships its own dowel executable, so the command works as soon as magic is a dependency, with no global activation. magic:install adds wind_kit, material_ui and dowel to your pubspec.yaml, writes the config files, the service providers, the .env files and a lib/main.dart that calls Magic.init(). It also scaffolds bin/dispatcher.dart, so plugin commands resolve.
SQLite, broadcasting, encryption and the file picker are plugins, not core. Add one with flutter pub add <package>, then dart run magic:dowel plugin:install <package>.
A taste of Magic #
A model maps a REST resource, a controller loads it and renders each state, a route serves the screen:
class User extends Model with HasTimestamps, InteractsWithPersistence {
@override String get table => 'users';
@override String get resource => 'users';
String? get name => getAttribute('name') as String?;
static User fromMap(Map<String, dynamic> map) =>
User()..setRawAttributes(map, sync: true)..exists = map.containsKey('id');
}
class UserController extends MagicController with MagicStateMixin<List<User>> {
static UserController get instance => Magic.findOrPut(UserController.new);
Widget index() {
if (isEmpty) fetchList('users', User.fromMap);
return renderState((users) => WDiv(
className: 'flex flex-col gap-2 p-4',
children: [for (final user in users) WText(user.name ?? '')],
));
}
}
// lib/routes/app.dart
void registerAppRoutes() {
MagicRoute.page('/users', () => UserController.instance.index());
}
fetchList drives loading, success, error and empty for you, and navigation, auth and validation work from anywhere without a BuildContext: MagicRoute.toNamed('user.show', params: {'id': '1'}), Auth.check(), Validator.make(data, rules).passes().
The plugin family #
Magic core stays small. Each plugin adds one layer and has its own page.
| Plugin | Adds |
|---|---|
magic_local_storage |
SQLite for models with useLocal: DB and Schema facades, migrations, seeders, factories, a query builder and sync. |
magic_socket |
Real-time broadcasting: the Echo facade, Reverb and null drivers, private and presence channels. |
magic_encryption |
AES-256-CBC encryption: the Crypt facade and key:generate. |
magic_picker |
File and image picking through the Pick facade, plus the share-sheet download handler. |
magic_deeplink |
Universal Links and App Links, resolved to Magic routes. |
magic_notifications |
Database (in-app), push (OneSignal) and mail channels behind one Notify facade. |
magic_social_auth |
Social sign-in with extensible drivers, in the style of Laravel Socialite. |
magic_payments |
One entitlement contract over Stripe on the web and store in-app purchase on mobile. |
magic_sentry |
Sentry for Magic apps: a web-safe boot, HTTP failure reports and an auth-synced user scope. |
magic_starter |
A starter kit: auth, profile, teams and notifications as opt-in features with overridable views. |
magic_device |
Gate background work on mains power, viewer idle and macOS window fullscreen. |
magic_devtools |
Magic adapters for the tapir and crumbs dev tools. |
For AI coding agents #
Rules for an agent writing code against Magic. Each one is a mistake that costs a debugging session.
| Do | Because |
|---|---|
Import package:magic/magic.dart, and package:magic/testing.dart in tests |
Everything under src/ is private. The barrel also re-exports wind_kit, dio and go_router. |
await Magic.init(...) in main() before any facade call |
Facades resolve from the container that init builds. |
Scaffold with dart run magic:dowel make:* |
The generators place files where the rest of the framework looks for them. |
Call Auth.manager.setUserFactory(...) in AppServiceProvider.boot(), and list AppServiceProvider before the auth provider |
Without a user factory, session restore fails. |
Register listeners from a provider's register(), as factories: Event.listen<T>(() => Listener()) |
The auth guard can dispatch during AuthServiceProvider.boot. T must be named, or Dart infers MagicEvent and no event matches. |
Pass configs that read Env.get() as configFactories |
Magic.init loads .env first and evaluates the factories after it. |
| Add the plugin when you use a layer that left core | A model with useLocal and no magic_local_storage throws StateError, and Storage.download on IO without magic_picker throws UnsupportedError. |
Add LaunchServiceProvider to the providers config if magic:install did not |
It is not registered automatically, and Launch needs it. |
Open tests with MagicTest.init() and fake with Http.fake(), Auth.fake(), Cache.fake(), Vault.fake(), Log.fake() |
Container and facade state leaks between tests otherwise. Mock by inheriting a contract, not with mockito. |
llms.txt carries the same facts in one file, and npx skills add anilcancakir/magic installs the agent skill.
Documentation #
Every page is at https://anilcancakir.com/magic/docs/<section>/<page>.
| Section | Pages |
|---|---|
| Getting started | Installation · Configuration · Service Providers · Directory Structure |
| Architecture | Service Container · Facades · Request Lifecycle · Application Structure |
| Basics | Routing · Controllers · Views · Middleware · HTTP Client · Forms · Actions · UI Helpers |
| Digging deeper | Cache · Events · File Storage · Helpers · Launch · Localization · Logging · Session · Session Scope · Validation · Carbon · Perf Hooks |
| Eloquent | Getting Started · Mutators · Repositories · Serialization |
| Security | Authentication · Authorization · Vault |
| Testing | Getting Started · Facades · HTTP Tests |
| Packages | Magic CLI · Magic DevTools |
| Contributing | Contribution Guide · Documentation Authoring Guide |
Dependencies #
wind_kit for styling, re-exported so WDiv and WText come with the barrel; material_ui for the MaterialApp that MagicApplication builds; dowel for the CLI behind dart run magic:dowel; dio for the Http facade; go_router for routing; flutter_secure_storage for Vault; flutter_dotenv for .env; intl and jiffy for localisation and dates; logger for logging; url_launcher for Launch. Core has no code generation and no dependency on the dev tools: magic_devtools carries those adapters.
Links #
- Documentation: installation, the container, facades, routing, Eloquent, security and testing
- API reference
- llms.txt and the agent skill for AI coding agents:
npx skills add anilcancakir/magic - Changelog
- Report an issue
- Security policy
License #
MIT, see LICENSE. Built by Anılcan Çakır.