Skip to content

Cratis Chronicle client PII declarations

Cratis Chronicle uses your client declarations to identify personally identifiable information (PII) and encrypt it when events are appended. Declare personal data on an event property when the classification belongs to that field, or on a reusable concept type when the value is personal wherever it appears.

Annotate individual properties on your event records when a value is personal in the context of that event. In .NET, the annotation is [PII]:

using Cratis.Chronicle.Compliance.GDPR;
using Cratis.Chronicle.Events;
[EventType]
public record ComplianceClientEmployeeRegistered(
[PII] string FirstName,
[PII] string LastName,
string Department,
DateTimeOffset StartDate);

View C# snippet source on GitHub

On a new append, FirstName and LastName are encrypted. Department and StartDate remain plaintext. If you are adding annotations to an existing model, read Adding PII to an existing event type before relying on erasure.

Use property-level annotation when:

  • The property type is a primitive (string, int) and you do not need a dedicated concept type.
  • The value is PII in this event but is conceptually not a PII concept elsewhere.
  • You are classifying selected fields in an existing model and have reviewed the earlier plaintext values.

You must repeat the annotation whenever another event carries the same personal value. Without a marker on the property or its type, the kernel has no PII classification to apply and stores the value as plaintext.

Option 2 — Annotate your ConceptAs types

Section titled “Option 2 — Annotate your ConceptAs types”

A concept is a domain type that wraps a value, such as PersonName wrapping a string. Put the PII declaration on that type so event properties retain the classification when they reuse it. In .NET, mark the ConceptAs<T> type with [PII]:

using Cratis.Chronicle.Compliance.GDPR;
[PII]
public record ComplianceClientPersonName(string Value) : ConceptAs<string>(Value)
{
public static readonly ComplianceClientPersonName NotSet = new(string.Empty);
public static implicit operator string(ComplianceClientPersonName name) => name.Value;
public static implicit operator ComplianceClientPersonName(string value) => new(value);
}

View C# snippet source on GitHub

The PersonName properties in these events take their classification from the type, so they need no separate PII annotation:

using Cratis.Chronicle.Events;
[EventType]
public record ComplianceClientEmployeeRegisteredWithConcept(ComplianceClientPersonName Name, string Department);
[EventType]
public record ComplianceClientEmployeeNameChanged(ComplianceClientPersonName NewName); // also encrypted

View C# snippet source on GitHub

Use concept-level annotation when:

  • The value represents a domain concept that is inherently personal (a person’s name, email address, phone number, national ID).
  • The same kind of value appears in multiple events and you want consistent protection without repeating the attribute.
  • You are building a new model and want the personal-data classification to travel with the type.

Prefer this approach for values that are personal by nature. It still depends on retaining the concept type in the generated schema; replacing it with a plain string loses that classification.

The two approaches complement each other. Use concept types for inherently personal domain values, and use property-level annotation for one-off cases where creating a concept type is not warranted.

using Cratis.Chronicle.Compliance.GDPR;
using Cratis.Chronicle.Events;
[PII]
public record ComplianceClientEmailAddress(string Value) : ConceptAs<string>(Value)
{
public static readonly ComplianceClientEmailAddress NotSet = new(string.Empty);
public static implicit operator string(ComplianceClientEmailAddress email) => email.Value;
public static implicit operator ComplianceClientEmailAddress(string value) => new(value);
}
[EventType]
public record ComplianceClientCustomerRegistered(
ComplianceClientPersonName Name, // encrypted via concept type
ComplianceClientEmailAddress Email, // encrypted via concept type
[PII] string PhoneNumber, // encrypted via property annotation
string Country); // plaintext

View C# snippet source on GitHub

Keep event source identifiers non-sensitive and readable because Chronicle uses them for key lookup. In .NET, applying [PII] to a type that inherits from EventSourceId or EventSourceId<T> throws PIINotSupportedOnEventSourceId. Other clients enforce this restriction differently; follow it regardless of the client.

using Cratis.Chronicle.Compliance.GDPR;
using Cratis.Chronicle.Events;
// ❌ This will throw PIINotSupportedOnEventSourceId at startup
[PII]
public record ComplianceClientCustomerId(Guid Value) : EventSourceId<Guid>(Value);

View C# snippet source on GitHub

If the identifier itself is sensitive, use a non-sensitive surrogate key as the event source identifier (a randomly generated Guid works well) and store the sensitive value in a [PII]-marked event property.

In a .NET ASP.NET Core application, AddCompliance() registers the providers that read PII annotations:

using Microsoft.Extensions.DependencyInjection;
public static class ComplianceClientRegistration
{
public static void Configure(IServiceCollection services) => services.AddCompliance();
}

View C# snippet source on GitHub

This registers PIIMetadataProvider for property and type metadata. AddCratisChronicle() already includes the call. The providers supply declarations during schema generation; the kernel applies encryption using that schema.

Next, mark the personal properties in any projection destination. An event annotation does not automatically protect every read-model property that receives its value; Read models and PII explains that separate storage and release path. These declarations do not authorize access or establish GDPR compliance by themselves.