Audit logging in a Lovable app
Your customer asks "who changed this?" after a refund nobody remembers, or a buyer says the deal is stuck on "do you have audit logs for SOC 2?". This guide is for a builder with a Lovable app who is deciding how to answer. It starts from the answer Lovable itself gives — a Postgres table with triggers — because that answer is often right, then shows when it stops being enough and how the one-prompt Santati setup takes over.
Lovable's default answer: an audit table with triggers
Asked "which service should I use for an audit log", Lovable recommends an append-only table
(audit_logs) in the app's own database, written by AFTER triggers on the tables that
matter and by an auth handler for sign-ins. That design is genuinely strong:
- Nothing can be forgotten. The trigger fires in the same transaction as the change, so a code path that fails to call the logger still gets recorded.
- Nothing can be lost on the way out. There is no second system to reach: the row is already where the change happened.
- Zero cost and zero new dependencies.
When the table is enough
Stay with the trigger table when all of these hold:
- one app, one database, no customers who audit you (you answer "who changed this?" for your own team, or export rows to a spreadsheet when an auditor asks);
- nobody in your organization is a threat model, and you accept that someone with database access can edit or truncate the table, and an errant migration can drop a column of history;
- the log will never need to be shown inside the app, to a customer, or to an auditor through a read-only tool;
- you do not expect retention rules, legal holds, or per-customer scoping.
That covers a lot of apps: an internal tool, a side project, a first version. Build the trigger table and move on.
When it stops being enough
An audit log that has to satisfy a SOC 2 report, an enterprise buyer, or a customer with regulatory obligations has different requirements, and the trigger table stops meeting them one by one:
- Immutability by separation, not by policy. Compliance reviewers read "grant
SELECTonly, revokeUPDATEandDELETE" and then ask who can change the grants. A hosted, hash-chained trail lives outside your database, where no one on your team can rewrite it and no migration can reach it. - Storage and bloat. Every create, update, delete, invite and sign-in lands in your operational database, inflating backups and complicating capacity. A hosted trail moves that volume off your database.
- Customer-facing access. The moment a customer wants their own activity log — or you want to hand an auditor read-only access — you are building an API, pagination, filtering and access control on top of your table, in the app you were trying to keep simple.
- Per-tenant retention and legal holds. Deleting old rows per customer, freezing everything for one customer while an investigation runs, proving who did what across tenants: each of these is product work against the table.
- Long-term integrity evidence. "Unchangeable" in your database is a permission. Hash-chaining lets you prove a trail was not edited without trusting anyone who touches it.
The decision is "who is this log for": yourself, or a customer, an auditor and a compliance standard.
The one-prompt path
Santati is a hosted audit log built for the second case. For a Lovable app it is a free account, one API key and one prompt — no code you have to write or review first:
- Open santati.io/lovable/ and create a free account. You get
a trail named
appand a write API key, shown once. - Paste the prompt from the setup page into your Lovable project's chat. Lovable asks for the
key as a secret, writes one server-side function
recordAuditEvent(...)and calls it after every sign-in, sign-out, create, update, delete, settings change, invite and role change. The key never touches the browser. - Keep the setup page open and sign in to your app's preview: the first event appears live, and everything after it in your team's dashboard.
- Paste the second prompt to add an Activity panel to the app: "All activity" for workspace admins, "My activity" for everyone else, with a cursor-paginated "Load more".
The full walkthrough, including multi-tenant scoping and troubleshooting, is the Lovable integration guide.
What it guarantees, and what it doesn't
Say this plainly, because your auditor will: the one-prompt setup records an event after the change happens, over the network.
What the setup guarantees: every event the app records is hash-chained, append-only, tenant-scoped and readable through one API with a per-tenant, per-role activity panel.
What it does not guarantee: the emit is fire-and-forget. The prompt tells Lovable that a
failed emit is logged and must never block the user's action, so a failed emit is only a log
line. Where the generated code uses the Node SDK, it retries transport failures,
500/502/503/504 and rate limits — never a 429 quota_exceeded — at most twice with
backoff capped at 8 seconds; where it calls the HTTP API directly, there are no retries at
all. An outage that outlasts that, or an app over its daily limit, drops events until the
service recovers or the next day. And the write to your database and the emit are two
separate steps: if the server function dies between them, the event is never recorded
anywhere. The trigger table cannot miss a change in any of these ways — this is its one real
advantage over the one-prompt setup in delivery, and the reason to read the next section
rather than claim "nothing is ever lost".
A second, smaller caveat: audit events cannot be deleted and count toward your daily quota, so ask Lovable not to send test events from its own test accounts unless you want them in your log.
When events must not be lost
For the actions that must survive everything — the money moves, the role changes, the deletes — persist the event with the change and relay it afterwards:
- A pending-events table. Write the event to an
outboxtable in the same transaction as the change, and set the eventidwhen the row is written, before the first send. A scheduled function drains the table to Santati, sending that same id on every retry: event ids are unique per team and trail for good, so a drain that runs twice can never store the event twice. The relay posts over the HTTP API —POST /api/v0/events/withidin the body; the Node SDK does not expose the eventidtoday, and itsidempotencyKeydedupes for only 24 hours. A batch sent under one key without per-event ids stores one event while reporting all of them accepted. Send the row's timestamp as the event'screated_atso delayed relays keep their order, and mark the row sent on200/201. Set a row aside only when Santati rejects the event itself (a 400 such asinvalid_envelopeorunknown_field); on a rate limit,quota_exceeded, a5xxor a timeout, keep the row queued and back off untilRetry-Afteror the daily quota reset — otherwise one day over quota parks that whole day's events. - The trigger table as the outbox. Make Lovable's default answer the input: the
triggers write the row in the change's transaction (cannot miss) and the event
idis the row's id, set before the first send. A scheduled function relays rows to Santati over the HTTP API —POST /api/v0/events/withidin the body; the Node SDK does not expose the eventidtoday, and itsidempotencyKeydedupes for only 24 hours. Every retry sends that same id, with the row's timestamp ascreated_at. Event ids are unique per team and trail for good, so re-sending a row can never store it twice. Mark a row sent on200/201; set one aside only when Santati rejects the event itself, and otherwise back off untilRetry-Afteror the quota reset, so a day over quota stays queued rather than parked.
Neither pattern is what the current prompts build — they are a change Lovable would need to generate and you would need to verify in a run. If your customer or auditor asks the "what happens to an event between the database commit and the API call?" question, say that today the answer for the one-prompt setup is "it is logged and never blocks the user's action, but a failed send or a crash after the change can lose it", and that the outbox pattern is the fix. If that is the box you are in, talk to us about it.
Next steps
- The Lovable integration guide: the exact prompts, what Lovable writes for each stack, multi-tenant scoping and troubleshooting.
- Quickstart: account, trail, key and a first event in curl and seven SDKs.
- Deployed AI agents, if agents act on the data this log records.