Skip to content

Patterns

The audit trail

An audit trail is the history of a record: every state change writes one entry with the person, the time and, where it matters, the reason. In Meadowstack the api or the database writes that entry together with the change, never the screen, and `AuditTimeline` shows it oldest first, decisions marked by their status glyph and written text as a filled bubble.

By Bohuslav PoláčekChecked

templates/starter/src/modules/requests/domain/status.tsx
/** Routine events get a dot; decisions get their status glyph. */
export const eventMeta: Record<
  RequestEventType,
  { title: string; tone: "neutral" | "success" | "danger" | "warning" | "info"; icon?: ReactNode }
> = {
  created: { title: "Created", tone: "neutral" },
  edited: { title: "Edited", tone: "neutral" },
  submitted: { title: "Submitted for approval", tone: "warning", icon: statusMeta.submitted.icon },
  withdrawn: { title: "Withdrawn to draft", tone: "neutral", icon: statusMeta.draft.icon },
  approved: { title: "Approved", tone: "success", icon: statusMeta.approved.icon },
  rejected: { title: "Rejected", tone: "danger", icon: statusMeta.rejected.icon },
  reopened: { title: "Decision undone", tone: "warning", icon: statusMeta.submitted.icon },
  commented: { title: "Comment", tone: "neutral" },
};
How each history entry of the starter's purchase request reads: a label, not a sentence, with the status glyph for a decision and a dot for routine work. Read from the repository when the site was built.

Open it in the live demo

The flow, step by step

What the history of one purchase request in the starter shows, entry by entry:

  1. Created. Leah writes a draft. The first entry is "Created", her name and the time beside it.
  2. Edited. She changes the supplier and the amount and saves. One entry, "Edited", and under it what changed, old value to new; a rewritten reason reads "Reason rewritten". Saving without a change writes nothing.
  3. Submitted for approval. The entry carries the half-filled waiting glyph, so the moment the request left her hands stands out from the edits.
  4. Rejected. Marcus rejects it. The entry is in the danger tone with the rejected glyph, and his reason sits under it in a filled bubble, where Leah will look for it.
  5. Comment. Anyone who may read the request writes under the history in a Composer (Cmd/Ctrl+Enter sends). The comment lands as a bubble under a "Comment" label. If saving fails, the text stays in the box and a toast says so; the api refuses an empty comment.
  6. Decision undone. If Marcus presses Undo, the history gains "Decision undone". Nothing is removed: the mistake and its correction both stay.

The rules and where each one is enforced

What AI coding tools build instead

  • History written by the screen. The component that changes the status also posts an activity row. Then the bulk bar, an import or a second screen changes the status without one, and the gaps show only when someone needs the history. The entry belongs where the change is saved.
  • A sentence with the person as subject, "Marcus approved the request". It repeats the name the line already shows and has to agree with every person it names. A label, "Approved", with the person beside it reads right for everyone.
  • Every entry the same weight. Twenty "Edited" lines bury the one rejection. Decisions get their glyph and tone, the rest a dot.
  • Comments in a separate tab, so the reason for a decision and the talk about it live in two places. Here a comment is an entry in the same history, and the Composer sits under it.
  • An editable history, an update endpoint or an admin screen that corrects entries. A trail anyone can rewrite proves nothing.
  • The actor read from the request body. Anyone can then write history in someone else's name. The database fills it from the session.
  • "Updated" and nothing else. An edit here names what it changed, and a save that changed nothing writes nothing.

Where to see it

  • Document inbox: a document's history in its side panel.
  • Time-off approval: a leave request's decision card and its history.
  • In the print shop of Foldline, a customer signed in for proofs sees only their side of a job's history (customerEvents in the module's domain/permissions.ts); the shop's own notes never reach them.
  • The kit's AuditTimeline and Composer, the approval flow whose moves fill the history, and permissions, which decide whose history shows what.

Example apps with a record history

Which example apps and modules render the kit's AuditTimeline, computed from the demo's code when the site was built.Read from the demo's source when the site was built: 9 of 9 example apps render <AuditTimeline>, in the modules named here as each app's sidebar names them.

The history table in Postgres

docs/recipes/examples/supabase/0001_requests.sql
-- History: every change writes one row, in the same transaction, and nobody
-- edits or deletes a row (no update or delete policy exists).
create table public.request_events (
  id uuid primary key default gen_random_uuid(),
  request_id uuid not null references public.requests (id) on delete cascade,
  type text not null
    check (type in ('created', 'edited', 'submitted', 'withdrawn', 'approved', 'rejected', 'reopened', 'commented')),
  actor_id uuid not null default auth.uid() references public.profiles (id),
  actor_name text not null default public.app_name(),
  at timestamptz not null default now(),
  detail text
);
The starter's Supabase example: one row for every change, the person filled in from the session, and no policy that lets anyone edit or delete a row.

Questions

Should the frontend or the backend write audit log entries?

The backend, in the same transaction as the change. A screen can only log the changes made through it, and the first import, bulk action or second screen leaves a gap. In the starter's Supabase example a trigger writes the row, so no client can forget it.

Can someone delete or correct a history entry?

No. The history table has no update or delete policy, and a correction is a new entry: an undone decision adds Decision undone rather than removing Approved.

Why are entries labels like Approved instead of sentences?

The person is already beside the label with their avatar, so a sentence would say the name twice, and a sentence has to agree with whoever it names. A label reads right for everyone and scans faster down a long history.

Where do comments go?

Into the same history, as a filled bubble under a Comment label, with the box to write in underneath. A reason for a rejection appears the same way, so everything said about the record reads in one place, oldest first.

Does a customer see the same history as the staff?

Not in the demo's print shop. A customer sees the steps of their own job, from the quote to the delivery, while the shop's notes and its internal steps, such as a colleague's check of a proof, stay with the staff. The filter is part of the permissions, not of the screen.

Two ways

Build it yourself, or have it built

  • Build it yourself

    Build your app on the framework

    Get the codebase these apps stand on and build yours with Claude Code, Cursor or Codex.

    One payment, lifetime updates

    Get the framework
  • Have it built

    Have us build your app

    Tell us how your team works. We plan the app with you and build it on the same framework at a fixed price.

    After launch, Care keeps it improving, from €99 a month.

    from €1,990

    Describe your app