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.
Option 1 — Annotate your event types
Section titled “Option 1 — Annotate your event types”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);import io.cratis.chronicle.compliance.Piiimport io.cratis.chronicle.events.EventTypeimport java.time.Instant
@EventTypedata class ComplianceClientEmployeeRegistered( @Pii val firstName: String, @Pii val lastName: String, val department: String, val startDate: Instant)import io.cratis.chronicle.compliance.Pii;import io.cratis.chronicle.events.EventType;
import java.time.Instant;
@EventTyperecord ComplianceClientEmployeeRegistered( @Pii String firstName, @Pii String lastName, String department, Instant startDate) {}defmodule MyApp.Events.ComplianceClientEmployeeRegistered do use Cratis.Chronicle.Events.EventType, id: "compliance-client-employee-registered"
defstruct [:first_name, :last_name, :department, :start_date]
pii(:first_name) pii(:last_name)endimport { eventType, pii } from '@cratis/chronicle';
@eventType()class ComplianceClientEmployeeRegistered { @pii() firstName = ''; @pii() lastName = ''; department = ''; startDate = new Date();}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.
When to use this approach
Section titled “When to use this approach”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.
Limitation
Section titled “Limitation”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);}import io.cratis.chronicle.compliance.Piiimport io.cratis.fundamentals.concepts.ConceptAs
@Piidata class ComplianceClientPersonName(val value: String) : ConceptAs<String> { override fun value(): String = value}import io.cratis.chronicle.compliance.Pii;import io.cratis.fundamentals.concepts.ConceptAs;
@Piirecord ComplianceClientPersonName(String value) implements ConceptAs<String> {}defmodule MyApp.Compliance.Client.PersonName do use Cratis.Chronicle.Concept, type: :string pii()endimport { pii } from '@cratis/chronicle';import { ConceptAs } from '@cratis/fundamentals';
@pii()class ComplianceClientPersonName extends ConceptAs<string> { static readonly valueType = String;
constructor(value: string) { super(value); }}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 encryptedimport io.cratis.chronicle.events.EventType
@EventTypedata class ComplianceClientEmployeeRegisteredWithConcept(val name: ComplianceClientPersonName, val department: String)
// also encrypted@EventTypedata class ComplianceClientEmployeeNameChanged(val newName: ComplianceClientPersonName)import io.cratis.chronicle.events.EventType;
@EventTyperecord ComplianceClientEmployeeRegisteredWithConcept(ComplianceClientPersonName name, String department) {}
// also encrypted@EventTyperecord ComplianceClientEmployeeNameChanged(ComplianceClientPersonName newName) {}defmodule MyApp.Compliance.Client.ConceptUsagePersonName do use Cratis.Chronicle.Concept, type: :string pii()end
defmodule MyApp.Compliance.Client.EmployeeRegisteredWithConcept do use Cratis.Chronicle.Events.EventType, id: "compliance-client-employee-registered-with-concept"
defstruct name: %MyApp.Compliance.Client.ConceptUsagePersonName{}, department: ""end
defmodule MyApp.Compliance.Client.EmployeeNameChanged do use Cratis.Chronicle.Events.EventType, id: "compliance-client-employee-name-changed"
# Also encrypted — reuses the same concept. defstruct new_name: %MyApp.Compliance.Client.ConceptUsagePersonName{}endimport { eventType } from '@cratis/chronicle';import { field } from '@cratis/fundamentals';
@eventType()class ComplianceClientEmployeeRegisteredWithConcept { @field(ComplianceClientPersonName) readonly name: ComplianceClientPersonName; @field(String) readonly department: string;
constructor(name: ComplianceClientPersonName, department: string) { this.name = name; this.department = department; }}
@eventType()class ComplianceClientEmployeeNameChanged { @field(ComplianceClientPersonName) readonly newName: ComplianceClientPersonName;
constructor(newName: ComplianceClientPersonName) { this.newName = newName; } // also encrypted}When to use this approach
Section titled “When to use this approach”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.
Combining both approaches
Section titled “Combining both approaches”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); // plaintextimport io.cratis.chronicle.compliance.Piiimport io.cratis.fundamentals.concepts.ConceptAsimport io.cratis.chronicle.events.EventType
@Piidata class ComplianceClientEmailAddress(val value: String) : ConceptAs<String> { override fun value(): String = value}
@EventTypedata class ComplianceClientCustomerRegistered( val name: ComplianceClientPersonName, // encrypted via concept type val email: ComplianceClientEmailAddress, // encrypted via concept type @Pii val phoneNumber: String, // encrypted via property annotation val country: String // plaintext)import io.cratis.chronicle.compliance.Pii;import io.cratis.fundamentals.concepts.ConceptAs;import io.cratis.chronicle.events.EventType;
@Piirecord ComplianceClientEmailAddress(String value) implements ConceptAs<String> {}
@EventTyperecord ComplianceClientCustomerRegistered( ComplianceClientPersonName name, // encrypted via concept type ComplianceClientEmailAddress email, // encrypted via concept type @Pii String phoneNumber, // encrypted via property annotation String country) { // plaintext}defmodule MyApp.Compliance.Client.CombiningPersonName do use Cratis.Chronicle.Concept, type: :string pii()end
defmodule MyApp.Compliance.Client.CombiningEmailAddress do use Cratis.Chronicle.Concept, type: :string pii()end
defmodule MyApp.Compliance.Client.CustomerRegistered do use Cratis.Chronicle.Events.EventType, id: "compliance-client-customer-registered"
defstruct name: %MyApp.Compliance.Client.CombiningPersonName{}, email: %MyApp.Compliance.Client.CombiningEmailAddress{}, phone_number: "", country: ""
# name and email are encrypted via their concept types; phone_number is # encrypted via this property-level annotation; country stays plaintext. pii(:phone_number)endimport { eventType, pii } from '@cratis/chronicle';import { ConceptAs } from '@cratis/fundamentals';
@pii()class ComplianceClientEmailAddress extends ConceptAs<string> { static readonly valueType = String;
constructor(value: string) { super(value); }}
@eventType()class ComplianceClientCustomerRegistered { name: ComplianceClientPersonName = new ComplianceClientPersonName(''); // encrypted via concept type email: ComplianceClientEmailAddress = new ComplianceClientEmailAddress(''); // encrypted via concept type @pii() phoneNumber = ''; // encrypted via property annotation country = ''; // plaintext}EventSourceId cannot be marked PII
Section titled “EventSourceId cannot be marked PII”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);import io.cratis.chronicle.compliance.Piiimport io.cratis.chronicle.concepts.EventSourceId
// This will throw PiiNotSupportedOnEventSourceId at registration@Piidata class ComplianceClientCustomerId(val value: String) : EventSourceId { override fun value(): String = value}import io.cratis.chronicle.compliance.Pii;import io.cratis.chronicle.concepts.EventSourceId;
// This will throw PiiNotSupportedOnEventSourceId at registration@Piirecord ComplianceClientCustomerId(String value) implements EventSourceId {}# Raises ArgumentError at compile time — the event source id is used to look# up the encryption key, so it cannot itself be an encrypted value.## defmodule MyApp.Compliance.Client.CustomerId do# use Cratis.Chronicle.Concept, type: :uuid, event_source_id: true# pii()# endimport { pii } from '@cratis/chronicle';
// TypeScript represents the event source identifier as the conventional 'eventSourceId'// property rather than a dedicated EventSourceId<T> type. Marking it @pii() throws// PIINotSupportedOnEventSourceId - event source identifiers are required for key lookup and// cannot be encrypted.class ComplianceClientCustomerId { @pii() eventSourceId = '';}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.
Registering compliance services
Section titled “Registering compliance services”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();}import io.cratis.chronicle.ChronicleClientimport io.cratis.chronicle.ChronicleOptionsimport io.cratis.chronicle.EventStore
// The Kotlin client has no separate compliance registration step. Every event type and read model// it registers carries its @Pii metadata in the schema it sends to the kernel, so connecting the// client is all compliance needs - and the compliance service is on every event store it returns.object ComplianceClientRegistration { fun configure(): EventStore { val client = ChronicleClient(ChronicleOptions.development()) return client.getEventStore("Sales") }}import io.cratis.chronicle.ChronicleOptions;import io.cratis.chronicle.java.BlockingChronicleClient;import io.cratis.chronicle.java.BlockingEventStore;
// The Java client has no separate compliance registration step. Every event type and read model// it registers carries its @Pii metadata in the schema it sends to the kernel, so connecting the// client is all compliance needs - and the compliance service is on every event store it returns.class ComplianceClientRegistration { static BlockingEventStore configure() { BlockingChronicleClient client = BlockingChronicleClient.connect(ChronicleOptions.development()); return client.getEventStore("Sales"); }}# No separate compliance registration step exists. Compliance metadata is# resolved automatically — from pii/1,2 declarations and from# Cratis.Chronicle.Concept field types — whenever an event type or read model is# registered, as part of the normal Cratis.Chronicle.Client supervision tree entry.{Cratis.Chronicle.Client, connection_string: "chronicle://localhost:35000", event_store: "my-store", event_types: [MyApp.Compliance.Client.CustomerRegistered], read_models: [MyApp.Compliance.Client.Customer]}import { ChronicleClient } from '@cratis/chronicle';
// TypeScript has no DI-container registration step for compliance support - the PII manager// is available automatically as soon as you have an event store, with no separate wiring.async function getPIIManager(chronicleClient: ChronicleClient) { const eventStore = await chronicleClient.getEventStore('Sales'); return eventStore.pii;}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.