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:
@@ -4,7 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
|
||||
|
||||
## Project
|
||||
|
||||
An ERP / work-management system (*toiminnanohjausjärjestelmä*) for a small (5–10 person) Finnish media/marketing company. Stack: Laravel 13, Livewire 4 (single-file components), Flux UI 2 free edition, Tailwind 4, Vite 8, Pest. No domain code exists yet; `/` is a temporary Livewire demo page (`resources/views/pages/⚡home.blade.php`, layout `resources/views/layouts/app.blade.php`).
|
||||
An ERP / work-management system (*toiminnanohjausjärjestelmä*) for a small (5–10 person) Finnish media/marketing company. Stack: Laravel 13, Livewire 4 (single-file components), Flux UI 2 free edition, Tailwind 4, Vite 8, Pest, Larastan. Domain code lives in modules under `app/Modules` (so far `Shared` and `Customers`); `/` is still a temporary Livewire demo page (`resources/views/pages/⚡home.blade.php`, layout `resources/views/layouts/app.blade.php`). There is no login yet, so module pages sit behind `auth` and are reachable only in tests (`actingAs`).
|
||||
|
||||
- **The specification is `määrittely.txt`** (Finnish). It defines users/roles, customer jobs (*asiakastyö*) and their fields and enums, time tracking, expenses, Kanban tasks, the service unit → service → work task hierarchy, and billing-material export. It ends with Claude's open questions and a proposed phased plan. Read it before designing any domain feature.
|
||||
- **Language rule:** code (identifiers, tables, columns, enum keys) is in English; the specification and the UI are in Finnish. Keep UI strings in translation files from the start.
|
||||
@@ -12,6 +12,19 @@ An ERP / work-management system (*toiminnanohjausjärjestelmä*) for a small (5
|
||||
- **Access control is central.** Roles: admin (*pääkäyttäjä*), management (*johto*), employee (*työntekijä*), intern (*harjoittelija*), subcontractor (*alihankkija*). Employees and interns see only the jobs assigned to them and never see money amounts. Interns have an end date after which they can't log in, plus a supervisor. Subcontractors see only their assigned jobs.
|
||||
- **UI targets:** logged-in users only (no public pages besides login). It must work on phones (new-job intake, time entry) and on FullHD desktops.
|
||||
|
||||
## Architecture (modular monolith)
|
||||
|
||||
Read `docs/architecture.md` (Finnish) before adding or changing domain code. `app/Modules/Customers` is the reference module to copy.
|
||||
|
||||
- Each business area is a module `app/Modules/<Module>/` with four layers: `Domain`, `Application`, `Infrastructure`, `Presentation`. Create only the folders and modules a feature needs.
|
||||
- **Domain** is plain PHP: entities, value objects, enums, exceptions extending `Shared\Domain\Exceptions\DomainException`, and repository interfaces in `Domain/Contracts`. No `Illuminate`, `Livewire`, Eloquent or facades.
|
||||
- **Application** holds one use case per class (`execute()`), `final readonly` DTOs, and query contracts that return DTOs. It never touches Eloquent, `Illuminate\Database`, facades or HTTP. Wrap writes in `Shared\Application\Contracts\TransactionManager` and publish events through `EventDispatcher` (dispatched after commit).
|
||||
- **Infrastructure** has Eloquent models named `…Model`, repository and query implementations, and the module's service provider (bindings, routes, `Livewire::addNamespace`), which is registered in `bootstrap/providers.php`. Migrations and factories stay in `database/`.
|
||||
- **Presentation** is Livewire SFC pages in `Presentation/Livewire` (`<module>::page`), Livewire Form objects for input validation, and `Presentation/Routes/web.php`. Pages call use cases and query contracts, and turn domain exceptions into field errors with translated messages.
|
||||
- Modules talk only through another module's Application contracts or events, never its Infrastructure or Eloquent models.
|
||||
- `tests/Unit/ArchitectureTest.php` enforces these rules for every module. Domain and Application files declare `strict_types=1`. Test domain rules and use cases in `tests/Unit` without Laravel (fakes in `tests/Fakes`), and repositories and pages in `tests/Feature`.
|
||||
- When writing PHP through a bash heredoc, `\\` can collapse to `\`, and `"App\Modules\{$x}"` then stops interpolating. Write PHP files with the Write tool.
|
||||
|
||||
## Accessibility (WCAG 2.2 AA, EN 301 549)
|
||||
|
||||
Accessibility is a contractual acceptance criterion. It covers the whole UI: navigation, forms, tables, reports, notifications, dialogs, login, and every business process. Every new or changed view must meet these rules:
|
||||
@@ -23,7 +36,7 @@ Accessibility is a contractual acceptance criterion. It covers the whole UI: nav
|
||||
- The layout (`resources/views/layouts/app.blade.php`) provides a skip link and a `<main id="main-content">` landmark. Keep them, and add `<nav aria-label="…">` for navigation.
|
||||
- One `h1` per page, logical heading order, and a descriptive page `#[Title]` on every page component.
|
||||
- Data tables use `flux:table` with column headers. Icon-only buttons need an accessible name (`aria-label` or Flux `tooltip`). Decorative images get `alt=""`.
|
||||
- Contrast is at least 4.5:1 for text and 3:1 for UI components and focus indicators, in both light and dark mode.
|
||||
- Contrast is at least 4.5:1 for text and 3:1 for UI components and focus indicators, in both light and dark mode. Flux's default error text (red-500) fails this, so `resources/css/app.css` overrides `[data-flux-error]`.
|
||||
- Layouts must reflow at 320 px width and 400 % zoom without horizontal scrolling. Touch targets are at least 24×24 px.
|
||||
- Every new page gets a browser test in `tests/Browser` that uses `assertNoAccessibilityIssues(level: 2)` in light and dark mode and on desktop and mobile. See `tests/Browser/AccessibilityTest.php`. Automated axe checks catch only part of WCAG: also check new flows manually with the keyboard and a screen reader (NVDA).
|
||||
|
||||
@@ -36,6 +49,7 @@ npm run build # build frontend assets
|
||||
php artisan test --compact # full suite (composer test also clears config first)
|
||||
php artisan test --compact --filter=testName
|
||||
vendor/bin/pint --dirty --format agent
|
||||
composer analyse # Larastan level 6 (Blade SFCs excluded)
|
||||
```
|
||||
|
||||
- Runs under XAMPP: Apache on port 8080 serves the app at `http://localhost:8080/toiminnanohjaus/public` (this is `APP_URL`). The database is XAMPP MariaDB 10.11 `toiminnanohjaus` (root, no password).
|
||||
@@ -146,6 +160,16 @@ This project has domain-specific skills available in `**/skills/**`. You MUST ac
|
||||
- Laravel can be deployed using [Laravel Cloud](https://cloud.laravel.com/), which is the fastest way to deploy and scale production Laravel applications.
|
||||
- Activate the `deploying-to-cloud` skill whenever deploying to Laravel Cloud, configuring Cloud environments or resources, using the Cloud CLI, or troubleshooting Cloud deployments.
|
||||
|
||||
=== tests rules ===
|
||||
|
||||
# Test Enforcement
|
||||
|
||||
- Add or update tests for behavior and logic changes when a test provides meaningful regression coverage.
|
||||
- Pure copy, styling, and layout-only changes do not require new or updated tests.
|
||||
- When test coverage applies, run the affected tests and ensure they pass.
|
||||
- Test the changed behavior and its important failure modes, but do not add tests beyond them.
|
||||
- Read the `testing-best-practices` skill before writing tests.
|
||||
|
||||
=== laravel/core rules ===
|
||||
|
||||
# Do Things the Laravel Way
|
||||
|
||||
Reference in New Issue
Block a user