Skip to content

Activity Domain

The activity domain provides activity tracking, feeds, and timelines. It records who did what to which resource, enabling social-style activity feeds and audit-like timelines.

Terminal window
npx @backcap/cli add activity

Each activity entry captures an actor, an action, a target resource, and optional metadata.

import { ActivityEntry } from "./domains/activity/domain/entities/activity-entry.entity";
const entry = ActivityEntry.create({
id: crypto.randomUUID(),
actorId: "user-1",
actorDisplayName: "Jane Doe",
action: "commented",
targetId: "post-42",
targetType: "post",
metadata: { commentId: "c-99" },
occurredAt: new Date(),
});
  • Actor — validated user reference (id + display name)
  • Action — validated action string
Use CaseDescription
RecordLog a new activity event
GetFeedRetrieve the activity feed for a user
GetTimelineGet chronological timeline of activities for a resource
  • IActivityRepositorysave, findByActor, findByTarget
import { createActivityService } from "./domains/activity/contracts";
const activity = createActivityService({
activityRepository: myActivityRepo,
});
await activity.record({
actorId: "user-1",
actorDisplayName: "Jane Doe",
action: "commented",
targetId: "post-42",
targetType: "post",
});
EventPayload
ActivityRecordedactorId, action, targetId, targetType