Celestial CLI

Introduction

Celestial is the command-line interface included with Slenix. Celestial exists at the root of your application as the celestial script and provides a number of helpful commands that can assist you while you build your application. To view a list of all available Celestial commands, you may use the help command:

bash
php celestial help

Every command also includes a brief description. To see the current version of Celestial:

bash
php celestial version

Writing and Running Commands

Starting the Development Server

Celestial includes a built-in development server powered by PHP's native server. To start it, run the serve command from the root of your application:

bash
php celestial serve

The development server will be accessible at http://127.0.0.1:8080 by default. You may specify a custom port by passing it as an argument:

bash
php celestial serve 9000

This will serve your application at http://127.0.0.1:9000. To stop the server, press Ctrl+C in your terminal.

Note: Celestial serves files from the public/ directory. If the public/ directory does not exist, Celestial will attempt to create it automatically.

Valid port numbers range from 1 to 65535. Passing a port outside this range will result in an error.


Generating Application Keys

Slenix uses an application key for encryption and security. This key is stored as APP_KEY in your .env file and should always be set before deploying to production.

To generate and save a new application key:

bash
php celestial key:generate

This command generates a cryptographically secure 32-byte key, encodes it as base64 with a base64: prefix, and writes it directly to your .env file. If the .env file does not exist, Celestial will attempt to create it by copying .env.example.

plaintext
[✔] APP_KEY generated and saved to .env
[ℹ] Key: base64:i4OjqaSH96ZEoCkKRfuIyBYZCj6zyg8fS/WnzlLbkZ4=

You should regenerate the application key any time you suspect your existing key has been compromised. Note that changing the key will invalidate all encrypted data and active sessions.


Generating Controllers

To generate a new controller class, use the make:controller command:

bash
php celestial make:controller User

This will create a new file at app/Controllers/UserController.php with a minimal class stub ready to use:

php
namespace App\Controllers;

use Slenix\Http\Request;
use Slenix\Http\Response;

class UserController
{
    public function index(Request $request, Response $response)
    {
        // Your application logic
    }
}

You can specify a name in any case — Celestial will automatically capitalize the first letter. The Controller suffix is not required in the command argument:

bash
php celestial make:controller UserProfile
# Creates: app/Controllers/UserProfileController.php  ← not added, name preserved

Note: If a controller with the same name already exists, Celestial will display an error and will not overwrite it.


Generating Models

To generate a new model class, use the make:model command:

bash
php celestial make:model Post

This will create app/Models/Post.php with a stub that extends Slenix\Supports\Database\Model. The table name is automatically inferred from the model name using snake_case with a plural suffix:

php
namespace App\Models;

use Slenix\Supports\Database\Model;

class Post extends Model
{
    protected string $table      = 'posts';
    protected string $primaryKey = 'id';
    protected array  $fillable   = [];
}

For multi-word model names, the table name is derived accordingly:

Model NameInferred Table
Userusers
BlogPostblog_posts
OrderItemorder_items
ProductCategoryproduct_categorys

Note: For irregular plurals (e.g. Personpeople), set the $table property manually inside the generated model.


Generating Middleware

To generate a new middleware class, use the make:middleware command:

bash
php celestial make:middleware EnsureEmailIsVerified

This will create app/Middlewares/EnsureEmailIsVerifiedMiddleware.php. If the name you provide does not already end in Middleware, Celestial appends it automatically:

bash
php celestial make:middleware Auth
# Creates: app/Middlewares/AuthMiddleware.php

The generated class implements the Slenix\Http\Middlewares\Middleware interface and includes a ready-to-use handle stub:

php
namespace App\Middlewares;

use Slenix\Http\Request;
use Slenix\Http\Response;
use Slenix\Http\Middlewares\Middleware;

class AuthMiddleware implements Middleware
{
    public function handle(Request $request, Response $response, callable $next): mixed
    {
        // Middleware logic here

        return $next($request, $response);
    }
}

Listing Routes

To inspect all routes registered in your application, use the route:list command:

bash
php celestial route:list

Celestial loads routes/web.php and prints a formatted table showing the HTTP method, URI, handler, and route name for every registered route:

plaintext
--------------------------------------------------------------------------------
METHOD   URI                            HANDLER                   NAME
--------------------------------------------------------------------------------
GET      /                              HomeController@index      home
GET      /login                         AuthController@loginShow  login.show
POST     /login                         AuthController@login      login
GET      /register                      AuthController@register.. register.show
POST     /register                      AuthController@register   register
GET      /dashboard                     DashboardController@index home.show
         [auth]
--------------------------------------------------------------------------------
[✔] Total: 6 routes

Middleware assigned to a route is displayed on the line below the route entry, enclosed in square brackets.


Clearing the View Cache

Luna compiles your .luna.php templates into plain PHP and caches them in storage/views/. When deploying new templates, you may want to clear the compiled cache:

bash
php celestial view

This calls Luna::clearCache() internally, deleting all .php files in storage/views/. The next request to any view will trigger a fresh compilation.

Tip: In development, set APP_DEBUG=true in your .env file. This causes Luna to bypass the cache entirely, so you never need to clear it manually during development.


Terminal Output Reference

Celestial uses colored, prefixed output to help you distinguish between different types of messages at a glance:

SymbolColorMethodMeaning
[ℹ]CyanCommand::info()Informational message
[✔]GreenCommand::success()Operation completed successfully
[!]YellowCommand::warning()Non-critical warning
[✗]RedCommand::error()Error or failed operation

Command Reference

Below is a complete reference of all commands available in Celestial:

CommandArgumentsDescription
php celestial helpDisplay the help screen with all available commands
php celestial versionDisplay the current Celestial CLI version
php celestial serve[port]Start the local development server (default port: 8080)
php celestial key:generateGenerate and save a new APP_KEY to .env
php celestial make:controller<name>Generate a new controller class in app/Controllers/
php celestial make:model<name>Generate a new model class in app/Models/
php celestial make:middleware<name>Generate a new middleware class in app/Middlewares/
php celestial route:listDisplay all registered application routes
php celestial viewClear the compiled Luna template cache

Exit Codes

Celestial uses standard POSIX exit codes:

CodeMeaning
0Success
1General error (unknown command, missing argument, file write failure, etc.)

When an unrecoverable error occurs, Celestial prints a descriptive message in red and exits with code 1:

plaintext
[✗] Error: Controller 'UserController' already exists at app/Controllers/UserController.php.