Product Decisions This Supports
- Compliance & Governance: Enables automated tracking of entity changes for audit trails, critical for industries like healthcare (HIPAA), finance (SOX), or legal (GDPR).
- Debugging & Rollback: Facilitates debugging by allowing developers to inspect historical states of entities, reducing downtime during incidents.
- Feature Roadmap: Supports "time-travel" features (e.g., "Show me how this record looked 3 months ago") for admin dashboards or reporting tools.
- Build vs. Buy: Avoids reinventing audit logging wheels, reducing dev time and maintenance overhead compared to custom solutions.
- Use Cases:
- Regulatory Compliance: Automatically log changes to sensitive data (e.g., user profiles, financial records).
- Data Integrity: Track who modified what and when to prevent unauthorized changes.
- Analytics: Analyze trends by querying historical entity states (e.g., "How many orders were canceled last month?").
- Disaster Recovery: Revert entities to previous states if corrupted or accidentally altered.
When to Consider This Package
-
Adopt if:
- Your application requires immutable audit logs for critical entities (e.g., user data, transactions).
- You’re using Symfony/Laravel with Doctrine ORM and need a lightweight, battle-tested solution.
- Your team lacks bandwidth to build a custom audit system from scratch.
- You need association tracking (e.g., auditing changes to related entities like orders and customers).
- Your stack supports PHP 8.2+ and Symfony 8+ (or standalone Doctrine).
-
Look elsewhere if:
- You need real-time audit streaming (e.g., Kafka-based event sourcing) instead of periodic snapshots.
- Your database schema is highly dynamic (e.g., NoSQL or schema-less systems).
- You require fine-grained field-level auditing (e.g., tracking individual array elements in JSON columns) without custom extensions.
- Your team prefers event sourcing over snapshot-based auditing (e.g., using libraries like
spatie/laravel-activitylog for event-based logs).
- You’re using Joined-Table Inheritance (this package has limited support).
- You need multi-database support (e.g., PostgreSQL + MySQL) without additional configuration.
How to Pitch It (Stakeholders)
For Executives:
"This package automates compliance and reduces risk by creating an unalterable log of every change to critical data—like a ‘black box’ for your database. For example, if a customer disputes a charge, we can instantly prove what their account looked like at the time of the transaction. It’s like adding a time machine to your data, which cuts audit prep time by 70% and eliminates manual logging errors. The cost? Minimal—just a few lines of config and zero ongoing maintenance. Industries like finance and healthcare already use this to pass compliance checks effortlessly."
For Engineers:
*"This is a drop-in Doctrine extension that mirrors your entity tables with revision history (e.g., users_audit). It hooks into Doctrine’s lifecycle to auto-track inserts, updates, and deletes, including associations. Key perks:
- Zero code changes: Just configure which entities to audit in
config/packages/entity_audit.yaml.
- Query historical states: Fetch any entity’s past version with
$auditReader->find(Entity::class, $id, $revision).
- Built-in UI: Get a ready-made
/audit dashboard to browse revisions (secure it with Symfony’s security system).
- Lightweight: Adds ~50KB to your bundle and runs in the background.
Tradeoff: It’s not real-time (uses snapshots), but it’s 10x faster to implement than a custom solution and handles edge cases like associations out of the box."*
For Data Teams:
*"This gives you SQL-based audit trails without ETL overhead. Need to analyze how a field changed over time? Query the _audit tables directly or use the AuditReader to compare revisions. For example:
$revisions = $auditReader->findRevisions(User::class, 42); // Get all changes for user #42
$changesAtRev10 = $auditReader->findEntitiesChangedAtRevision(10); // See what changed in bulk
It’s like git for your database—except you can’t git reset --hard by accident."*