Skip to content

Command

Command is an authorized Artisan or scheduler inbound adapter that calls one UseCase.

Generated facts

Layer
service
Generated path
app/Pulsar/Services/{Service}/Modules/{Module}/Commands/{Name}.php
Generator command
make:command
Workflow method
None
Stability
Current manifest surface (Pulsar 0.4.1)

Canonical example

Generated src/stubs/command.stub — canonical synchronized stub.

<?php

namespace {{namespace}};

use {{useCaseNamespace}}\{{useCase}};
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Gate;

class {{name}} extends Command
{
    protected $signature = {{signature}};

    protected $description = 'Run the {{name}} workflow';

    public function handle({{useCase}} $useCase): int
    {
        // Validate CLI input and establish actor/tenant context before this point.
        // Replace this framework string with the owning domain's backed Ability enum value.
        Gate::authorize('replace-with-domain-ability');

        // Call exactly one UseCase. The UseCase owns the transaction and business branching.
        $useCase->execute();

        return self::SUCCESS;
    }
}

Responsibility

Command owns the responsibility stated above; it must not absorb delivery, transaction, or unrelated cross-layer behavior.

Placement and dependencies

Keep this type in its generated Service Module path. It may depend inward on Domain capability, but it must not make another Service its behavioral dependency.

Workflow and tests

Command is an inbound adapter: establish the delivery boundary, then call one UseCase. Test its direct contract, its rejected boundary cases, and the caller or callee that proves the rule in application flow.

Three pitfalls

  1. ❌ Prohibited: move this responsibility into a neighboring type merely because it is nearby.
  2. ✅ Correct: keep the generated placement and depend only on the documented layer direction.
  3. ✅ Correct: test the boundary through the caller and the return or side effect visible to its callee.

Related reading

Read architecture placement for shared rationale and follow this page’s related concept links for the adjacent responsibility.

Boundaries

❌ Prohibited: Do not confuse this generated application Command with the Pulsar generator CLI.

✅ Correct: Validate CLI input, establish context, and call one UseCase.