Skip to content

Translation — import members from HR

A Translation turns information from another system into work expressed in your application’s language. Here, active HR staff should become Library members. You will use a Cratis Chronicle reactor to map an incoming HR record to a Cratis Arc registration command, so the Library applies its own validation and records MemberRegistered rather than depending on HR’s field names.

The examples show C#, Kotlin, Java and TypeScript backends. The TypeScript backend is published on npm at 1.0.0. Their command identities and retry behavior differ, as explained below and in the backend comparison.

In Event Modeling terms, a Translation slice answers the question: “How do we accept information from outside our boundary without letting that outside world shape our inside world?”

The two systems have different needs:

HR System Library System
HR personnel fields Member with FirstName, LastName
Employee ID as string "EMP-00247" MemberId as a domain concept
status: "ACTIVE" / "INACTIVE" MemberRegistered / MemberDeactivated events
Events owned by HR Events owned by the Library

If Library projections consumed HR payloads directly, they would depend on HR’s schema and status codes. A rename or a change in meaning would spread through the Library code. Keep the integration event at the boundary and translate it once, so the rest of the application depends on Library facts.

The import follows this path:

  1. The inbound adapter records an HR integration event in Chronicle, where the translator observes it
  2. The translator extracts only the data the Library cares about
  3. The translator sends RegisterMember using that data
  4. The Library’s own command pipeline validates and records a MemberRegistered event

Library domain projections consume MemberRegistered, not HRMemberCreated. The integration event can still be stored in Chronicle for the translator to observe; storing it does not make it part of the Library’s domain vocabulary.

Source/
└── Members/
├── MemberId.cs ← Concept: strongly-typed member identity
├── MemberName.cs ← Concept: strongly-typed member name
├── Registration/
│ └── Registration.cs ← RegisterMember command + MemberRegistered event
└── HRIntegration/
└── HRIntegration.cs ← External event type + translator reactor (C# layout)

Kotlin and TypeScript use the same folders with .kt or .ts files. Java puts each public type in its own file, so Registration/ and HRIntegration/ hold one file per event, command and reactor.

The HR contract lives in HRIntegration/, apart from the Library’s registration rules. Replacing the HR system changes that boundary and its inbound adapter; the registration command can stay unchanged as long as the Library’s own requirements stay the same.

First, the domain side: the Library’s own vocabulary. This follows the same State Change pattern as registering an author: a strongly-typed member identity and name, with a concept validator for the nonempty-name rule.

using Cratis.Arc.Validation;
using Cratis.Chronicle.Events;
using Cratis.Concepts;
using FluentValidation;
namespace Library.Members;
// Members/MemberId.cs
public record MemberId(Guid Value) : EventSourceId<Guid>(Value)
{
public static readonly MemberId NotSet = new(Guid.Empty);
public static MemberId New() => new(Guid.NewGuid());
public static implicit operator MemberId(Guid value) => new(value);
}
// Members/MemberName.cs
public record MemberName(string Value) : ConceptAs<string>(Value)
{
public static readonly MemberName NotSet = new(string.Empty);
public static implicit operator MemberName(string value) => new(value);
}
public class MemberNameValidator : ConceptValidator<MemberName>
{
public MemberNameValidator() => RuleFor(name => name.Value).NotEmpty();
}

View C# snippet source on GitHub

The registration command and its event:

Members/Registration/Registration.cs
using Cratis.Arc.Commands.ModelBound;
using Cratis.Chronicle.Events;
namespace Library.Members.Registration;
/// <summary>Records a member's registration in the Library.</summary>
[EventType]
public record MemberRegistered(MemberName FirstName, MemberName LastName);
[Command]
public record RegisterMember(MemberName FirstName, MemberName LastName)
{
public MemberId Provide() => MemberId.New();
public (MemberId, MemberRegistered) Handle(MemberId memberId) =>
(memberId, new MemberRegistered(FirstName, LastName));
}

View C# snippet source on GitHub

And the Library’s uniqueness rule for member names:

// Members/Registration/Registration.cs (continued)
using Cratis.Chronicle.Events.Constraints;
namespace Library.Members.Registration;
public class UniqueMemberName : IConstraint
{
public void Define(IConstraintBuilder builder) => builder
.Unique(_ => _
.On<MemberRegistered>(e => e.FirstName, e => e.LastName)
.WithMessage("A member with that name is already registered"));
}

View C# snippet source on GitHub

RegisterMember knows nothing about HR. It can be called from the UI, from an API, or — as here — from a reactor. MemberNameValidator applies the same nonempty-name invariant to each entry point.

The command both appends MemberRegistered under the new member’s identity and returns that identity as its response, in each backend’s own way:

  • C#: MemberId derives from EventSourceId<Guid>, so the optional Arc–Chronicle integration uses the returned identity both for the append and for the command response. An ordinary ConceptAs<Guid> response would not select the event source. Provide() creates the ID and Handle() constructs the fact.
  • TypeScript: provide() creates the ID, and handle() returns tuple(eventSourceIdResponse(id), event) to append to that ID and return it.
  • Kotlin and Java: the caller supplies the ID in the @CommandKey property; Arc appends the event under the command key and returns the MemberId half of the Pair.

Every backend keeps the Library’s exact first-name/last-name uniqueness rule; Kotlin and Java need Chronicle.Kotlin 6.9.0 or later for it. That rule is checked at append time, after the handler. It is a registration policy, not an HR deduplication key: two different employees can share a name.

Now the integration side. This is the only place in the codebase that knows anything about the HR system’s shape.

Members/HRIntegration/HRIntegration.cs
using Cratis.Arc.Commands;
using Cratis.Chronicle.Events;
using Cratis.Chronicle.Reactors;
using Library.Members.Registration;
namespace Library.Members.HRIntegration;
// ─── External Event ───────────────────────────────────────────────────────────
// The inbound adapter records this integration event in Chronicle.
// Its string fields mirror the HR payload, not Library domain concepts.
/// <summary>Records the staff-creation payload received from HR.</summary>
[EventType]
public record HRMemberCreated(
string EmployeeId,
string GivenName,
string FamilyName,
string Status);
// ─── Translator Reactor ───────────────────────────────────────────────────────
public class MemberImportReactor(ICommandPipeline commandPipeline) : IReactor
{
[OnceOnly]
public async Task HandleHRMemberCreated(HRMemberCreated @event)
{
// Only import active staff as library members
if (@event.Status != "ACTIVE")
{
return;
}
var result = await commandPipeline.Execute(new RegisterMember(
FirstName: new MemberName(@event.GivenName),
LastName: new MemberName(@event.FamilyName)));
if (!result.IsSuccess)
{
throw new MemberImportFailed();
}
}
}
public class MemberImportFailed() : Exception("Library member registration failed.");

View C# snippet source on GitHub

Your inbound adapter records HRMemberCreated as an integration event. Declaring the type does not connect Chronicle to HR: the adapter must receive and validate the payload, then append it to the configured event log before the reactor can see it.

The once-only marker skips this handler during replay. Rebuilding Library views should consume existing MemberRegistered facts, not register members again from historical HR records. The marker does not prevent retries after failure or deduplicate separately delivered messages.

The translator accepts only records whose status is "ACTIVE". It maps their given and family names to Library member names, with no further distinction between employment categories. RegisterMember does not need to understand HR status codes.

Chronicle finds the handler using the mechanics described in Automation. In TypeScript the method must be named hRMemberCreated: the event class name with only its first letter lowercased.

Arc runs the registration command’s validation and Chronicle append, including the name constraint. Unlike the C# expiry sweep, this translator treats every unsuccessful command result as an import failure. The C#, Kotlin and Java reactors throw MemberImportFailed; TypeScript’s reactorCommandResultHandler fails with a message naming the rejected command. This keeps a rejected registration visible to Chronicle instead of acknowledging an import that did not happen.

As in Automation, these background calls do not inherit a user’s HTTP principal; configure an execution context if registration requires authorization. The Kotlin and Java RegisterMember is @AllowAnonymous, matching the C# command, which has no authorization rules.

A repeated name causes a visible rejection, not a successful deduplication. In C# and TypeScript, RegisterMember creates a new MemberId on each attempt. If registration succeeds but the reactor fails before acknowledging the HR event, the retry arrives under a new identity and the name constraint rejects it.

In Kotlin and Java the member identity is the command key, so the reactor supplies it, and one that created a new MemberId on each attempt would meet the same rejection on a retry. Their reactors instead derive the member ID from the employee ID with a name-based UUID (UUID.nameUUIDFromBytes). A retry then appends another MemberRegistered to the same member, which the constraint accepts because the same event source may append its current name again. Two employees who share a name still get different member IDs, so the constraint rejects the second.

A production import needs a durable mapping from HR’s employee identity to MemberId, and a policy for repeated messages and name conflicts. EmployeeId is available at this boundary for that work; do not parse values such as "EMP-00247" as GUIDs or substitute name equality for employee identity.

Automation and Translation look similar at a glance: both use a reactor and both send commands through Arc’s command pipeline. The difference is in who owns the events:

Aspect Automation Translation
What triggers it A clock signal (DailyTick) checking Library reservations An imported HR payload (HRMemberCreated)
Who owns the trigger event The Library’s scheduler contract The adapter mirrors HR’s contract
What the reactor knows Library read models External payload structure
Output Library domain events Library domain events

Automation carries out Library work that is due. Translation reacts to information from another system and maps it into the Library’s language. Both examples use Arc’s optional Chronicle integration; neither changes how standalone Arc commands work.

Step 4 — Wiring the external event stream

Section titled “Step 4 — Wiring the external event stream”

The transport adapter and translator have separate jobs. The adapter receives HR messages; Chronicle delivers the recorded integration event to MemberImportReactor.

Wire the boundary in this order:

  1. Configure Arc’s Chronicle integration (C#, Kotlin and Java, TypeScript) and include the integration event and reactor in application discovery.
  2. Implement the inbound adapter for HR’s actual transport — for example, an authenticated webhook or a broker consumer. Validate the sender and payload before accepting it.
  3. Use the configured Chronicle event log to append HRMemberCreated under a stable integration-event source identity. Check the append result before acknowledging the upstream message.
  4. Keep transport message deduplication and the employee-to-member mapping durable. Test redelivery and a failure after registration succeeds, not only the first successful message.

A Chronicle namespace isolates event-store data; it is not a Kafka or Service Bus connection. Because the concrete adapter depends on HR’s delivery contract, it belongs in the host integration and stays out of RegisterMember.

Start with a direct handler spec: inactive staff should issue no command, while active staff should pass GivenName and FamilyName as MemberName values. In C#, substitute ICommandPipeline and also check that an unsuccessful result throws MemberImportFailed. In TypeScript, call hRMemberCreated and assert the returned command; this tests mapping, not command execution or rejection handling. Test reactorCommandResultHandler separately for the latter.

The JVM reactor takes ChronicleCommandSideEffectHandler, so its handler spec needs that dependency wired to a stub command pipeline. Arc.Kotlin’s ChronicleCommandSideEffectHandlerTests demonstrates the setup. The pipeline methods are suspending Kotlin functions; a Kotlin test fixture can supply the stub for a Java reactor as well. This series does not include a JVM handler spec.

For every backend, add a hosted test through the real adapter and observer. Cover ingestion, discovery, authorization and recovery, including a retry after registration succeeds. A direct mapping spec cannot establish those behaviors.

Over the four tutorials in this series you have built:

Tutorial Pattern What you built
Register an author State Change Register an author and reject an exact duplicate name
List authors State View Show registered authors in a live list
Cancel expired reservations Automation Record expiry when an uncollected reservation is due
Import members from HR Translation Apply Library registration rules to active HR staff

Each slice keeps one behavior in one folder: user intent, a query’s needs, background work or an external vocabulary. Chronicle holds the event log, Arc the commands and queries, and Components the UI.