## Summary - add a shared diff presentation layer under `app/Support/Diff` with deterministic row classification, summary derivation, and value stringification - centralize diff-state badge semantics through `BadgeCatalog` with a dedicated `DiffRowStatusBadge` - add reusable Filament diff partials, focused Pest coverage, and the full SpecKit artifact set for spec 141 ## Testing - `vendor/bin/sail artisan test --compact tests/Unit/Support/Diff/DiffRowStatusTest.php tests/Unit/Support/Diff/DiffRowTest.php tests/Unit/Support/Diff/DiffPresenterTest.php tests/Unit/Support/Diff/ValueStringifierTest.php tests/Unit/Badges/DiffRowStatusBadgeTest.php tests/Feature/Support/Diff/SharedDiffSummaryPartialTest.php tests/Feature/Support/Diff/SharedDiffRowPartialTest.php tests/Feature/Support/Diff/SharedInlineListDiffPartialTest.php` - `vendor/bin/sail bin pint --dirty --format agent` ## Filament / Livewire Contract - Livewire v4.0+ compliance: unchanged and respected; this feature adds presentation support only within the existing Filament v5 / Livewire v4 stack - Provider registration: unchanged; no panel/provider changes were required, so `bootstrap/providers.php` remains the correct registration location - Global search: unchanged; no Resource or global-search behavior was added or modified - Destructive actions: none introduced in this feature - Asset strategy: no new registered Filament assets; shared Blade partials rely on the existing asset pipeline and standard deploy step for `php artisan filament:assets` when assets change generally - Testing coverage: presenter, DTOs, stringifier, badge semantics, summary partial, row partial, and inline-list partial are covered by focused Pest unit and feature tests ## Notes - Spec checklist status is complete for `specs/141-shared-diff-presentation-foundation/checklists/requirements.md` - This PR preserves specialized diff renderers and documents incremental adoption rather than forcing migration in the same change Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #170
4.6 KiB
4.6 KiB
Data Model: Shared Diff Presentation Foundation
Overview
This feature adds presentation-layer value objects and support types only. No database schema or persisted business record changes are introduced.
Entities
1. DiffRowStatus
- Type: PHP backed enum
- Purpose: Canonical presentation-state vocabulary for shared diff rendering
- Values:
unchangedchangedaddedremoved
- Rules:
- Treated as a presentation concern only
- Drives summary counts, badge semantics, icons, and row-state rendering
- Must remain reusable outside any single resource or domain service
2. DiffRow
- Type: Immutable value object / DTO
- Purpose: Render-ready representation of one compare row
- Fields:
key: stringlabel: stringstatus:DiffRowStatusoldValue: mixednewValue: mixedisListLike: booladdedItems: array<int, mixed>removedItems: array<int, mixed>unchangedItems: array<int, mixed>meta: array<string, scalar|array|null>
- Validation rules:
keymust be non-emptylabelmust be non-emptystatusmust be one of the enum values- List fragment arrays must be present as empty arrays when not used
metamust stay presentation-safe and serializable for view consumption
3. DiffSummary
- Type: Immutable value object / DTO
- Purpose: Shared summary counts and high-level message context for a rendered compare block
- Fields:
changedCount: intaddedCount: intremovedCount: intunchangedCount: inthasRows: boolmessage: ?string
- Validation rules:
- Counts are non-negative integers
hasRowsis derived from total countmessageis optional and consumer-supplied or presenter-generated fallback copy
4. DiffPresentation
- Type: Immutable value object / DTO
- Purpose: Stable wrapper returned by
DiffPresenterso consumers can pass one object containing summary and ordered rows into shared partials or downstream adapters - Fields:
summary:DiffSummaryrows: array<int, DiffRow>
- Validation rules:
summarymust always be presentrowsmust preserve deterministic ordering- Empty compares are represented as an empty
rowscollection plus an explicit summary state
5. StructuredCompareInput
- Type: Internal input shape consumed by
DiffPresenter - Purpose: Minimal adaptation contract for simple compare payloads
- Fields:
baseline: array<string, mixed>current: array<string, mixed>changedKeys: array<int, string>labels: array<string, string>meta: array<string, array<string, scalar|array|null>>
- Rules:
baselineandcurrentmay each omit keys that exist on the other sidechangedKeysis optional hint data; presenter can still derive state from valueslabelsis optional and must not block rendering when absent
6. InlineListFragments
- Type: Derived presentation fragment embedded in
DiffRow - Purpose: Simple inline list diff rendering for string or scalar lists
- Fields:
addedItems: array<int, mixed>removedItems: array<int, mixed>unchangedItems: array<int, mixed>
- Rules:
- Built only when both values are simple list-like collections appropriate for inline comparison
- Ordering should remain deterministic for stable rendering and tests
- Not intended for token-level or line-level diff logic
Relationships
- One
DiffSummarydescribes a collection ofDiffRowinstances. - Each
DiffRowhas exactly oneDiffRowStatus. DiffPresenterconverts oneStructuredCompareInputinto oneDiffPresentation, containing oneDiffSummaryplus an ordered list ofDiffRowinstances.ValueStringifierformatsDiffRow.oldValue,DiffRow.newValue, and inline list items for display, but can also be used independently by specialized views.
State transitions
Row classification
- Missing in baseline + present in current →
added - Present in baseline + missing in current →
removed - Present on both sides + materially equal →
unchanged - Present on both sides + materially different →
changed
Summary derivation
- Summary counts are derived from the final
DiffRowlist. - Empty compare input produces either an empty summary or a no-data state, but never synthetic changes.
Non-persistent boundaries
- None of these entities map to database tables.
- None of these entities may fetch models or rely on Livewire runtime state.
- None of these entities define authoritative business drift, compare, or restore logic.