{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "audit-log",
  "type": "registry:block",
  "title": "Audit Log",
  "description": "Append-only activity table, event helpers, and admin timeline UI.",
  "dependencies": [],
  "devDependencies": [],
  "registryDependencies": [
    "https://stackfoundry.dev/r/drizzle-postgres.json"
  ],
  "files": [
    {
      "path": "packages/db/src/schema/audit-log.ts",
      "type": "registry:file",
      "target": "packages/db/src/schema/audit-log.ts",
      "content": "import { index, jsonb, pgTable, text, timestamp, uuid } from \"drizzle-orm/pg-core\";\n\nexport const auditLogEvents = pgTable(\n  \"audit_log_events\",\n  {\n    id: uuid(\"id\").primaryKey().defaultRandom(),\n    actorId: text(\"actor_id\"),\n    actorType: text(\"actor_type\").notNull().default(\"user\"),\n    action: text(\"action\").notNull(),\n    resourceType: text(\"resource_type\").notNull(),\n    resourceId: text(\"resource_id\"),\n    organizationId: text(\"organization_id\"),\n    metadata: jsonb(\"metadata\").$type<Record<string, unknown>>().notNull().default({}),\n    createdAt: timestamp(\"created_at\", { withTimezone: true }).defaultNow().notNull(),\n  },\n  (table) => [\n    index(\"audit_log_events_org_idx\").on(table.organizationId),\n    index(\"audit_log_events_resource_idx\").on(table.resourceType, table.resourceId),\n  ]\n);\n"
    },
    {
      "path": "apps/web/src/lib/audit-log.ts",
      "type": "registry:file",
      "target": "apps/web/src/lib/audit-log.ts",
      "content": "import \"server-only\";\n\nexport type AuditLogEventInput = {\n  actorId?: string | null;\n  actorType?: \"user\" | \"system\" | \"service\";\n  action: string;\n  resourceType: string;\n  resourceId?: string | null;\n  organizationId?: string | null;\n  metadata?: Record<string, unknown>;\n};\n\nexport function buildAuditLogEvent(input: AuditLogEventInput) {\n  return {\n    actorId: input.actorId ?? null,\n    actorType: input.actorType ?? \"user\",\n    action: input.action,\n    resourceType: input.resourceType,\n    resourceId: input.resourceId ?? null,\n    organizationId: input.organizationId ?? null,\n    metadata: input.metadata ?? {},\n  };\n}\n\nexport function assertAuditAction(action: string) {\n  if (!/^[a-z]+(?:\\.[a-z]+)+$/.test(action)) {\n    throw new Error(\"Audit actions should use a namespaced form like billing.subscription_updated\");\n  }\n}\n"
    },
    {
      "path": "apps/web/src/app/(console)/audit-log/page.tsx",
      "type": "registry:page",
      "target": "apps/web/src/app/(console)/audit-log/page.tsx",
      "content": "const exampleEvents = [\n  { action: \"billing.subscription_updated\", actor: \"system\", resource: \"subscription\" },\n  { action: \"api_key.created\", actor: \"user_123\", resource: \"api_key\" },\n  { action: \"workspace.member_invited\", actor: \"user_456\", resource: \"invite\" },\n];\n\nexport default function AuditLogPage() {\n  return (\n    <main className=\"flex flex-col gap-6 p-6\">\n      <div>\n        <h1 className=\"text-2xl font-semibold\">Audit Log</h1>\n        <p className=\"text-muted-foreground\">Review sensitive account, workspace, and system events.</p>\n      </div>\n      <div className=\"grid gap-3\">\n        {exampleEvents.map((event) => (\n          <div key={event.action} className=\"rounded-lg border p-4\">\n            <p className=\"font-medium\">{event.action}</p>\n            <p className=\"text-sm text-muted-foreground\">{event.actor} changed {event.resource}</p>\n          </div>\n        ))}\n      </div>\n    </main>\n  );\n}\n"
    }
  ],
  "maintenanceSkills": [
    {
      "name": "audit-log",
      "target": ".stackfoundry/skills/audit-log/SKILL.md",
      "content": "---\nname: audit-log\ndescription: Maintain the Audit Log module installed by StackFoundry.\n---\n\n# Audit Log Maintenance Instructions\n\n- Preserve the module boundary described in `docs.md`.\n- Keep public APIs small and typed.\n- Update tests/checklist.md when behavior changes.\n- Do not introduce secrets, generated machine metadata, or provider lock-in.\n- Keep Drizzle schema exports documented in module.json.\n\n## Shared Skills\n\nWhen provider, framework, or database behavior changes, load the installed shared skill before editing implementation details:\n\n- `.stackfoundry/skills/nextjs/SKILL.md` (source: `registry/skills/nextjs/SKILL.md`)\n- `.stackfoundry/skills/drizzle/SKILL.md` (source: `registry/skills/drizzle/SKILL.md`)\n\nKeep this module skill focused on ownership, installed files, env vars, deployment checks, and module-specific invariants.\n\n"
    },
    {
      "name": "nextjs",
      "target": ".stackfoundry/skills/nextjs/SKILL.md",
      "content": "---\nname: nextjs\ndescription: Maintain Next.js App Router code installed by StackFoundry modules.\n---\n\n# Next.js Operating Instructions\n\n## Installed Location\n\n- Installed target: `.stackfoundry/skills/nextjs/SKILL.md`\n- Registry source: `registry/skills/nextjs/SKILL.md`\n\nAgents maintaining an installed module should load this shared skill from the installed target when provider, framework, database, SDK, or platform behavior is involved. Keep provider-specific API details here instead of duplicating them inside module maintenance skills.\n\n- Keep server-only data access out of Client Components.\n- Put route handlers under `app/api` and UI routes under the relevant App Router segment.\n- Prefer Server Components for data loading and add `\"use client\"` only for interactivity.\n- Keep public environment variables prefixed with `NEXT_PUBLIC_`; keep secrets server-only.\n- Re-run typecheck and build after changing route handlers, layouts, or shared app configuration.\n"
    },
    {
      "name": "drizzle",
      "target": ".stackfoundry/skills/drizzle/SKILL.md",
      "content": "---\nname: drizzle\ndescription: Maintain Drizzle ORM and Postgres code installed by StackFoundry modules.\n---\n\n# Drizzle Operating Instructions\n\n## Installed Location\n\n- Installed target: `.stackfoundry/skills/drizzle/SKILL.md`\n- Registry source: `registry/skills/drizzle/SKILL.md`\n\nAgents maintaining an installed module should load this shared skill from the installed target when provider, framework, database, SDK, or platform behavior is involved. Keep provider-specific API details here instead of duplicating them inside module maintenance skills.\n\n- Keep database access in server-only code.\n- Add schema changes under `packages/db/src/schema` and export shared tables from the schema barrel.\n- Generate and commit migrations when schema changes are intended.\n- Use typed query helpers instead of raw SQL unless the query needs a documented escape hatch.\n- Include tenant, organization, or user scope in queries and cache tags whenever data is not global.\n"
    }
  ],
  "envVars": {},
  "docs": "# Audit Log Module\n\nAppend-only activity table, event helpers, and admin timeline UI.\n\n## Owns\n\n- `packages/db/src/schema/audit-log.ts`\n- `apps/web/src/lib/audit-log.ts`\n- `apps/web/src/app/(console)/audit-log/page.tsx`\n\n## Environment\n\nRequires `DATABASE_URL` through the `drizzle-postgres` dependency.\n\n## Maintenance\n\n- Keep this module provider-neutral unless a provider adapter is added as a separate module.\n- Update the manifest when source files, schema exports, dependencies, or environment variables change.\n- Verify install output with `stackfoundry add audit-log --target <app> --dry-run` before promoting status.\n",
  "meta": {
    "category": "operations",
    "env": [],
    "status": "ready",
    "maturity": "ready",
    "drizzle": {
      "schemaExports": [
        "auditLogEvents"
      ],
      "migrationRecommended": true
    },
    "recommendedFor": []
  }
}
