v0.1.0 · MIT Licensed

The type-safe activity log for TypeScript

Framework-agnostic, multi-database audit logging modeled on the architecture of better-auth. Declare your entities once, log everything that happens, query it with confidence.

$pnpm addbetter-activity
activity.ts
import { betterActivity } from "better-activity";
import { postgresAdapter } from "better-activity/adapters/postgres";
 
export const activity = betterActivity({
database: postgresAdapter({ pool }),
entities: {
user: {
actions: ["created", "updated", "logged_in"],
metadata: {} as { ip?: string; userAgent?: string },
},
project: {
actions: ["created", "archived", "member_added"],
},
},
});
 
// Fully-typed save() — checked at compile time
await activity.save({
entity: "user", action: "logged_in",
entityId: "usr_123", actorId: "usr_123",
metadata: { ip: "1.2.3.4" },
});
Features

Everything you need to track changes.

An audit log shouldn't be a side project. better-activity gives you the primitives to record, query, and react to every meaningful event in your app.

Type-safe per entity

Declare entities and their allowed actions once. save() and list() are fully checked at compile time — no stringly-typed events.

Eight adapters, one API

Postgres, MySQL, SQLite, MongoDB, Drizzle, Prisma, Kysely, and in-memory for tests. Swap the backend without touching the call site.

Flexible metadata

Attach arbitrary JSON to any event. Opt into strict types per entity for end-to-end safety from the producer to the query.

Cursor pagination

Stable cursors, by-actor lookups, and time-range queries built in. Designed to scale from one row to billions.

Realtime subscribers

In-process subscribers and before/after hooks let you fan events out to webhooks, queues, or live UIs.

CLI & migrations

Generate or apply the schema for your configured adapter with a single command. No hand-rolled SQL.

Adapters

Bring your own database.

One core, every backend. Each adapter ships with its own schema, indices, and pagination strategy — tuned for the engine you actually run.

Postgres
MySQL
SQLite
MongoDB
Drizzle
Prisma
Kysely
In-Memory
Cursor

Pagination that stays stable as rows arrive.

Hooks

before / after save with full event context.

React

Hooks, optimistic inserts, realtime feeds.

Maintainers

Built and maintained with care.

better-activity is open source and shaped by the people behind it. Reach out, file an issue, or send a PR — contributions are welcome.

Dan Zabrotski

Dan Zabrotski

Creator & Maintainer
United States

Start logging what matters.

Wire up better-activity in minutes. Replace your homegrown audit table, kill your event-tracking todo list, and ship with confidence.