PHPackages                             pupadevs/laramain - 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. pupadevs/laramain

ActiveLibrary[Framework](/categories/framework)

pupadevs/laramain
=================

Install CQRS with DDD folder structure and Command/Query Buses for the specified entity

2.0.0(1y ago)020MITPHPPHP ^8.2

Since Sep 21Pushed 1y ago1 watchersCompare

[ Source](https://github.com/pupadevs/laramain)[ Packagist](https://packagist.org/packages/pupadevs/laramain)[ Fund](https://paypal.me/pvpaofficial?country.x=ES&locale.x=es_ES)[ RSS](/packages/pupadevs-laramain/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (9)Used By (0)

Pupadevs\\Laramain
==================

[](#pupadevslaramain)

[![](https://private-user-images.githubusercontent.com/121895258/375166807-2f4a0a0a-94a9-4566-9907-5931ac9640da.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzU2NzA1MDIsIm5iZiI6MTc3NTY3MDIwMiwicGF0aCI6Ii8xMjE4OTUyNTgvMzc1MTY2ODA3LTJmNGEwYTBhLTk0YTktNDU2Ni05OTA3LTU5MzFhYzk2NDBkYS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjYwNDA4JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI2MDQwOFQxNzQzMjJaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1jNTg1OWFjYzgxYzFlZjA3MjY3NDkyYmUwNTM2ODI5OTYzYzYxOWNhYjM1Y2M3MGU2ZTk5NjAwNjQ2MGM3MzY5JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.KYGz1vRedNjDvDSAddq5K2lo0e51ksaYFqjxjJ48EXo)](https://private-user-images.githubusercontent.com/121895258/375166807-2f4a0a0a-94a9-4566-9907-5931ac9640da.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzU2NzA1MDIsIm5iZiI6MTc3NTY3MDIwMiwicGF0aCI6Ii8xMjE4OTUyNTgvMzc1MTY2ODA3LTJmNGEwYTBhLTk0YTktNDU2Ni05OTA3LTU5MzFhYzk2NDBkYS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjYwNDA4JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI2MDQwOFQxNzQzMjJaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1jNTg1OWFjYzgxYzFlZjA3MjY3NDkyYmUwNTM2ODI5OTYzYzYxOWNhYjM1Y2M3MGU2ZTk5NjAwNjQ2MGM3MzY5JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.KYGz1vRedNjDvDSAddq5K2lo0e51ksaYFqjxjJ48EXo)

[![Packagist Version](https://camo.githubusercontent.com/8d5a01f2b23229000bec460d9645b5a6df5ed370729c3ce11a7fe0908977b61e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70757061646576732f6c6172616d61696e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pupadevs/laramain)[![License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Total Downloads](https://camo.githubusercontent.com/997574553418be574ebcf221e2fe9a56c3f9189077eb42003e428378f9f8299d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70757061646576732f6c6172616d61696e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pupadevs/laramain)[![PHP Version](https://camo.githubusercontent.com/ef136d769ad9edf1111ed5ad7e69040d4cc8336d5989e9f211e7b755baa21525/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253545382e322d3838393242462e7376673f7374796c653d666c61742d737175617265)](https://www.php.net/)[![Laravel](https://camo.githubusercontent.com/6348bb91911c2d0bfa2d12df50e1baafdf386e5080ed3568c2f5c24057e9fb2c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d25354531302e302545322539432539342d4646324435352e7376673f7374796c653d666c61742d737175617265)](https://www.laravel.com)

Descripción
-----------

[](#descripción)

**Pupadevs\\Laramain** Es un paquete Laravel diseñado para facilitar la implementación de la arquitectura DDD (Domain-Driven Design) y CQRS (Command Query Responsibility Segregation) en tus aplicaciones Laravel.

Requisitos
----------

[](#requisitos)

- PHP &gt;= 8.2
- Laravel &gt;= 10x

Instalación
-----------

[](#instalación)

Para instalar el paquete es necesario tener instalado Composer. Ejecuta el siguiente comando

```
composer require pupadevs/laramain
```

Uso de comandos de artisan
--------------------------

[](#uso-de-comandos-de-artisan)

**1.Comando Artisan con parametro**Este comando te pedirá que ingreses un nombre para tu dominio. Usará ese nombre para crear la estructura de carpetas siguiendo la arquitectura DDD (Domain-Driven Design). La carpeta principal llevará el nombre que hayas proporcionado como dominio, y dentro de ella se generarán las subcarpetas correspondientes para organizar tu proyecto de acuerdo con los principios de DDD.

```
php artisan laramain:install {nombreDominio}
```

```
php artisan vendor:publish --provider="Pupadevs\Laramain\Providers\PackageServiceProvider"
```

**2.Comando Artisan basico**

```
php artisan laramain:install-basic
```

**Repetimos publicacion del vendor**

Uso del Command y Query Bus
---------------------------

[](#uso-del-command-y-query-bus)

Para utilizar las clases `CommandBus` y `QueryBus`, asegúrate de incluir los siguientes **namespaces** en tu archivo:

```
use Pupadevs\Laramain\Shared\CQRS\Command\CommandBus;
use Pupadevs\Laramain\Shared\CQRS\Query\QueryBus;
```

### **Creando Comando personalizado**

[](#creando-comando-personalizado)

- En la ubicacion **App/Commands**, crearemos nuestros commandos y sus respectivos manejadores
- Para la creacion de un Comando , necesitamos implementar de la interfaz Command **use Pupadevs\\Laramain\\Shared\\CQRS\\Command\\CommandBus;**

```
namespace App\Commands;

class CreateUserCommand implements Command
{
    public string $name;
    public string $email;
    public string $password;

    public function __construct(string $name, string $email, string $password)
    {
        $this->name = $name;
        $this->email = $email;
        $this->password = $password;
    }
}
```

- **Creando Manejador de comando**-En la misma ubicación donde hemos creado nuestro Command, también debemos crear su Handler. ¡Importante! El nombre del Handler debe ser exactamente igual al del Command, pero con la palabra **"Handler"** al final. Por ejemplo:

```
namespace App\Commands;

use App\Commands\CreateUserCommand;
use App\Repositories\UserRepository;

class CreateUserCommandHandler
{
    protected $userRepository;

    public function __construct(UserRepository $userRepository)
    {
        $this->userRepository = $userRepository;
    }

    public function handle(CreateUserCommand $command)
    {
        // Lógica para crear un usuario
        $this->userRepository->create([
            'name' => $command->name,
            'email' => $command->email,
            'password' => bcrypt($command->password),
        ]);
    }
}
```

### **Creando Query personalizada**

[](#creando-query-personalizada)

- En la ubicacion **App/Querys**, crearemos nuestros commandos y sus respectivos manejadores
- Para la creacion de un Comando , necesitamos implementar la interface Query **use Pupadevs\\Laramain\\Shared\\CQRS\\Query\\QueryBus;**

```
class CheckEmailQuery implements Query
{

    public Email $email;

    public function __construct( Email $email)
    {

        $this->email = $email;

    }

    public function getEmail(){
        return $this->email;
    }
}
```

- **Creando Manejador de Query**-En la misma ubicación donde hemos creado nuestra Query, también debemos crear su Handler. ¡Importante! El nombre del Handler debe ser exactamente igual al de la Query, pero con la palabra **"Handler"** al final. Por ejemplo:

```
namespace App\Query;

use App\Queyr\CheckEmailQuery;
use App\Repositories\UserRepository;

class CheckEmailQueryHanlder
{
    protected $userRepository;

    public function __construct(UserRepository $userRepository)
    {
        $this->userRepository = $userRepository;
    }

    public function handle(CheckEmailQuery $query)
    {
       return $this->userRepository->findEmail($query->toString());
    }
}
```

### Luego, puedes instanciarlas en tu Servcio o controlador como se muestra a continuación:

[](#luego-puedes-instanciarlas-en-tu-servcio-o-controlador-como-se-muestra-a-continuación)

**Uso en un servicio de Aplicacion**

```
class YourService
{
    protected CommandBus $command;
    protected QueryBus $query;

    public function __construct(CommandBus $commandBus, QueryBus $queryBus)
    {
        $this->command = $commandBus;
        $this->query = $queryBus;
    }

    public function someMethod($email)
    {
        $this->query->handle(new CheckEmailQuery(new Email($email)));
    }
}
```

**Uso en un Controlador**

```
Class SomeController{

    protected CommandBus $command;
    protected QueryBus $query;

    public function __construct(CommandBus $command, QueryBus $query)
    {
        $this->command = $commandBus;
        $this->query = $queryBus;
    }

    public function showSomeThings(Request $request){
        $this->query->handle(new CheckEmailQuery($request->email));
        $this->command->execute(new CreateUserCommand($request->all()));
    }
}
```

### Uso de la Interfaz StringValueObject y la Clase Identifier

[](#uso-de-la-interfaz-stringvalueobject-y-la-clase-identifier)

### Interfaz StringValueObject

[](#interfaz-stringvalueobject)

La interfaz `StringValueObject` asegura que cualquier clase que la implemente debe ser capaz de convertirse a una representación de cadena, proporcionando métodos para manejar esta conversión.

#### Métodos de la Interfaz

[](#métodos-de-la-interfaz)

```
interface StringValueObject
{
    public function toString(): string;

    public function __toString(): string;
}
```

### Clase Identifier

[](#clase-identifier)

La clase Identifier implementa la interfaz StringValueObject y representa un identificador único basado en UUID. **Instanciación**Para usar la clase Identifier, primero incluye el namespace correspondiente:

```
use Pupadevs\Laramain\Shared\YourNamespace\Identifier;
```

Luego, puedes crear una instancia de la clase Identifier. Si no proporcionas un identificador, se generará uno automáticamente:

```
// Genera un nuevo identificador único (UUID)
$identifier = new Identifier();
```

**Conversión a Cadena**Para convertir el identificador a cadena de texto, puedes usar el método **toString()** o simplemente tratar la instancia como una cadena:

```
// Usando el método toString()
echo $identifier->toString(); // Imprime el UUID generado
```

Version 2.0.0
-------------

[](#version-200)

### Nuevas funcionalidades

[](#nuevas-funcionalidades)

- Nueva funcion intalacion basica
- Se agregó la carpeta DTOs a la capa de App a la instalacion con parametros.
- Se agregó la carpeta Middlewares y Requests a la capa de Infrastructure a la instalacion con parametros.
- Se agregan EventProvider y DependencyProvider a la carpeta Shared para manejar evento y DIP

Licencia
--------

[](#licencia)

Este proyecto está bajo la Licencia MIT.

Colaboración
------------

[](#colaboración)

Si deseas contribuir a **Pupadevs\\Laramain**, por favor sigue estos pasos:

1. **Fork del repositorio**: Crea un fork del repositorio en GitHub.
2. **Crea una nueva rama**: Realiza tus cambios en una nueva rama utilizando el siguiente comando: ```
    git checkout -b nombre-de-la-rama
    ```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

8

Last Release

594d ago

Major Versions

1.4.5 → 2.0.02024-09-24

PHP version history (3 changes)1.0.0PHP ^7.3|^8.0

1.3.0PHP ^8.0|^8.2

1.4.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/60d5ae750e407a0f83b833ac00916ae95f1ffa1f5af6943972ee32a21de19615?d=identicon)[pesedevs](/maintainers/pesedevs)

---

Top Contributors

[![petersonsenadevs](https://avatars.githubusercontent.com/u/121895258?v=4)](https://github.com/petersonsenadevs "petersonsenadevs (5 commits)")

### Embed Badge

![Health badge](/badges/pupadevs-laramain/health.svg)

```
[![Health](https://phpackages.com/badges/pupadevs-laramain/health.svg)](https://phpackages.com/packages/pupadevs-laramain)
```

###  Alternatives

[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.2k84.2M225](/packages/laravel-horizon)[laravel/ui

Laravel UI utilities and presets.

2.7k134.9M600](/packages/laravel-ui)[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M531](/packages/laravel-passport)[laravel/sail

Docker files for running a basic Laravel application.

1.9k186.9M1.0k](/packages/laravel-sail)[laravel/jetstream

Tailwind scaffolding for the Laravel framework.

4.1k19.8M136](/packages/laravel-jetstream)[laravel/breeze

Minimal Laravel authentication scaffolding with Blade and Tailwind.

3.0k31.3M148](/packages/laravel-breeze)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
