Audit Logs Table
Component Detail
Data Layer
medium complexity
backend
1
Dependencies
2
Dependents
0
Entities
0
Integrations
Description
PostgreSQL table storing the immutable, chronological trail of all security-relevant events. Schema includes event_type, actor_id, actor_role, target_entity_type, target_entity_id, organization_id, ip_address, user_agent, and a JSONB metadata blob. Composite indexes on (organization_id, created_at) and (actor_id, created_at) are mandatory for query performance. No UPDATE or DELETE is permitted - enforced via database-level trigger and a dedicated write-only PostgreSQL role.
audit-logs-table
Responsibilities
- Persist all audit log entries with full event context as immutable rows
- Provide indexed read access by organization, actor, and timestamp
- Enforce append-only constraint via DB trigger and restricted write role
- Store arbitrary event metadata as a JSONB blob for extensibility
Interfaces
INSERT INTO audit_logs (event_type, actor_id, actor_role, target_entity_type, target_entity_id, organization_id, ip_address, user_agent, metadata, created_at)
SELECT ... FROM audit_logs WHERE organization_id = $1 AND created_at BETWEEN $2 AND $3
SELECT ... FROM audit_logs WHERE actor_id = $1 AND created_at BETWEEN $2 AND $3
Relationships
Dependents (2)
Components that depend on this component