search ESC

Searching…

No results for "".

Type at least 2 characters to search.

Docs
You are viewing an older version (v1.0.0-alpha.1). Go to the latest.

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

Install Magic CLI globally via Dart's package manager:

dart pub global activate fluttersdk_magic_cli

[!NOTE] Ensure ~/.pub-cache/bin is in your system PATH to use the magic command globally.

Verify installation:

magic --version

Project Setup

magic init

Initializes Magic in an existing Flutter project with the recommended directory structure and configuration.

cd my_flutter_app
magic init

This command:

  1. Adds fluttersdk_magic dependency to pubspec.yaml
  2. Creates directory structure (app/, config/, routes/, etc.)
  3. Generates configuration files with sensible defaults
  4. Sets up service providers
  5. Generates an application encryption key

Excluding Features

You can exclude features you don't need:

# Skip specific features
magic init --without-database
magic init --without-cache
magic init --without-auth
magic init --without-events
magic init --without-localization

# Combine exclusions
magic init --without-database --without-events

key:generate

Generates a random encryption key for your application:

magic key:generate

Updates your .env file with:

APP_KEY=base64:randomGeneratedKey...

Make Commands

make:model

Creates an Eloquent-style model with optional related files:

magic make:model User
magic make:model Post --migration --controller --factory
magic make:model Comment -mcf  # Shorthand
magic make:model Product --all  # Create everything

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 all related files

Output: lib/app/models/.dart

make:controller

Creates a controller class:

magic make:controller User
magic make:controller UserController  # Explicit naming
magic make:controller Admin/Dashboard  # Nested path

Options

Option Shortcut Description
--stateful -s Include MagicStateMixin for state management
--resource -r Create resource controller with CRUD methods and views

Output: lib/app/controllers/_controller.dart

make:view

Creates a view class:

magic make:view Login
magic make:view LoginView  # Explicit naming
magic make:view Auth/Register  # Nested path

Options

Option Description
--stateful Create stateful view with MagicFormData support

Output: lib/resources/views/_view.dart

make:migration

Creates a database migration file:

magic make:migration create_users_table
magic make:migration add_email_to_users_table

Options

Option Shortcut Description
--create -c The table to be created
--table -t The table to migrate

Output: lib/database/migrations/_.dart

make:seeder

Creates a database seeder:

magic make:seeder UserSeeder

Output: lib/database/seeders/.dart

make:factory

Creates a model factory for generating fake data:

magic make:factory User
magic make:factory UserFactory  # Explicit naming

Output: lib/database/factories/_factory.dart

make:policy

Creates an authorization policy:

magic make:policy Post
magic make:policy Comment --model=Comment

Options

Option Shortcut Description
--model -m The model that the policy applies to

Output: lib/app/policies/_policy.dart

make:lang

Creates a language JSON file:

magic make:lang tr
magic make:lang es
magic make:lang de

Output: assets/lang/.json

Inspection Commands

route:list

Lists all registered routes in your application:

magic route:list

Output:

+---------------------+------------+----------+
| URI                 | Middleware | File     |
+---------------------+------------+----------+
| /                   | auth       | app.dart |
| /auth/login         | -          | auth.dart|
| /dashboard          | auth       | app.dart |
| /settings/team      | auth       | app.dart |
+---------------------+------------+----------+

config:list

Lists all configuration files and their keys:

magic config:list
magic config:list --verbose  # Show key previews

config:get

Gets a specific configuration value using dot notation:

magic config:get app.name
# Output: My App

magic config:get network.drivers.api.base_url
# Output: http://localhost:8000/api/v1

magic config:get app.url --show-source
# Output: http://localhost (from: .env)

Priority: Project config → .env → Framework defaults

Magic Boost (AI Integration)

Magic Boost provides AI-powered development tools through MCP (Model Context Protocol), allowing AI assistants like Claude to understand your Magic project.

Setup

Install Boost in your project:

magic boost:install

This will:

  • Create .magic/guidelines/ with framework documentation
  • Configure MCP server in your IDE (Cursor, VS Code)
  • Generate project-aware context for AI assistants

Commands

Command Description
boost:install Setup AI guidelines + MCP config
boost:mcp Run the MCP server (stdio)
boost:update Refresh guidelines to latest version

MCP Tools

The MCP server exposes these tools to AI assistants:

Tool Description
app_info Get pubspec.yaml info (name, version, dependencies)
list_routes List all application routes
get_config Read config values with dot notation
validate_wind Validate Wind UI utility classes
search_docs Search Magic documentation

IDE Configuration

After running boost:install, your IDE's MCP config is automatically updated:

.cursor/mcp.json or .vscode/mcp.json:

{
  "mcpServers": {
    "magic-boost": {
      "command": "dart",
      "args": ["run", "fluttersdk_magic_cli:magic", "boost:mcp"],
      "cwd": "/path/to/your/project"
    }
  }
}

Generated Guidelines

After installation, .magic/guidelines/ contains:

.magic/
└── guidelines/
    ├── core.md      # Core Magic framework
    ├── wind.md      # Wind UI system
    ├── eloquent.md  # Eloquent models
    └── routing.md   # Routing system

These files provide context for AI assistants about your project's architecture and coding conventions.

[!TIP] Run magic boost:update periodically to get the latest framework guidelines.