# Audit Logs

## Purpose

Pluscare includes an **audit log** system to support accountability and compliance requirements, including **GDPR**.

## How it works

The system records actions performed by users, specifically all **CRUD operations**:

- **Create**
- **Read**
- **Update**
- **Delete**

Each audit entry captures who performed the action, what was affected, and any additional relevant metadata (when available). This provides a clear trace of user activity within the system.

### Enabling auditing for a model

To start tracking changes for a specific model/entity, add the auditing trait to the model class:

- Add the `AuditableWithMetadata` trait to the model you want to audit.

Once included, the system automatically logs the model's CRUD activity according to the audit log configuration.

## Key entities & DB

Audit entries are created automatically when an auditable model is created, read, updated, or deleted. Each entry includes the acting user and affected resource metadata.

## Technical flow

1. A model uses the `AuditableWithMetadata` trait.
2. On CRUD operations, the audit system records the action with user and metadata context.
3. Audit entries can be queried for compliance and accountability review.

## Notes / edge cases

- Auditing must be explicitly enabled per model by adding the trait.
- Not all models are audited by default — only those that include `AuditableWithMetadata`.

## Related documentation

- [Business Logic](../business-logic.md) — user roles and data access
