Library Domain — dettaglio

> Library Domain

Library Domain
PHP

iadicola/domain

DTO-driven domain persistence layer for Laravel

iadicola/domain is a Laravel-oriented library that introduces a DTO-first approach to data persistence, making Data Transfer Objects the single source of truth for create, update, and upsert operations on Eloquent models.

The goal of this library is to make persistence explicit, intentional, and testable, avoiding anonymous arrays and hidden model mutations spread across the codebase.

Project status

Initial version: 0.1.0

Public API may evolve

Tooling (Artisan commands) is not included in the core package

Tests

The project is covered by unit tests based on PHPUnit.

To run the full test suite, simply execute:

composer test

The command uses TestDox format with colored output to clearly display which classes and methods are being tested.

Goals

  • Centralize persistence logic using DTOs
  • Avoid raw arrays in repositories and services
  • Make create / update / upsert flows explicit
  • Reduce tight coupling between application code and Eloquent models
  • Improve readability, predictability, and testability

What this library is NOT

  • Not an ORM
  • Not a replacement for Eloquent
  • Not a full DDD or Hexagonal Architecture framework
  • Not responsible for validation or business logic

This library focuses only on DTO-driven persistence.


Package structure


Core concepts

Data Transfer Objects (DTO)

DTOs represent persistable data, not Eloquent models.

They:

  • Expose only writable attributes
  • Define unique keys via unique()
  • Filter attributes according to the model fillable
  • Act as the single source of truth for persistence

All DTOs must implement IDTO and extend BaseDTO.


DTO-driven repositories

Repositories never accept raw arrays.

The data flow is always explicit: DTO → Repository → Model

This prevents hidden mutations and unclear persistence behavior.


DTO example

final class UserDTO extends BaseDTO
{
    public function __construct(
        ?int $id,
        public string $name,
        public string $email
    ) {
        parent::__construct($id);
    }

    public static function fromModel(Model $model): static
    {
        return new static(
            $model->id,
            $model->name,
            $model->email
        );
    }

    public function unique(): array
    {
        return ['email' => $this->email];
    }
}

Stateless usage (explicit)

$dto = UserDTO::fromModel($user);

$repository = new BaseDTORepository(new User());

$repository->update($dto);

Stateful usage (ergonomic)

$dto = UserDTO::fromModel($user);

$repository = new StatefulDTORepository(
    new BaseDTORepository(new User()),
    $dto
);

$repository->update();

Fast Usage

use App\Model\User
$dto = UsetDTO::fromArray($request->all())->repo(new User)->create();

Progetti

Ecommerce library
Ecommerce library $ open --project

Ecommerce library

Laravel JavaScript MySQL CSS
Ecommerce completo in Laravel con gestione sconti, ordini, mail e analisi vendite.
offline
Multi-Marketplace Management System
Multi-Marketplace Management System $ open --project

Multi-Marketplace Management System

Laravel Filament PostgreSQL CSS
Sistema di gestione multi-marketplace con integrazione eBay, Amazon SP-API e altri canali per sincronizzazione prodotti, stock, prezzi e ordini.
offline
MDC Project - Schindler
MDC Project - Schindler $ open --project

MDC Project - Schindler

PHP Laravel Docker
Server di calcolo e reportistica per Schindler, a supporto dell'installazione di ascensori terrestri e navali tramite modelli fisici ingegneristici.
offline
Healthcare Management System - Emodial
Healthcare Management System - Emodial $ open --project

Healthcare Management System - Emodial

Java Spring Boot Python
Sistema gestionale sanitario per Emodai, con supporto a workflow operativi e gestione dati sensibili in ambiente regolamentato.
offline
Tourism Management & Data Analysis
Tourism Management & Data Analysis $ open --project

Tourism Management & Data Analysis

Laravel JavaScript MySQL CSS
Sistemi gestionali per il settore turistico con dashboard, moduli analitici e strumenti di analisi trend e dati.
offline
Finance & Credit Management Systems
Finance & Credit Management Systems $ open --project

Finance & Credit Management Systems

PHP Laravel JavaScript
Sistemi di gestione finanziaria e creditizia sviluppati per Sagres S.p.A., con funzionalità custom per processi aziendali interni.
offline