PHPackages                             r2luna/brain - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. r2luna/brain

ActiveLibrary[Framework](/categories/framework)

r2luna/brain
============

Brain: A process-driven architecture alternative for your Laravel Application.

3.7.0(2mo ago)6018.8k↑22.8%6[1 PRs](https://github.com/r2luna/brain/pulls)1MITPHPPHP ^8.3.0 || ^8.4.0 || ^8.5.0CI passing

Since Mar 6Pushed 2mo ago6 watchersCompare

[ Source](https://github.com/r2luna/brain)[ Packagist](https://packagist.org/packages/r2luna/brain)[ Docs](https://github.com/r2luna/brain)[ RSS](/packages/r2luna-brain/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (26)Versions (55)Used By (1)

[![Banner](https://private-user-images.githubusercontent.com/23129218/422072038-35c6a96d-bebb-40c5-b20b-5bce9a915fe0.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzQzNTYxMDksIm5iZiI6MTc3NDM1NTgwOSwicGF0aCI6Ii8yMzEyOTIxOC80MjIwNzIwMzgtMzVjNmE5NmQtYmViYi00MGM1LWIyMGItNWJjZTlhOTE1ZmUwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjAzMjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwMzI0VDEyMzY0OVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTI4YWEzODM1YTc1MzUyZGI5YTllZTZkOTUwZDljODBmZmMzYmUzY2FmOTkxNGJlYzY4YTJhMmMzZDdmZDY3YzYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.Edg39eJ6MGR_fStTSpRQ-nbAGJjcLXE3usrapN-Qdqs)](https://private-user-images.githubusercontent.com/23129218/422072038-35c6a96d-bebb-40c5-b20b-5bce9a915fe0.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzQzNTYxMDksIm5iZiI6MTc3NDM1NTgwOSwicGF0aCI6Ii8yMzEyOTIxOC80MjIwNzIwMzgtMzVjNmE5NmQtYmViYi00MGM1LWIyMGItNWJjZTlhOTE1ZmUwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjAzMjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwMzI0VDEyMzY0OVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTI4YWEzODM1YTc1MzUyZGI5YTllZTZkOTUwZDljODBmZmMzYmUzY2FmOTkxNGJlYzY4YTJhMmMzZDdmZDY3YzYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.Edg39eJ6MGR_fStTSpRQ-nbAGJjcLXE3usrapN-Qdqs)

 [![GitHub Workflow Status](https://camo.githubusercontent.com/db03b264a2d7613d7266f647449991a249318cc9f0edd321d2eead611eac0a88/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f72326c756e612f627261696e2f74657374732e796d6c)](https://github.com/r2luna/brain/actions) [![Total Downloads](https://camo.githubusercontent.com/a5ecbef0834b432de6e2c1c8e6a04276c2f80e649af03d23f7401130513e6f30/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72326c756e612f627261696e)](https://packagist.org/packages/r2luna/brain) [![Latest Version](https://camo.githubusercontent.com/471dd0a1c416a195436c96e524220858c7d0cab899c2eaf01c744276d6980446/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72326c756e612f627261696e)](https://packagist.org/packages/r2luna/brain) [![License](https://camo.githubusercontent.com/7a47de024b2bc7e18993927a7e3897a3745b2de39fbc6e1428b9e61a9dd966aa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f72326c756e612f627261696e)](https://packagist.org/packages/r2luna/brain)

---

**Brain** is an elegant Laravel Package that helps you organize your Laravel application using Domain-Driven Design principles through a simple command-line interface.

Features
--------

[](#features)

- 🎯 **Domain-Driven Structure**: Easily create new domains with proper architecture (optional)
- 🔄 **Process Management**: Generate process classes for complex business operations
- 🔍 **Query Objects**: Create dedicated query classes for database operations
- ⚡ **Task Management**: Generate task classes for background jobs and queue operations
- 🔧 **Flexible Configuration**: Customize root directory, domain organization, and class naming conventions
- 📊 **Built-in Logging**: Track process and task execution with comprehensive event system

Gains
-----

[](#gains)

- ♻️ **Code Reusability**: By using tasks, you can easily reuse code across different processes, reducing duplication and enhancing maintainability.
- 🧩 **Clear Domain Understanding**: The structured approach provides a better understanding of each domain's processes, making it easier to manage and scale your application.
- 🔧 **Improved Maintainability**: With well-defined domains and processes, maintaining and updating your application becomes more straightforward and less error-prone.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require r2luna/brain
```

Configuration
-------------

[](#configuration)

Brain can be customized through environment variables or by publishing the configuration file:

```
php artisan vendor:publish --provider="Brain\BrainServiceProvider"
```

### Available Configuration Options

[](#available-configuration-options)

#### Root Directory

[](#root-directory)

```
# .env
BRAIN_ROOT=Brain
```

Defines the main directory where processes, tasks, and queries are created. Default: `Brain`

#### Use Domains

[](#use-domains)

```
# .env
BRAIN_USE_DOMAINS=false
```

Organizes code into domain-specific subdirectories. When enabled, creates structure like `app/Brain/Users/Processes`. Default: `false`

#### Use Suffix

[](#use-suffix)

```
# .env
BRAIN_USE_SUFFIX=false
```

Automatically appends suffixes to class names (e.g., `CreateUser` becomes `CreateUserProcess`). Default: `false`

#### Custom Suffixes

[](#custom-suffixes)

```
# .env
BRAIN_TASK_SUFFIX=Task
BRAIN_PROCESS_SUFFIX=Process
BRAIN_QUERY_SUFFIX=Query
```

Customize the suffixes used when `BRAIN_USE_SUFFIX=true`. Defaults: `Task`, `Process`, `Query`

#### Logging

[](#logging)

```
# .env
BRAIN_LOG_ENABLED=false
```

Enables logging for all processes and tasks. See [Logging](#logging) section for details. Default: `false`

Usage
-----

[](#usage)

### Creating a Process

[](#creating-a-process)

```
php artisan make:process
... follow prompt
name: CreateUserProcess
domain: Users  # Only asked if BRAIN_USE_DOMAINS=true
```

This will create a new process class:

- With domains: `app/Brain/Users/Processes/CreateUserProcess.php`
- Without domains: `app/Brain/Processes/CreateUserProcess.php`

Important

Note that every task running inside a process executes within a database transaction by default.

### Creating a Task

[](#creating-a-task)

```
php artisan make:task
... follow prompt
name: SendWelcomeEmailTask
domain: Users  # Only asked if BRAIN_USE_DOMAINS=true
```

This will create a new task class:

- With domains: `app/Brain/Users/Tasks/SendWelcomeEmailTask.php`
- Without domains: `app/Brain/Tasks/SendWelcomeEmailTask.php`

#### Queuable Tasks

[](#queuable-tasks)

To send the task to the queue simply implements Laravel Contract `ShouldQueue` to the class

```
