Magic CLI
Introduction
Magic CLI is the Artisan-like command-line tool for Magic. If you've used Laravel's Artisan, you'll feel right at home. Scaffold controllers, models, views, migrations, and more with a single command.
Installation
Magic CLI ships as a Dart package dependency. Add it to your pubspec.yaml and run commands via dart run:
dart run magic:magic [arguments] [options]
[!TIP] For a shorter command, activate Magic CLI globally:
dart pub global activate magic_cliEnsure
~/.pub-cache/binis in your system PATH, then usemagicdirectly.
Verify installation:
dart run magic:magic --version
Project Setup
install
Initializes Magic in an existing Flutter project with the recommended directory structure and configuration.
dart run magic:magic install
This command:
- Creates the directory structure (
lib/app/,lib/config/,lib/routes/, etc.) - Generates configuration files with sensible defaults (app, routing, view are always created; others are optional)
- Creates starter service providers (
AppServiceProvider,RouteServiceProvider) - Writes
lib/main.dartwith Magic bootstrap - Creates
.envand.env.examplefiles - Registers
.envas a Flutter asset inpubspec.yaml - Downloads
sqlite3.wasmfor web platform support (when database is enabled)
Excluding Features
You can exclude features you don't need with --without-* flags:
dart run magic:magic install --without-database
dart run magic:magic install --without-auth --without-events
| Flag | What it skips |
|---|---|
--without-auth |
Auth config, VaultServiceProvider, AuthServiceProvider |
--without-database |
Database directories, config/database.dart, DatabaseServiceProvider, web SQLite setup |
--without-network |
config/network.dart, NetworkServiceProvider |
--without-cache |
config/cache.dart, CacheServiceProvider |
--without-events |
lib/app/events/ and lib/app/listeners/ directories |
--without-localization |
assets/lang/ directory, LocalizationServiceProvider |
--without-logging |
config/logging.dart |
--without-broadcasting |
config/broadcasting.dart, BroadcastServiceProvider |
key:generate
Generates a random 32-byte encryption key for your application:
dart run magic:magic key:generate
Updates your .env file with:
APP_KEY=base64:randomGeneratedKey...
Options
| Option | Description |
|---|---|
--show |
Display the key in the terminal instead of writing to .env |
Make Commands
All make:* commands support the --force flag to overwrite existing files. Nested paths are supported via slash syntax (e.g., Admin/Dashboard), which creates subdirectories automatically.
Commands that auto-append a suffix (Controller, View, Factory, Seeder, Policy, ServiceProvider, Request) handle duplicates gracefully — make:controller UserController will not produce UserControllerController.
make:model
Creates an Eloquent-style model with optional related files:
dart run magic:magic make:model User
dart run magic:magic make:model Post --migration --controller --factory
dart run magic:magic make:model Comment -mcf
dart run magic:magic make:model Product -mcfsp
dart run magic:magic make:model Order --all
Options
| Option | Shortcut | Description |
|---|---|---|
--migration |
-m |
Create a database migration |
--controller |
-c |
Create a controller |
--factory |
-f |
Create a model factory |
--seeder |
-s |
Create a database seeder |
--policy |
-p |
Create an authorization policy |
--all |
-a |
Create migration, seeder, factory, policy, and resource controller |
[!NOTE] The
-mcfspshorthand combines all five flags: migration, controller, factory, seeder, and policy. The--allflag does the same but also makes the controller a resource controller with CRUD methods.
Output: lib/app/models/
make:controller
Creates a controller class:
dart run magic:magic make:controller User
dart run magic:magic make:controller UserController
dart run magic:magic make:controller Admin/Dashboard
dart run magic:magic make:controller Post --resource
dart run magic:magic make:controller Post --resource --model=Post
Options
| Option | Shortcut | Description |
|---|---|---|
--resource |
-r |
Generate a resource controller with CRUD methods |
--model |
-m |
The model the controller applies to |
Output: lib/app/controllers/
make:view
Creates a view class:
dart run magic:magic make:view Login
dart run magic:magic make:view LoginView
dart run magic:magic make:view Auth/Register
dart run magic:magic make:view Dashboard --stateful
Options
| Option | Description |
|---|---|
--stateful |
Generate a stateful view with lifecycle hooks |
Output: lib/resources/views/
make:migration
Creates a timestamped database migration file:
dart run magic:magic make:migration create_users_table
dart run magic:magic make:migration create_users_table --create=users
dart run magic:magic make:migration add_email_to_users --table=users
Options
| Option | Shortcut | Description |
|---|---|---|
--create |
-c |
The table to be created (selects the create stub) |
--table |
-t |
The table to migrate |
Output: lib/database/migrations/m_YYYYMMDDHHMMSS_
make:seeder
Creates a database seeder:
dart run magic:magic make:seeder User
dart run magic:magic make:seeder UserSeeder
Output: lib/database/seeders/
make:factory
Creates a model factory for generating fake data:
dart run magic:magic make:factory User
dart run magic:magic make:factory UserFactory
Output: lib/database/factories/
make:policy
Creates an authorization policy:
dart run magic:magic make:policy Post
dart run magic:magic make:policy PostPolicy
dart run magic:magic make:policy Post --model=Post
dart run magic:magic make:policy Admin/Dashboard
Options
| Option | Shortcut | Description |
|---|---|---|
--model |
-m |
The model the policy applies to |
Output: lib/app/policies/
make:provider
Creates a service provider class with register() and boot() stubs:
dart run magic:magic make:provider Payment
dart run magic:magic make:provider PaymentServiceProvider
The ServiceProvider suffix is appended automatically when omitted.
Output: lib/app/providers/
make:middleware
Creates a middleware class:
dart run magic:magic make:middleware EnsureAuthenticated
dart run magic:magic make:middleware Admin/RoleCheck
Output: lib/app/middleware/
make:enum
Creates a string-backed enum with fromValue() factory and selectOptions getter:
dart run magic:magic make:enum MonitorType
dart run magic:magic make:enum Status/OrderStatus
Output: lib/app/enums/
make:event
Creates a dispatchable event class that extends MagicEvent:
dart run magic:magic make:event UserLoggedIn
dart run magic:magic make:event Auth/TokenRefreshed
Output: lib/app/events/
make:listener
Creates an event listener class that extends MagicListener:
dart run magic:magic make:listener AuthRestore
dart run magic:magic make:listener AuthRestore --event=UserLoggedInEvent
dart run magic:magic make:listener Auth/RestoreSession
Options
| Option | Shortcut | Description |
|---|---|---|
--event |
-e |
The event class the listener handles (defaults to MagicEvent) |
Output: lib/app/listeners/
make:request
Creates a form request class with a typed rules() method for request validation:
dart run magic:magic make:request StoreMonitor
dart run magic:magic make:request StoreMonitorRequest
The Request suffix is appended automatically when omitted.
Output: lib/app/validation/requests/
make:lang
Creates a language JSON file:
dart run magic:magic make:lang tr
dart run magic:magic make:lang es
dart run magic:magic make:lang de
Output: assets/lang/