Skip to content

Creating a New Domain

1. Identify Domain Boundaries

Before creating a domain, ensure:

  • The domain represents a cohesive business capability
  • Responsibilities are clearly defined
  • Dependencies on other domains are minimal
  • The domain can be understood and maintained independently

2. Create Domain Structure

bash
# Use the domain creation script (recommended)
php artisan make:module DomainName

# Or manually create the structure
mkdir -p modules/DomainName/{Config,Database/{Migrations,Seeders,Factories},Http/{Controllers,Requests,Resources,Middleware},Models,Events,Listeners,Jobs,Notifications,Policies,Providers,Routes,Services,ValueObjects,Tests/{Feature,Unit}}

3. Define Domain Models

Identify the core entities and value objects:

php
// modules/DomainName/Models/DomainEntity.php
namespace Modules\DomainName\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Concerns\HasUuids;

class DomainEntity extends Model
{
    use HasUuids;

    protected $fillable = ['name', 'status'];

    protected $casts = [
        'status' => 'string',
    ];
}

4. Create Domain Service

Encapsulate business logic in service classes:

php
// modules/DomainName/Services/DomainService.php
namespace Modules\DomainName\Services;

use Modules\DomainName\Models\DomainEntity;

class DomainService
{
    public function create(array $data): DomainEntity
    {
        // Business logic here
        return DomainEntity::create($data);
    }

    public function processBusinessLogic(DomainEntity $entity): void
    {
        // Complex domain logic
    }
}

5. Configure Domain

php
// modules/DomainName/Config/config.php
return [
    'name' => 'DomainName',
    'enabled' => true,
    'features' => [
        'feature_flag_1' => env('DOMAIN_FEATURE_1', false),
    ],
];

6. Register Domain

php
// config/platform.common.modules
return [
    'enabled' => [
        'Vendors',
        'Listings',
        'DomainName', // Add here
    ],
    'classes' => [
        'DomainName' => \Modules\DomainName\Providers\DomainServiceProvider::class,
    ],
];

Wedissimo API Documentation