Cratis Chronicle projection tags
Projection tags in Cratis Chronicle label a projection definition with its purpose or domain, such as Analytics or Inventory. Use them to describe what a projection is for. They do not filter the events it observes or select projections for operations such as rebuilds.
To control projection input, declare the event types and select the event sequence. If you need a reducer or reactor to process only events with particular metadata, use appended event metadata filters instead of projection tags.
Adding Tags
Section titled “Adding Tags”Choose the form that keeps the labels readable beside the projection. A single tag, several tags in one attribute or decorator, and repeated attributes or decorators all label the same definition.
Single Tag
Section titled “Single Tag”Place a tag on the projection class. In this example, Analytics describes the projection’s purpose:
using Cratis.Chronicle;using Cratis.Chronicle.Events;using Cratis.Chronicle.Projections;
[EventType]public record TaggingOrderPlaced(string OrderId);
[EventType]public record TaggingItemAddedToOrder(decimal Amount);
public record TaggingOrderAnalytics(string OrderId, decimal TotalAmount);
[Tag("Analytics")]public class TaggingOrderAnalyticsProjection : IProjectionFor<TaggingOrderAnalytics>{ public void Define(IProjectionBuilderFor<TaggingOrderAnalytics> builder) => builder .From<TaggingOrderPlaced>() .From<TaggingItemAddedToOrder>(_ => _ .Add(m => m.TotalAmount).With(e => e.Amount));}Kotlin does not support this workflow yet.`@Tag` only labels a reactor or reducer — neither `ProjectionsService.buildDeclarativeDefinition` nor`buildModelBoundDefinition` ever reads a `Tag` annotation off a projection class, so tagging aprojection has no effect yet.Java does not support this workflow yet.`@Tag` only labels a reactor or reducer — neither `ProjectionsService.buildDeclarativeDefinition` nor`buildModelBoundDefinition` ever reads a `Tag` annotation off a projection class, so tagging aprojection has no effect yet.Elixir does not support this workflow yet.import { eventType, IProjectionBuilderFor, IProjectionFor, projection, tag } from '@cratis/chronicle';
@eventType()class TaggingOrderPlaced { orderId = '';}
@eventType()class TaggingItemAddedToOrder { amount = 0;}
class TaggingOrderAnalytics { orderId = ''; totalAmount = 0;}
@projection('', TaggingOrderAnalytics)@tag('Analytics')class TaggingOrderAnalyticsProjection implements IProjectionFor<TaggingOrderAnalytics> { define(builder: IProjectionBuilderFor<TaggingOrderAnalytics>): void { builder.from(TaggingOrderPlaced) .from(TaggingItemAddedToOrder, from => from.add(model => model.totalAmount).with(event => event.amount)); }}Multiple Tags (Single Attribute)
Section titled “Multiple Tags (Single Attribute)”Pass several names to label a projection for more than one purpose. The C# attribute uses params; the TypeScript decorator accepts multiple names too:
using Cratis.Chronicle;using Cratis.Chronicle.Events;using Cratis.Chronicle.Projections;
[EventType]public record TaggingSaleRecorded(string ProductId, decimal Amount);
public record TaggingSalesReport(string ProductId, decimal TotalSales);
[Tag("Analytics", "Reporting", "Dashboard")]public class TaggingSalesReportProjection : IProjectionFor<TaggingSalesReport>{ public void Define(IProjectionBuilderFor<TaggingSalesReport> builder) => builder .From<TaggingSaleRecorded>(_ => _ .Add(m => m.TotalSales).With(e => e.Amount));}Kotlin does not support this workflow yet.`@Tag` only labels a reactor or reducer — neither `ProjectionsService.buildDeclarativeDefinition` nor`buildModelBoundDefinition` ever reads a `Tag` annotation off a projection class, so a `@Tag` withmultiple values on a projection has no effect yet.Java does not support this workflow yet.`@Tag` only labels a reactor or reducer — neither `ProjectionsService.buildDeclarativeDefinition` nor`buildModelBoundDefinition` ever reads a `Tag` annotation off a projection class, so a `@Tag` withmultiple values on a projection has no effect yet.Elixir does not support this workflow yet.import { eventType, IProjectionBuilderFor, IProjectionFor, projection, tags } from '@cratis/chronicle';
@eventType()class TaggingSaleRecorded { productId = ''; amount = 0;}
class TaggingSalesReport { productId = ''; totalSales = 0;}
@projection('', TaggingSalesReport)@tags('Analytics', 'Reporting', 'Dashboard')class TaggingSalesReportProjection implements IProjectionFor<TaggingSalesReport> { define(builder: IProjectionBuilderFor<TaggingSalesReport>): void { builder.from(TaggingSaleRecorded, from => from.add(model => model.totalSales).with(event => event.amount)); }}Multiple Tags (Multiple Attributes)
Section titled “Multiple Tags (Multiple Attributes)”You can put each tag on its own line with repeated [Tag] attributes or @tag decorators:
using Cratis.Chronicle;using Cratis.Chronicle.Events;using Cratis.Chronicle.Projections;
[EventType]public record TaggingAuditEntryRecorded(string EntryId, string Category);
public record TaggingComplianceReport(string EntryId, string Category);
[Tag("Analytics")][Tag("Compliance")][Tag("Auditing")]public class TaggingComplianceReportProjection : IProjectionFor<TaggingComplianceReport>{ public void Define(IProjectionBuilderFor<TaggingComplianceReport> builder) => builder .From<TaggingAuditEntryRecorded>();}Kotlin does not support this workflow yet.`@Tag` only labels a reactor or reducer — neither `ProjectionsService.buildDeclarativeDefinition` nor`buildModelBoundDefinition` ever reads a `Tag` annotation off a projection class, so repeated `@Tag`attributes on a projection have no effect yet.Java does not support this workflow yet.`@Tag` only labels a reactor or reducer — neither `ProjectionsService.buildDeclarativeDefinition` nor`buildModelBoundDefinition` ever reads a `Tag` annotation off a projection class, so repeated `@Tag`attributes on a projection have no effect yet.Elixir does not support this workflow yet.import { eventType, IProjectionBuilderFor, IProjectionFor, projection, tag } from '@cratis/chronicle';
@eventType()class TaggingAuditEntryRecorded { entryId = ''; category = '';}
class TaggingComplianceReport { entryId = ''; category = '';}
@projection('', TaggingComplianceReport)@tag('Analytics')@tag('Compliance')@tag('Auditing')class TaggingComplianceReportProjection implements IProjectionFor<TaggingComplianceReport> { define(builder: IProjectionBuilderFor<TaggingComplianceReport>): void { builder.from(TaggingAuditEntryRecorded); }}Mixed Approach
Section titled “Mixed Approach”You can also combine multi-name and repeated annotations on the same class:
using Cratis.Chronicle;using Cratis.Chronicle.Events;using Cratis.Chronicle.Projections;
[EventType]public record TaggingKpiRecorded(string Kpi, decimal Value);
public record TaggingExecutiveDashboard(string Kpi, decimal Value);
[Tag("Analytics", "Reporting")][Tag("Executive")]public class TaggingExecutiveDashboardProjection : IProjectionFor<TaggingExecutiveDashboard>{ public void Define(IProjectionBuilderFor<TaggingExecutiveDashboard> builder) => builder .From<TaggingKpiRecorded>();}Kotlin does not support this workflow yet.`@Tag` only labels a reactor or reducer — neither the declarative nor the model-bound projectionbuilder in `ProjectionsService` ever reads a `Tag` annotation off a projection class, so tagging aprojection (fluent or model-bound) has no effect yet.Java does not support this workflow yet.`@Tag` only labels a reactor or reducer — neither the declarative nor the model-bound projectionbuilder in `ProjectionsService` ever reads a `Tag` annotation off a projection class, so tagging aprojection (fluent or model-bound) has no effect yet.Elixir does not support this workflow yet.import { eventType, IProjectionBuilderFor, IProjectionFor, projection, tag, tags } from '@cratis/chronicle';
@eventType()class TaggingKpiRecorded { kpi = ''; value = 0;}
class TaggingExecutiveDashboard { kpi = ''; value = 0;}
@projection('', TaggingExecutiveDashboard)@tags('Analytics', 'Reporting')@tag('Executive')class TaggingExecutiveDashboardProjection implements IProjectionFor<TaggingExecutiveDashboard> { define(builder: IProjectionBuilderFor<TaggingExecutiveDashboard>): void { builder.from(TaggingKpiRecorded); }}Model-Bound Projections
Section titled “Model-Bound Projections”A model-bound projection declares its mappings on the read model itself, so put the tags on that type. The Inventory and Operations labels below become metadata on its projection definition; they do not change the event mapping:
using Cratis.Chronicle;using Cratis.Chronicle.Events;using Cratis.Chronicle.Keys;using Cratis.Chronicle.Projections.ModelBound;
[EventType]public record TaggingProductRegistered(Guid ProductId, string Name, int QuantityInStock, decimal UnitPrice);
[Tag("Inventory", "Operations")][FromEvent<TaggingProductRegistered>(key: nameof(TaggingProductRegistered.ProductId))]public record TaggingProductInventory( [Key] Guid ProductId, string Name, int QuantityInStock, decimal UnitPrice);Kotlin does not support this workflow yet.`@Tag` only labels a reactor or reducer — `ProjectionsService.buildModelBoundDefinition` never reads a`Tag` annotation off the read model class, so tagging a model-bound projection has no effect yet.Java does not support this workflow yet.`@Tag` only labels a reactor or reducer — `ProjectionsService.buildModelBoundDefinition` never reads a`Tag` annotation off the read model class, so tagging a model-bound projection has no effect yet.Elixir does not support this workflow yet.import { eventType, fromEvent, tag } from '@cratis/chronicle';
@eventType()class TaggingProductRegistered { productId = ''; name = ''; quantityInStock = 0; unitPrice = 0;}
@tag('Inventory', 'Operations')@fromEvent(TaggingProductRegistered, { key: 'productId' })class TaggingProductInventory { productId = ''; name = ''; quantityInStock = 0; unitPrice = 0;}Best Practices
Section titled “Best Practices”Choose names a teammate can recognize without opening the projection’s mappings. Reuse the same spelling for the same domain or purpose across projections, and add a tag only when it helps describe the projection. This gives related definitions a shared vocabulary without implying that Chronicle groups them for execution.
Common Tag Examples
Section titled “Common Tag Examples”The following examples label projections by purpose, business domain, and stakeholder. Pick the categories that help someone understand your application’s read models:
using Cratis.Chronicle;using Cratis.Chronicle.Projections;
public record TaggingCategoryExamples(Guid Id);
// By domain[Tag("Sales", "Inventory", "Customer")]// By purpose[Tag("Analytics", "Reporting", "Dashboard", "Search")]// By stakeholder[Tag("Executive", "Operations", "Finance")]// By consistency model[Tag("Immediate", "Eventual")]// By data type[Tag("Aggregates", "Lists", "Details")]public class TaggingCategoryExamplesProjection : IProjectionFor<TaggingCategoryExamples>{ public void Define(IProjectionBuilderFor<TaggingCategoryExamples> builder) { }}Kotlin does not support this workflow yet.`@Tag` only labels a reactor or reducer — neither `ProjectionsService.buildDeclarativeDefinition` nor`buildModelBoundDefinition` ever reads a `Tag` annotation off a projection class, so tagging aprojection by domain, purpose, stakeholder, or any other category has no effect yet.Java does not support this workflow yet.`@Tag` only labels a reactor or reducer — neither `ProjectionsService.buildDeclarativeDefinition` nor`buildModelBoundDefinition` ever reads a `Tag` annotation off a projection class, so tagging aprojection by domain, purpose, stakeholder, or any other category has no effect yet.Elixir does not support this workflow yet.import { IProjectionBuilderFor, IProjectionFor, projection, tag } from '@cratis/chronicle';
class TaggingCategoryExamples { id = '';}
@projection('', TaggingCategoryExamples)// By domain@tag('Sales', 'Inventory', 'Customer')// By purpose@tag('Analytics', 'Reporting', 'Dashboard', 'Search')// By stakeholder@tag('Executive', 'Operations', 'Finance')// By consistency model@tag('Immediate', 'Eventual')// By data type@tag('Aggregates', 'Lists', 'Details')class TaggingCategoryExamplesProjection implements IProjectionFor<TaggingCategoryExamples> { define(_builder: IProjectionBuilderFor<TaggingCategoryExamples>): void {}}Querying by Tag
Section titled “Querying by Tag”Projection tags are stored metadata, not a query or rebuild selector. Adding Analytics to several projections does not make Chronicle select or rebuild them as a group. To change which events build a read model, edit the projection’s event declarations or event sequence selection.
See Also
Section titled “See Also”For the distinction between event tags and observer labels, read Tagging. If you are labeling other observers, continue with Reactors Tagging or Reducers Tagging.