Skip to content

fluttersdk/magic

Repository files navigation

Magic Logo

Magic

The Laravel Experience for Flutter.
Build production-ready Flutter apps with Facades, Eloquent ORM, Service Providers, and an IoC Container. If you know Laravel, you already know Magic.

pub package CI License: MIT pub points GitHub stars

Documentation · pub.dev · Issues


Note

Requires Flutter >= 3.41.0 and Dart >= 3.11.0. Alpha: Magic is under active development and APIs may change before 1.0. Star the repo to follow progress.

Installation

flutter pub add magic
dart run magic:artisan magic:install

Magic ships its own artisan executable, so dart run magic:artisan works the moment magic is a dependency, with no global activation and no per-app wrapper to write. The one-shot magic:install scaffolds every config file, your service providers, the .env files, and a ready-to-run lib/main.dart bootstrap. The full setup walkthrough, all 18 facades, the CLI generators, and every subsystem live at the Getting Started guide.

Why Magic?

Flutter gives you widgets, but not architecture. Building a real app means wiring up HTTP clients, auth flows, caching, validation, routing, and state management, all from scratch, every time.

Magic fixes this. If you know Laravel, you already know Magic:

// Before: the Flutter way
final dio = Dio(BaseOptions(baseUrl: 'https://api.example.com'));
final response = await dio.get('/users/1');
final user = User.fromJson(response.data['data']);
// ...manually handle tokens, errors, caching, state...

// After: the Magic way
final user = await User.find(1);

The same Facades, the same Eloquent syntax, the same Service Provider lifecycle you reach for in Laravel, mapped onto a reactive Flutter client. No BuildContext plumbing, no boilerplate.

Features

Feature Description
🏗️ IoC Container Service container with singleton, bind, and instance registration.
🎭 18 Facades Auth, Http, Cache, DB, Echo, Event, Gate, Log, Route, Lang, Storage, Vault, Crypt, and more, static-style access to resolved singletons.
🗄️ Eloquent ORM Models, query builder, migrations, seeders, factories, a hybrid REST + SQLite persistence layer.
🛣️ Routing GoRouter integration with middleware, named routes, context-free navigation, and automatic page-title management.
🔐 Authentication Token-based auth with guards (Bearer, BasicAuth, ApiKey), cache-first session restore, and auto-refresh.
🛡️ Authorization Gates, policies, and MagicCan / MagicCannot widgets.
Validation Laravel-style rules: Required, Email, Min, Max, In, Confirmed, and more.
📡 Events Pub/sub event system with MagicEvent and MagicListener.
💾 Caching Memory and file drivers with TTL and the remember() pattern.
🌍 Localization JSON-based i18n with :attribute placeholders.
🎨 Wind UI Built-in Wind Tailwind-syntax styling with className strings.
📡 Broadcasting Laravel Echo equivalent: real-time WebSocket channels via the Echo facade with presence support and Echo.fake().
🧪 Testing First-class fakes: Http.fake(), Auth.fake(), Cache.fake(), Vault.fake(), Log.fake(), Echo.fake(). No mockito needed.
🧰 Magic CLI Artisan-style scaffolding via dart run magic:artisan make:model, make:controller, and 14 generators.

A taste of Magic

A controller fetches over HTTP, an Eloquent model maps the response, and Wind styles the screen, the way it feels in Laravel:

class UserController extends MagicController with MagicStateMixin<List<User>> {
  static UserController get instance => Magic.findOrPut(UserController.new);

  Future<void> fetchUsers() => fetchList('users', User.fromMap);

  Widget index() => renderState(
    (users) => WDiv(
      className: 'flex flex-col gap-2 p-4 bg-white dark:bg-gray-900',
      children: [
        for (final user in users)
          WText(user.name ?? '', className: 'text-base text-gray-900 dark:text-white'),
      ],
    ),
    onLoading: const CircularProgressIndicator(),
    onError: (msg) => WText('Error: $msg', className: 'text-red-500'),
  );
}
// Eloquent: SQLite-first, API fallback, automatic sync
final user = await User.find(1);
final admins = await User.where('role', 'admin').get();
await user.save();

// Context-free navigation, auth, and validation, from anywhere
MagicRoute.toNamed('user.show', params: {'id': '1'});
if (Auth.check()) { final me = Auth.user<User>(); }
final ok = Validator.make(data, {'email': [Required(), Email()]}).passes();

See the documentation for the full Facade reference, the Eloquent guide, routing, forms, broadcasting, and testing.

AI Coding Assistants

Magic ships AI-first. The magic-framework skill teaches your agent the correct patterns, Facades, Eloquent ORM, Service Providers, controllers, routing, and the common anti-patterns, so it generates correct Magic code on the first try. The skill is distributed through fluttersdk/ai for Claude Code, Cursor, OpenCode, Gemini CLI, VS Code Copilot, Codex CLI, Cline, and Roo Code with one command:

npx skills add fluttersdk/ai --skill magic-framework

Documentation

Full docs at magic.fluttersdk.com.

Topic
Installation Setup and requirements
Configuration Environment and config files
Service Providers Provider lifecycle
Routing Routes and navigation
Controllers Request handlers
HTTP Client Network requests
Eloquent ORM Models and persistence
Forms Form handling and validation
Broadcasting Real-time WebSocket channels
Magic CLI Generators and scaffolding

Contributing

git clone https://github.com/fluttersdk/magic.git
cd magic && flutter pub get
flutter test && dart analyze

Report a bug · Request a feature

License

MIT, see LICENSE for details.


Built with care by FlutterSDK
If Magic saves you time, give it a star, it helps others discover it.

About

Build production-ready Flutter apps with Facades, Eloquent ORM, Service Providers, and IoC Container — zero boilerplate.

Topics

Resources

License

Stars

Watchers

Forks

Contributors