# Examples

> Example applications in the Occurrent repository.

The [`example`](https://github.com/johanhaleby/occurrent/tree/occurrent-0.34.0/example) folder in the repository has runnable, tested applications that put the concepts on this page together. The table below points to the most instructive ones and highlights which Occurrent features each demonstrates. Every link is pinned to the `0.34.0` release.

| Example                                                                                                                                                                  | What it shows                                                                                                                                                                                                                                                                                                                                        | Occurrent features                                                                                                                                                                                                                               |
| :----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Number guessing game](https://github.com/johanhaleby/occurrent/tree/occurrent-0.34.0/example/domain/number-guessing-game)                                               | A guess-the-secret-number game in plain Java, wired up two ways: the native MongoDB driver and Spring Boot (blocking).                                                                                                                                                                                                                               | `GenericApplicationService`, native and Spring (blocking) MongoDB event stores, subscription-based read models, side-effects (policies), integration events, `CloudEventConverter`                                                               |
| [Word guessing game](https://github.com/johanhaleby/occurrent/tree/occurrent-0.34.0/example/domain/word-guessing-game)                                                   | A hangman-style word game as a full feature-sliced CQRS app on Spring Boot, in both a classic stream version and a DCB version.                                                                                                                                                                                                                      | Blocking subscriptions, subscription-driven side-effects (reveal hint, award points, email winner), MongoDB read models with the Query DSL, `CloudEventConverter`, DCB, jqwik property tests                                                     |
| [Rock paper scissors](https://github.com/johanhaleby/occurrent/tree/occurrent-0.34.0/example/domain/rps)                                                                 | The same game modelled several ways (pragmatic, single-round and multi-round `Decider`), plus a Spring Boot web app that plays it.                                                                                                                                                                                                                   | `Decider` DSL, combining and multi-round deciders, Spring Boot starter (`@EnableOccurrent`), CQRS gameplay and views, blocking subscriptions                                                                                                     |
| [Uno](https://github.com/johanhaleby/occurrent/tree/occurrent-0.34.0/example/domain/uno)                                                                                 | The Uno card game as a pure event-sourced model, run against the native MongoDB driver and Spring.                                                                                                                                                                                                                                                   | Event-sourced model, native and Spring MongoDB event stores, `GenericApplicationService`, command composition, `NativeMongoSubscriptionModel`                                                                                                    |
| [Mastermind](https://github.com/johanhaleby/occurrent/tree/occurrent-0.34.0/example/domain/mastermind)                                                                   | The Mastermind board game modelled with the `Decider` pattern, playable against the computer.                                                                                                                                                                                                                                                        | `Decider` DSL, in-memory event store, `ApplicationService`                                                                                                                                                                                       |
| [Course enrollment](https://github.com/johanhaleby/occurrent/tree/occurrent-0.34.0/example/domain/course-enrollment)                                                     | Enrolling a student holds a course-capacity rule and a per-student limit at once, across two entities, using DCB.                                                                                                                                                                                                                                    | DCB, blocking `DcbApplicationService`, `dcbDecider` DSL, Spring Boot starter auto-configuration, conditional append with retry                                                                                                                   |
| [Hotel booking](https://github.com/johanhaleby/occurrent/tree/occurrent-0.34.0/example/domain/hotel-booking)                                                             | The reactive twin of course enrollment: no double-booking a room, a per-guest active-booking limit, and a live SSE activity feed.                                                                                                                                                                                                                    | Reactive DCB, reactive `DcbApplicationService`, DCB subscription DSL (SSE feed), reactive Spring Boot starter, cross-boundary deciders                                                                                                           |
| [Appointment scheduling](https://github.com/johanhaleby/occurrent/tree/occurrent-0.34.0/example/domain/appointment-scheduling)                                           | A clinic scheduler that books a clinician, patient and time slot under one consistency boundary, in plain Java with no Spring.                                                                                                                                                                                                                       | DCB on the native MongoDB store, plain Java `Decider`s with a hand-built `DcbCriteria`, `@DcbTag` annotation tags (`AnnotationTagGenerator`), Javalin and j2html web                                                                             |
| [DCB patterns catalog](https://github.com/johanhaleby/occurrent/tree/occurrent-0.34.0/example/domain/dcb-patterns)                                                       | Five self-contained vignettes covering the [dcb.events](https://dcb.events/examples/) patterns the other examples do not show: unique username with a retention period, idempotency, a price change grace period, a consume-once opt-in token, and a gapless invoice number. Kotlin, no Spring, no Docker.                                           | DCB, `DcbDecider`, `GenericDcbApplicationService`, in-memory DCB event store, uniqueness and idempotency as a scoped append condition, `DcbReadOptions.fromBeginning().backwards().limit(1)`                                                     |
| [Projection DSL](https://github.com/johanhaleby/occurrent/tree/occurrent-0.34.0/example/projection/projection-dsl)                                                       | Four vignettes on the [Projection DSL](/docs/layer-1/projections/), in Java and Kotlin, stream and DCB. Each projection is run two ways, pushed through a subscription into a stored read model and run over a query on demand, and the two are asserted to agree.                                                                                   | `Projection`, `DcbProjection`, the Java handler builder and the Kotlin `projection { }` DSL, `MaterializedView`, an explicit `Filter` selecting on subject, tag-scoped single-instance read models, in-memory event store and subscription model |
| [Global position catch-up](https://github.com/johanhaleby/occurrent/tree/occurrent-0.34.0/example/projection/global-position-catchup)                                    | The global `position` assigned to every event, and rebuilding a projection by replaying across streams in write order.                                                                                                                                                                                                                               | Global position, catch-up projections, `DomainEventQueries.readInPositionOrder`, in-memory event store, `withoutStreamPosition()` opt-out                                                                                                        |
| [Subscription-based projections](https://github.com/johanhaleby/occurrent/tree/occurrent-0.34.0/example/projection/spring-subscription-based-mongodb-projections)        | Building a MongoDB read model by subscribing to the event stream.                                                                                                                                                                                                                                                                                    | Blocking subscriptions, MongoDB read models, `CloudEventConverter`                                                                                                                                                                               |
| [Transactional projection (blocking)](https://github.com/johanhaleby/occurrent/tree/occurrent-0.34.0/example/projection/spring-transactional-projection-mongodb)         | Updating a projection in the same MongoDB transaction as the event append.                                                                                                                                                                                                                                                                           | Blocking Spring MongoDB event store, same-transaction projections                                                                                                                                                                                |
| [Transactional projection (reactive)](https://github.com/johanhaleby/occurrent/tree/occurrent-0.34.0/example/projection/spring-reactor-transactional-projection-mongodb) | The reactive version of the transactional projection.                                                                                                                                                                                                                                                                                                | Reactive Spring MongoDB event store, same-transaction projections on Project Reactor                                                                                                                                                             |
| [Ad-hoc event store queries](https://github.com/johanhaleby/occurrent/tree/occurrent-0.34.0/example/projection/spring-adhoc-eventstore-mongodb-queries)                  | Answering a query (most workouts completed) by querying the event store directly, with no separate read model.                                                                                                                                                                                                                                       | `EventStore` queries, ad-hoc querying, Spring MongoDB                                                                                                                                                                                            |
| [Order fulfillment saga](https://github.com/johanhaleby/occurrent/tree/occurrent-0.34.0/example/saga/order-fulfillment)                                                  | One order-fulfillment process written twice, with the machine-core `Saga.builder(...)` in Java and with the Kotlin flow `saga { }` block, both run through `SagaRunner`. Placing an order reserves payment and arms a timeout, a reservation ships the order, and a payment failure or the timeout firing cancels it. In-memory, no Docker.          | `Saga`, the core and flow saga DSLs, `SagaRunner`, per-instance state and timers, `CommandDispatcher` both as a plain `ApplicationService` lambda and through the `CommandDispatchers.decider(...)` adapter                                      |
| [Closing the books](https://github.com/johanhaleby/occurrent/tree/occurrent-0.34.0/example/snapshot/closing-the-books)                                                   | An account ledger using both snapshot styles: `everyNEvents` to keep a long-lived stream’s replay bounded, and `whenTerminal` to snapshot the closing balance when the books close. The closing balance carries into the next period as an event, so the closed period’s detailed events can be archived without losing money. In-memory, no Docker. | `SnapshotDeciderApplicationService`, `SnapshotPolicy` (`everyNEvents`, `whenTerminal`), `schemaVersion` falling back to a full replay, `EventStoreOperations.deleteEventStream`                                                                  |
| [Forward to Spring events](https://github.com/johanhaleby/occurrent/tree/occurrent-0.34.0/example/forwarder/mongodb-subscription-to-spring-event)                        | Forwarding CloudEvents from a MongoDB subscription to Spring `ApplicationEvent`s.                                                                                                                                                                                                                                                                    | Blocking subscriptions, Spring `ApplicationEventPublisher` integration                                                                                                                                                                           |