Skip to content

About this specification

This section is the precise, construct-by-construct specification of the Koine language. If the Start here and Tutorials sections teach you how to think in Koine, the reference tells you exactly what each keyword does and what C# it emits.

Every page is grounded in the compiler’s tests and the Shop demo, so the snippets compile and the emitted shapes are real.

Each construct chapter follows a fixed General → Syntax → Semantics → Translation structure, uses EBNF for grammar, and cites sections with the § glyph. The full set of conventions — grammar notation, numbering, callouts, and diagnostics — is described in Notation & conventions (§2). The token-level rules (comments, identifiers, keywords, literals, operators) live in Lexical structure (§3).

A .koi file declares one or more bounded contexts. Inside a context you declare types (value objects, entities, aggregates, enums, quantities), the behaviour on those types (invariants, derived fields, commands, events, state machines, factories), the strategic pieces (specs, services, policies), and the application layer (repositories, use cases, read models, queries). At the top level — sibling to the contexts — a single contextmap wires the contexts together.

context Catalog {
enum Currency { EUR, USD, GBP }
value Money {
amount: Decimal
currency: Currency
invariant amount >= 0 "a monetary amount cannot be negative"
}
}

Each construct family has its own reference page. Start here and follow the link for the one you need.

ConstructWhat you writePage
context, module, type basicsbounded contexts, sub-namespaces, the type familiesContexts & types
value, quantity, Range<T>immutable value objects, unit-checked quantities, intervalsValue objects
entity … identified by …entities and the four identity strategiesEntities & identity
aggregate … root …aggregate roots, IAggregateRoot, versioningAggregates
enumsmart enums, with optional associated dataEnums
comparisons, arithmetic, matches, lambdasthe pure expression sublanguageExpressions
invariant, spec as guardconstructor guards, regex and conditional rulesInvariants
command, event, statesbehaviour, domain events, state machinesCommands, events & state machines
create … { … -> … emit … }factory methods and -> field initializationFactories
spec, service, policynamed predicates, domain services, reaction seamsSpecs, services & policies
repository, find, versionedrepository contracts, finders, optimistic concurrencyRepositories & concurrency
service … usecase …, readmodel, queryapplication services, CQRS read models and queriesApplication layer & CQRS
import, module, directory buildsmulti-file models, imports, sub-namespacesMulti-file, imports & modules
contextmap, integration event, publishes/subscribes, aclcontext maps, the seven roles, shared kernels, integration eventsContext maps & integration
version, @since, @deprecated, koine checkmodel versioning, deprecation, compatibility checksVersioning & evolution

For a feature-by-feature tour, see the feature catalogue. For the koine build/koine check flags, see the CLI reference.

Koine has a small set of built-in primitives that map straight to C#:

KoineC#Notes
Stringstringnot orderable
Intintorderable
Decimaldecimalmoney / quantities; orderable
Boolbool
InstantDateTimeOffsetorderable
List<T>IReadOnlyList<T>defensively copied in constructors
<Name>Idgenerated ID value objecta record wrapping a Guid by default

List<T>, Set<T>, Map<K,V>, and Range<T> are the four built-in generic type constructors. Orderable types (Int, Decimal, Instant) are the ones allowed in relational comparisons and as Range<T> element types — String is not orderable. See Value objects (§5) and Expressions (§9) for the details.

The lexical layer — comments, identifiers, the reserved (invariant, matches) vs soft keyword rule, reserved type names, literals, and the atomic -> / <-> operators — is specified in Lexical structure (§3).