Skip to content

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 SaveChanges interceptor 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, an outcome (success or failure), a category (security or data), 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/catalog and 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 GrydAudit
csharp
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 ​

PackageDescription
GrydAudit.CoreEntities, abstractions, DTOs and the AUDIT_* error codes
GrydAudit.ApplicationMediatR queries, handlers, label catalog and the ports of export and integrity
GrydAudit.InfrastructureEF Core DbContext, interceptor, repository, retention and hash chain
GrydAudit.APIREST API controllers
GrydAudit.ExportOpt-in. CSV and PDF export (needs GrydFiles, GrydJobs and GrydNotifications). Not part of the meta-package
GrydAudit.IntegrityOpt-in. Anchor storage of the integrity proof (needs GrydFiles and GrydJobs). Not part of the meta-package
GrydAuditMeta-package including the first four

Core Concepts ​

AuditLog Entity ​

The central entity that stores audit information:

  • Who: UserId, UserEmail, UserDisplayName, ActorType (user or system), 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: CorrelationId and TraceId; old and new values per field

Change Types ​

Change typeNumberDescription
Created1Entity was inserted
Updated2Entity was modified
Deleted3Entity was removed
Accessed4Entity was read (written explicitly by the module)

Actions, outcomes and categories ​

  • action is {entity}.{verb} in lower case with _ (user.updated). Every entity gets the generic verbs created, updated, deleted and accessed; modules add specific ones (user.password_reset_by_admin).
  • outcome is success, or failure for a denied or failed attempt.
  • category is security or data. A category outside the set is stored as data.
  • 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.

MethodRouteDescription
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/catalogTranslated labels and the retention window
GET/facetsFilter options with counts
GET/summaryTotals and daily series
GET/entity/{entityType}/{entityId}/stateState of a record at a date
POST/exportsCreate a CSV or PDF export
GET/exports/{id}Follow an export
GET/exports/{id}/fileDownload the file
GET/{id}/integrityVerify one record
POST/integrity-checksVerify 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.

Released under the MIT License.