Skip to content

Cratis Chronicle PII declarations on concepts

Declare personally identifiable information (PII) on a concept type when the value is personal wherever you use it. A concept wraps a value in a domain type, such as PersonName wrapping a string. Cratis Chronicle carries the type’s classification into event and read-model schemas, so each property using that type needs no separate PII annotation.

Why concept-level declaration is preferred

Section titled “Why concept-level declaration is preferred”

A property-level declaration must be repeated on every event or read model that carries the value. If a new property uses a plain string with no PII marker, the schema does not tell Chronicle to encrypt it.

Putting the declaration on PersonName lets the schema generator find it wherever that type is used. The benefit depends on keeping the concept type: copying the value into an unmarked string property does not carry the classification with it. A projection destination needs its own PII metadata, either from the concept or a property annotation.

using Cratis.Chronicle.Compliance.GDPR;
using Cratis.Chronicle.Events;
// ❌ Property-level: requires repetition across every event
[EventType]
public record PiiConceptsComparisonEmployeeRegistered([PII] string Name, string Department);
[EventType]
public record PiiConceptsComparisonEmployeeNameChanged([PII] string NewName); // must remember [PII] again
// ✅ Concept-level: declare once, apply everywhere automatically
[PII]
public record PiiConceptsComparisonPersonName(string Value) : ConceptAs<string>(Value)
{
public static readonly PiiConceptsComparisonPersonName NotSet = new(string.Empty);
public static implicit operator string(PiiConceptsComparisonPersonName name) => name.Value;
public static implicit operator PiiConceptsComparisonPersonName(string value) => new(value);
}
[EventType]
public record PiiConceptsComparisonEmployeeRegisteredGood(PiiConceptsComparisonPersonName Name, string Department); // Name is encrypted
[EventType]
public record PiiConceptsComparisonEmployeeNameChangedGood(PiiConceptsComparisonPersonName NewName); // also encrypted, no extra annotation needed

View C# snippet source on GitHub

In .NET, follow the ConceptAs<T> pattern and add [PII] to the record declaration. The client tabs show the corresponding declarations:

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

View C# snippet source on GitHub

Another example, documenting why the value is sensitive with the optional details parameter:

using Cratis.Chronicle.Compliance.GDPR;
[PII("National ID number — sensitive personal identifier")]
public record PiiConceptsNationalIdNumber(string Value) : ConceptAs<string>(Value)
{
public static readonly PiiConceptsNationalIdNumber NotSet = new(string.Empty);
public static implicit operator string(PiiConceptsNationalIdNumber id) => id.Value;
public static implicit operator PiiConceptsNationalIdNumber(string value) => new(value);
}

View C# snippet source on GitHub

In the .NET client, a concept parameter that defaults to null retains its underlying type and [PII] metadata in the precise schema. Supplying a value therefore encrypts it just as it does for a required parameter. Read models always use this shape; event registration uses it when the kernel advertises precise event type schema support.

If an older schema omitted the classification, adding it does not encrypt earlier values. See Adding PII to an existing event type before assuming that erasure protects that history.

Concept types belong in the feature folder they are primarily associated with, or at the feature root if they are shared across slices. Do not create a separate Concepts/ folder — keep concepts co-located with the code that uses them.

Features/
├── Employees/
│ ├── PersonName.cs ← shared across Registration and Updates slices
│ ├── Registration/
│ │ ├── Registration.cs ← uses PersonName
│ └── Updates/
│ ├── Updates.cs ← also uses PersonName — encryption is automatic

Use the optional details parameter on [PII] to explain why the value is classified as personal. The text is stored in the schema as documentation; it does not enforce a retention period, establish a legal basis or authorize access.

using Cratis.Chronicle.Compliance.GDPR;
[PII("Collected under GDPR Art. 6(1)(b) — necessary for contract performance. Retention: contract duration + 7 years.")]
public record PiiConceptsLegalName(string Value) : ConceptAs<string>(Value)
{
public static readonly PiiConceptsLegalName NotSet = new(string.Empty);
public static implicit operator string(PiiConceptsLegalName name) => name.Value;
public static implicit operator PiiConceptsLegalName(string value) => new(value);
}

View C# snippet source on GitHub

In .NET, marking a type that inherits from EventSourceId or EventSourceId<T> with [PII] throws PIINotSupportedOnEventSourceId. Chronicle needs a readable event source identifier to look up the key. Keep the identifier non-sensitive in every client, even where validation differs.

using Cratis.Chronicle.Compliance.GDPR;
using Cratis.Chronicle.Events;
// ❌ Throws PIINotSupportedOnEventSourceId
[PII]
public record PiiConceptsEmployeeId(Guid Value) : EventSourceId<Guid>(Value);

View C# snippet source on GitHub

Use a non-sensitive surrogate key as the event source identifier and store sensitive identity values in a separate event property:

using Cratis.Chronicle.Events;
// ✅ Surrogate key as event source identifier
public record PiiConceptsSurrogateEmployeeId(Guid Value) : EventSourceId<Guid>(Value)
{
public static PiiConceptsSurrogateEmployeeId New() => new(Guid.NewGuid());
}
// ✅ Sensitive value stored in a PII-marked concept type
[EventType]
public record PiiConceptsSurrogateEmployeeRegistered(PiiConceptsNationalIdNumber NationalId, PiiConceptsPersonName Name);

View C# snippet source on GitHub

Once the concept is declared, check the schemas of the events and read models that use it. Continue with Read models and PII to release encrypted values for queries, or Adding PII to an existing event type if the concept replaces a field already in production.