Download the PHP package youssefmansour9/audit-trail-package without Composer
On this page you can find all versions of the php package youssefmansour9/audit-trail-package. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download youssefmansour9/audit-trail-package
More information about youssefmansour9/audit-trail-package
Files in youssefmansour9/audit-trail-package
Package audit-trail-package
Short Description Production-grade audit trail package for tracking entity changes with Clean Architecture, CQRS, and PDO storage
License MIT
Informations about the package audit-trail-package
Audit Trail Package
A production-grade Composer package for tracking entity changes with complete audit history. Built with Clean Architecture, CQRS, Repository Pattern, and Dependency Injection.
Features
- Record entity changes (CREATE, UPDATE, DELETE) with full before/after state
- Query audit history by entity, user, date range, or action type
- Immutable entries — once written, never modified
- Batch recording with all-or-nothing validation
- Storage-agnostic architecture (PDO implementation included)
- PSR-3 logging — plug any logger (Monolog, Sentry, etc.)
- PHP 8.3+ with strict types everywhere
- Zero impact on your entity tables — audit data is stored separately
Requirements
- PHP 8.3+
- PDO extension (for the included MySQL implementation)
- MySQL 5.7+ or MariaDB 10.2+ (for JSON column support)
Installation
Quick Start
Architecture
Clean Architecture layers
| Layer | Folder | Responsibility |
|---|---|---|
| Domain | src/Domain/ |
Business value objects, enums, exceptions. Zero dependencies. |
| Port | src/Port/ |
Interface contracts (Repository, Logger). Inverts dependencies. |
| Application | src/Application/ |
Use-case orchestration, validation rules. Depends only on Ports. |
| Infrastructure | src/Infrastructure/ |
Concrete implementations (PDO). Swappable. |
| Facade | src/AuditTrail.php |
Single entry point. DI-friendly. |
Design patterns
| Pattern | Where | Purpose |
|---|---|---|
| Clean Architecture | Entire structure | Separation of concerns, testability, swappability |
| CQRS | AuditRepository |
Command methods (append) separated from Query methods (findBy*) |
| Repository | AuditRepository + PDOAuditRepository |
Abstracts storage behind a collection-like interface |
| Dependency Injection | Every class | Dependencies provided via constructor, never created internally |
| Value Object | AuditEntry |
Immutable, self-validating, equality by data |
| Facade | AuditTrail |
Simplified public API hiding internal complexity |
| Static Factory | AuditEntry::record(), AuditEntry::fromArray() |
Named constructors for different creation contexts |
| Primary Constructor | AuditEntry |
Private constructor + public named constructors |
| Adapter | PDOAuditRepository |
Adapts PDO to the Repository interface |
| Null Object | NullLogger |
Default no-op logger when none provided |
Usage
Recording changes
Batch recording (atomic)
All entries are validated before any are persisted. If the second entry fails validation, no entries are written.
Querying history
With Monolog
Database Schema
The schema file is located at src/Infrastructure/Persistence/Schema/mysql.sql.
Column guide
| Column | Type | Purpose |
|---|---|---|
id |
UUID v4 | Unique identifier for the audit entry |
aggregate_type |
string | Entity type (e.g., "order", "user", "product") |
aggregate_id |
string | Entity identifier (e.g., "42", "uuid-value") |
action |
enum string | One of: CREATE, UPDATE, DELETE |
old_state |
JSON or null | The entity state before this change |
new_state |
JSON or null | The entity state after this change |
performed_by |
string | Who performed the action |
performed_at |
datetime(6) | Microsecond-precision timestamp |
metadata |
JSON or null | Extra context (IP, request ID, tags) |
Testing
Tests use SQLite in-memory — no database server required. The test suite runs on CI with zero external dependencies.
Test structure
| Test suite | Tests | What it covers |
|---|---|---|
Domain\ActionTest |
6 | Enum values, cases, from/tryFrom |
Domain\AuditEntryTest |
20 | Creation, serialization, reconstruction, validation |
Domain\Exception\ExceptionTest |
5 | Exception hierarchy and messages |
Application\AuditServiceTest |
17 | Use cases, validation rules, batch atomicity |
Infrastructure\PDOAuditRepositoryTest |
17 | Full CRUD with SQLite, ordering, pagination, batch rollback |
AuditTrailTest |
8 | Public facade delegation, createWithPdo factory |
PHPStan
This project enforces level 9 (the maximum — property type hints, return type hints, generic array annotations, mixed type warnings, and strict comparison rules):
Contributing
See CONTRIBUTING.md.
License
MIT — see LICENSE.
Copyright (c) 2026 Youssef Mansour