Skip to content

Action Definition

lpachecob edited this page Mar 24, 2026 · 4 revisions

🧬 Action Definition: Declarative Endpoints

In BOUNDLY, an Action is a single Use Case. You don't need a routes/*.php file. Just add an attribute to your Action class.


🏗️ #[Action]

Required to register a class as an API endpoint.

Property Default Description
resource NULL The API path (e.g., 'auth/login').
method 'GET' The HTTP method (GET, POST, PUT, DELETE).
middleware [] Array of Laravel middleware to apply.
#[Action(resource: 'users/register', method: 'POST')]
class RegisterUserAction { ... }

🛠️ Implementation

Your Action class must implement a main entry point. While BOUNDLY doesn't require an interface, the Generic Controller will try to execute it as a handler for the resource.

// Application/Users/Actions/CreateUserAction.php
use Infrastructure\FrameworkCore\Attributes\UseCase\Action;

#[Action(resource: 'users', method: 'POST')]
class CreateUserAction
{
    public function handle(array $data)
    {
        // Your Use Case logic here...
        // Validation, Entity creation, Event dispatching.
        return ['status' => 'success', 'data' => $data];
    }
}

📦 Middleware Support

#[Action(
    resource: 'profile/private', 
    method: 'GET', 
    middleware: ['auth:sanctum', 'throttle:api']
)]
class GetPrivateProfileAction { ... }

🧬 Why Actions over Controllers?

  1. Single Responsibility: Each class does ONE thing (e.g., ResetPasswordAction).
  2. Declarative Routing: Routes live where they are used. No more hunting through a 2000-line routes/web.php.
  3. Decoupled: Your actions are cleaner, and BOUNDLY's registry finds them automatically during its scan.

Next Step: Behavioral-Traits 🛡️

Clone this wiki locally