---
name: audit-observers
description: The observer-based audit logging and soft-delete situation in the Mediknode/Unified codebase. Use when creating/updating/deleting User, Participant, ParticipantWorkshop, or Document records, when adding soft deletes, or when reasoning about the audits table and data integrity on delete.
---

# Audit observers & deletion

## Automatic audit logging
These observers (in `app/Observers/`) log create/update/delete to the `audits` table as changed-JSON — automatically:
- `UserObserver`, `ParticipantObserver`, `ParticipantWorkshopObserver`, plus a generic `ModelObserver` (no dedicated `DocumentObserver` — `Document` audit, if any, goes through `ModelObserver`).

**Implications:**
- Don't hand-roll audit logging for these models — it's already done.
- Every write to these models has a side effect (an `audits` row). Tests must account for it.
- A bulk/raw `DB::table()->update()` **bypasses observers** → no audit. Use Eloquent for audited models unless you deliberately want to skip the trail.

## Soft delete (partial today)
- Only `User`, `Participant`, `Show`, `Doctor`, `Lista` use `SoftDeletes`.
- Backlog #33/#36 want soft delete **everywhere** ("pas de delete physique"). When generalizing:
  1. Add `deleted_at` migration per table.
  2. Add `use SoftDeletes;` to the model.
  3. Audit the cascade behaviour (#29): FK `onDelete` rules, relationships that assume hard delete, queries that need `withTrashed()`.
  4. Add a regression test proving the record is hidden but recoverable.
- **Hard-deleting an audited entity destroys its audit trail** — flag this in reviews.

See also: [[project-conventions]], [[meta-pattern]].
