Add modular layered architecture with Customers module

Introduce a modular monolith under app/Modules with Domain, Application,
Infrastructure and Presentation layers.

- Shared module: DomainException base, TransactionManager and an
  EventDispatcher that publishes events after commit.
- Customers module: Customer entity, CustomerName and BusinessId
  (Y-tunnus checksum) value objects, RegisterCustomer/UpdateCustomer
  use cases, CustomerQueries read contract, Eloquent repository, and
  Livewire list and form pages with Finnish translations.
- Pest arch tests enforce layer and module dependency rules for every
  module; Larastan (level 6) added as a dev dependency.
- Raise Flux error text contrast to meet WCAG 2.2 AA.
- Document the architecture in docs/architecture.md and CLAUDE.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-22 10:23:33 +02:00
co-authored by Claude Opus 5.5
parent d403a86443
commit a3fb09bbf6
55 changed files with 2270 additions and 3 deletions
+18
View File
@@ -0,0 +1,18 @@
<?php
namespace Tests\Fakes;
use App\Modules\Shared\Application\Contracts\EventDispatcher;
class FakeEventDispatcher implements EventDispatcher
{
/**
* @var list<object>
*/
public array $dispatched = [];
public function dispatch(object ...$events): void
{
array_push($this->dispatched, ...$events);
}
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace Tests\Fakes;
use App\Modules\Shared\Application\Contracts\TransactionManager;
class FakeTransactionManager implements TransactionManager
{
public int $transactionCount = 0;
public function run(callable $work): mixed
{
$this->transactionCount++;
return $work();
}
}
@@ -0,0 +1,43 @@
<?php
namespace Tests\Fakes;
use App\Modules\Customers\Domain\Contracts\CustomerRepository;
use App\Modules\Customers\Domain\Entities\Customer;
use App\Modules\Customers\Domain\ValueObjects\BusinessId;
class InMemoryCustomerRepository implements CustomerRepository
{
/**
* @var array<int, Customer>
*/
public array $customers = [];
private int $nextId = 1;
public function findById(int $id): ?Customer
{
return isset($this->customers[$id]) ? clone $this->customers[$id] : null;
}
public function save(Customer $customer): Customer
{
$id = $customer->id() ?? $this->nextId++;
$stored = Customer::reconstitute($id, $customer->name(), $customer->type(), $customer->businessId());
$this->customers[$id] = $stored;
return clone $stored;
}
public function isBusinessIdTaken(BusinessId $businessId, ?int $exceptCustomerId = null): bool
{
foreach ($this->customers as $id => $customer) {
if ($id !== $exceptCustomerId && $customer->businessId()?->equals($businessId)) {
return true;
}
}
return false;
}
}