Appearance
GrydAudit Module
GrydAudit records who did what, when, from where and with what result, and serves that trail back in a form a person can read: names instead of ids, translated labels, filters, a summary, CSV and PDF evidence and a proof that the trail was not tampered with. It follows the 5W1H principle (Who, What, When, Where, Why, How).
Features
- Recording after the commit: an EF Core
SaveChangesinterceptor captures auditable changes and writes them only once the business change is committed. A failed save or a rolled-back transaction leaves no record. - Readable events: each record carries an
action, anoutcome(successorfailure), acategory(securityordata), and the display names of the record and of the author as they were at the time of the event. - Tenant isolation: every read is restricted to the tenant of the session, and the routes are a scoped domain (
audit-logs, tenant only). - Label catalog: translated labels (pt-BR, en-US, es-ES) for entity types, fields and actions, served by
GET /audit-logs/catalogand reused by the export. - Summary, facets and state at a date: totals and a daily series, filter options with counts, and what a record looked like on a given day.
- Export (opt-in): CSV and PDF, generated by a job, stored in GrydFiles, with the hash and the limits of the contract.
- Integrity proof (opt-in): a hash chain per tenant sealed in batches by a job, anchored outside the trail's database.
- Retention: an automatic cleanup, on by default.
- LGPD/GDPR Compliant: sensitive data exclusion and masked exports.
Architecture
GrydAudit/
├── GrydAudit.Core/ # Entities, abstractions, DTOs, error codes
├── GrydAudit.Application/ # MediatR handlers, label catalog, export and integrity use cases
├── GrydAudit.Infrastructure/ # EF Core, interceptor, repository, retention, hash chain
├── GrydAudit.API/ # REST controllers
├── GrydAudit.Export/ # Opt-in: CSV and PDF writers, job, files and notification adapters
├── GrydAudit.Integrity/ # Opt-in: anchor storage over GrydFiles
└── GrydAudit/ # Meta-package (core, application, infrastructure, API)Quick Start
bash
dotnet add package GrydAuditcsharp
services.AddGrydAudit(options => options.UseNpgsql(connectionString));
services.AddGrydAuditApi();Mark the entities to audit with IAuditableEntity and attach the interceptor to the business DbContext. See Getting Started for the complete setup, including the export and the integrity proof.
Packages
| Package | Description |
|---|---|
GrydAudit.Core | Entities, abstractions, DTOs and the AUDIT_* error codes |
GrydAudit.Application | MediatR queries, handlers, label catalog and the ports of export and integrity |
GrydAudit.Infrastructure | EF Core DbContext, interceptor, repository, retention and hash chain |
GrydAudit.API | REST API controllers |
GrydAudit.Export | Opt-in. CSV and PDF export (needs GrydFiles, GrydJobs and GrydNotifications). Not part of the meta-package |
GrydAudit.Integrity | Opt-in. Anchor storage of the integrity proof (needs GrydFiles and GrydJobs). Not part of the meta-package |
GrydAudit | Meta-package including the first four |
Core Concepts
AuditLog Entity
The central entity that stores audit information:
- Who:
UserId,UserEmail,UserDisplayName,ActorType(userorsystem),SystemActor,IpAddress,UserAgent - What:
EntityType,EntityId,EntityDisplayName,ChangeType,Action,Outcome,Category, and the changed fields (AuditLogDetail) - When:
Timestamp(UTC) - Where:
TenantId,ServiceName - Why: the metadata of the event, when the module that wrote it has context to add
- How:
CorrelationIdandTraceId; old and new values per field
Change Types
| Change type | Number | Description |
|---|---|---|
Created | 1 | Entity was inserted |
Updated | 2 | Entity was modified |
Deleted | 3 | Entity was removed |
Accessed | 4 | Entity was read (written explicitly by the module) |
Actions, outcomes and categories
actionis{entity}.{verb}in lower case with_(user.updated). Every entity gets the generic verbscreated,updated,deletedandaccessed; modules add specific ones (user.password_reset_by_admin).outcomeissuccess, orfailurefor a denied or failed attempt.categoryissecurityordata. A category outside the set is stored asdata.- The full list and the fallback rules are in the contract.
API Endpoints
All routes are under /api/v1/audit-logs, belong to the scoped domain audit-logs and need read:audit-logs. Fields, parameters, limits and error codes are defined once, in the audit logs contract.
| Method | Route | Description |
|---|---|---|
| GET | / | List with search and filters |
| GET | /{id} | Detail of one record, with the integrity block |
| GET | /entity/{entityType}/{entityId} | History of a record |
| GET | /user/{userId} | Activity of a person |
| GET | /catalog | Translated labels and the retention window |
| GET | /facets | Filter options with counts |
| GET | /summary | Totals and daily series |
| GET | /entity/{entityType}/{entityId}/state | State of a record at a date |
| POST | /exports | Create a CSV or PDF export |
| GET | /exports/{id} | Follow an export |
| GET | /exports/{id}/file | Download the file |
| GET | /{id}/integrity | Verify one record |
| POST | /integrity-checks | Verify a period |
| GET | /integrity-checks/{id} | Result of the period verification |
The export and integrity routes answer 503 AUDIT_EXPORT_UNAVAILABLE and 503 AUDIT_INTEGRITY_UNAVAILABLE when the host did not enable the auxiliary modules.
Which package brings the endpoints
GrydAudit.Infrastructure (and GrydAuth.Infrastructure, which uses it for the change interceptors) registers services only. The HTTP surface comes from GrydAudit.API, which the GrydAudit meta-package references on purpose: a host that wants the audit routes references one of those two. An architecture test (ModuleHttpSurfaceTests) fails the build if a module project reaches another module's *.API or meta-package.
Related Documentation
- Getting Started
- Configuration
- Querying Audit Logs
- LGPD & Data Protection
- Audit logs contract — the source of truth for the HTTP API
- ADR 0011 — scope model the routes follow