# Audit trail

An audit trail is a chronological record of a system's activity that is complete enough to reconstruct who did what, to which record, and when. In a business app it answers the question every dispute starts with, and Meadowstack 2.1 shows it on every record with `AuditTimeline` while your backend keeps the record itself.

Checked 2 December 2026. By Bohuslav Poláček. https://meadowstack.com/glossary/audit-trail/

*The Supabase example's history trigger: the database, not the client, decides what kind of change happened.*

From `docs/recipes/examples/supabase/0001_requests.sql` in the Meadowstack repository:

```sql
-- The history row for every change, written by the database so no client can
-- forget it. Security definer: people cannot insert these rows themselves.
create function public.requests_history() returns trigger
  language plpgsql security definer set search_path = ''
  as $$
declare
  kind text;
  changes text[] := '{}';
begin
  if tg_op = 'INSERT' then
    kind := 'created';
  elsif new.status is distinct from old.status then
    kind := case
      when new.status = 'submitted' and old.status in ('approved', 'rejected') then 'reopened'
      when new.status = 'submitted' then 'submitted'
      when new.status = 'draft' then 'withdrawn'
      else new.status
```

## Why it matters in a business app

"Who approved this?" and "when did the amount change?" come up every week in a business that runs on requests, orders and invoices. Without a history the answer is a meeting. With one, it is a line on the record: the person, the change, the time, and the reason when one was required.

A trail is evidence only if it cannot drift from the data. That rules out a log written by the browser after the fact: the entry has to be written where the change is, and nobody may edit it later.

## How Meadowstack handles it

What 2.1 does in the interface:

- Every state change in the starter and the demo writes an entry, and every record shows its history with [AuditTimeline](https://meadowstack.com/components/audit-timeline/); a rejection always carries its reason.
- The simulated api writes the entry with the change, the shape your backend should keep.

What the server side needs, from `docs/security.md`: the entry written **in the same transaction** as the change, the table **append-only** (the app's role may insert and read, never update or delete), every change covered, and no secrets or extra personal data in the detail. The Supabase example does exactly that with the trigger above and a history table with no update or delete policy.

Meadowstack 3.0, coming as an update to every licence, adds an audit trail of security events too: sign-ins, permission changes, exports and deletions, with who, what, when and from where. See also [the audit trail pattern](https://meadowstack.com/patterns/audit-trail/).

## Common mistakes

- **History written by the client.** A second request that can fail or be skipped is a history that lies.
- **An editable history table.** If the app's role can update it, so can a bug.
- **Logging everything.** Passwords, tokens and whole records in the detail turn the history into a leak.
- **Prose instead of facts.** "Updated" says nothing; the old and the new amount say what happened, the way the Supabase example writes "Amount: old → new".

## How people read it

*Two histories from the demo in AuditTimeline: a change order's decisions and a task's first changes.*

A live screen, rendered from the kit's components on the page: https://meadowstack.com/glossary/audit-trail/

## Questions

### What is the difference between an audit trail and application logs?

Logs are for developers and are rotated away; an audit trail is for people and auditors, tied to records, kept as long as the records, and never edited.

### Does Meadowstack store the audit trail?

Not in 2.1: it shows the history and writes it in the simulated api, and your backend stores it. The Supabase example shows a history table written by a trigger in the same transaction.

### Should an audit trail record reads as well as changes?

Record changes always. Record reads where the data is sensitive or the law asks for it, such as exports of personal data; logging every view of every list is noise.

## Sources

- [NIST CSRC Glossary, audit trail](https://csrc.nist.gov/glossary/term/audit_trail), checked 2 December 2026

## Related

- [The audit trail](https://meadowstack.com/patterns/audit-trail/) (Patterns)
- [Postgres: the person in a transaction setting](https://meadowstack.com/integrations/postgres/) (Integrations)
- [Soft delete](https://meadowstack.com/glossary/soft-delete/) (Glossary)
- [NIS2 Article 21 checklist for web apps](https://meadowstack.com/blog/nis2-article-21-checklist-for-web-apps/) (Blog)
- [From Access or FileMaker to a web app](https://meadowstack.com/from/access-filemaker/) (Moving from)
- [A document inbox that catches a changed bank account](https://meadowstack.com/screens/document-inbox/) (Screens)
