# Notification prototype

Build a small Laravel, Inertia and Vue app demonstrating our own toast messages and a persistent notification inbox. Use the supplied blank app. Keep it straightforward and pleasant to use; this is a prototype for a developer to review, not a production service.

## Toasts

Provide success, info, warning and error messages, plus a loading message that can change to success or error. Support a title, optional description and close button. Ordinary messages disappear after a few seconds; pause dismissal while hovered or keyboard-focused. An action button can run an async task, shows that it is working and handles failure without silently losing the action.

Multiple messages should form a neat stack without covering the whole page. Include restrained enter/exit transitions, respect reduced motion and announce messages accessibly. Toasts should survive Inertia navigation. Demonstrate messages fired directly in Vue and flashed from Laravel across a redirect, showing each server message once.

## Inbox

Use Laravel's notification facilities to store messages for the signed-in user. Put a bell and unread badge in the persistent header. Clicking it opens a panel with recent messages and a link to a full inbox page. Show a title, body, time and read state. Support mark read/unread, archive, and mark all read. Keep the panel, page and badge consistent after actions. The full page needs unread/archived views and pagination or load more.

Provide two local demo identities and a way to switch between them. Users must never read or change another user's notifications, including by guessing an ID. Gate demo identity switching to local development. Include clear buttons for generating sample notifications and trying toast behaviour, with brief expected-result instructions. Empty, pending and failed states should be understandable. Use responsive layouts and keyboard-friendly controls.

## Done

Run relevant backend tests, build the frontend, and leave the app working for browser review. Cover user isolation and notification state changes in tests. Document how to run it, what is incomplete and any shortcuts. Implement the toast/inbox UI ourselves; do not add a notification UI or toast library. Existing framework facilities and standard Vue/CSS are fine.

No tenants, email delivery, digests, notification preferences, WebSockets or web push in this prototype.

## Interaction requirements (added for this run)

- **Bounded stack.** At most one toast is fully visible at rest. Up to two more sit visibly behind it (offset and scaled down), and the rest are hidden. The stack never grows taller than about one and a half toasts and never scrolls.
- **Expand on hover or focus.** Hovering the stack, or moving keyboard focus into it, fans the toasts out into a list. Leaving collapses it again. Dismissing one while expanded reflows the others smoothly.
- **Repeat counter.** An ordinary toast (no action, not loading, no explicit id) with the same type, title and description as one already visible does not add a new toast. It increments a counter badge on the existing one (for example "×8") and restarts its timer.
- **Loading.** Use a proper spinner (SVG or CSS ring), not a rotating text character. Only the spinner rotates. Changing a loading toast to success or error transitions in place.
- **Persistent toasts.** Action and loading toasts stay until handled, but they still collapse into the bounded stack. Nothing is silently discarded: if a cap is needed, older ordinary toasts may go, never actions.
- **Inbox finish.** The panel and page should look like a finished product: clear unread markers, readable type hierarchy, consistent spacing, icon buttons with labels/tooltips, and visible focus states.

## Architecture (added for this run)

Write this as if it will be read by other developers and extended for years. Assume categories, per-user preferences, email digests, tenants and real-time delivery will arrive later. Don't build them, but don't make them hard to add.

- **Domain.** Give notifications their own model (extend Laravel's `DatabaseNotification` and point the notifiable relation at it). The lifecycle rules live there: named scopes for active, unread and archived, and intention-revealing methods such as `markAsRead()`, `archive()` and `restore()`. Nothing outside the model should write `read_at` or `archived_at` directly.
- **Application.** Anything that changes state across several records, such as mark all read, goes in a small single-purpose action class. Controllers call actions or model methods. They don't build queries.
- **Query.** A single inbox query object defines the views (all, unread, archived) and the ordering. The panel, page and badge all use it, so a count can never disagree with a list.
- **HTTP.** Controllers stay thin: Form Requests for validation and authorisation, API Resources as the only transformation layer between the model and the frontend. The payload shape is a contract. Keep the notification's own data under a stable key so new notification types don't change it.
- **Persistence.** Add indexes that match the queries the inbox actually runs (recipient + archived + created, recipient + read). Note in the README which query each one serves.
- **Frontend.** Keep state in composables (`useToasts`, `useInbox`) as plain, framework-light modules with no DOM access, and keep components presentational. Toast stacking, counting and capping should be pure functions you can unit test.
- **Components.** Build the UI on Reka UI (already installed) for accessible primitives: popover for the bell panel, tooltips, menus, focus management. Don't use its Toast primitive or any other toast or notification component. The toast stack is ours. Style with Tailwind.

## Tests (added for this run)

Feature tests for each scope, endpoint and action, plus isolation tests. Unit-test the pure toast functions with Vitest (already installed).
