Skip to content

Vinceveve/eventmodeling

Repository files navigation

Event modeling

Goal, Make this schema alive : Scenario for the eventmodeling

Described using Event Modeling All the post-its on the schema exists in the codebase

Using NATS Jetstream and NestJS

Concepts

And folder structure too

Feature :

The whole schema : One folder per event model containing everything needed for the flow

Adapter

Rows on the top : For each UI/Trigger on the schema an adapter.

NestJS controllers to adapt source protocol to domain's needs

  • HTTP REST API
  • Nats consumers :

Command

Blue post-its :

  • Business logic : handles command, emits events.
  • WARNING : Create, Update, Delete on the database is forbidden here !
  • Better to use with one Command by file to make code more atomic.
  • Consistency on the application : Infinite message deduplication in JetStream
  • Publish domain events on nats subjects (JetStream or Core)

Projection

Green Post it :

Model

All DTOs are here :

  • Shared accross all features on all domains and all teams
  • One folder per domain (bottom rows on the schema)
  • Mainly declarative

Event

Orange Post its

Stream

The row on the bottom :

Entity

Our core domain

Full Application layers

Run it

docker run -d --name nats -p 4222:4222 -p 8222:8222 -p 6222:6222 nats --jetstream -m 8222

rush install
ts-node feature/hotel-booking/backend/main.ts 

curl --request PUT \
 --url http://127.0.0.1:3000/mutation/book-room \
 --header 'Content-Type: application/json' \
 --data '{
    "data": {
      "room": { "id" : 1},
      "client": { "id": 1},
      "date": "2022-12-12"
    }
  }'

curl --request PUT \
 --url http://127.0.0.1:3000/mutation/cleanup \
 --header 'Content-Type: application/json' \
 --data '{
    "data": {
      "room": { "id" : 1},
      "date": "2022-12-12"
    }
  }'

curl --request PUT \
 --url http://127.0.0.1:3000/mutation/checkin \
 --header 'Content-Type: application/json' \
 --data '{
    "data": {
      "room": { "id" : 1 },
      "client": { "id": 1},
      "date": "2022-12-13"
    }
  }'

nats stream view room-booking --subject='booking.1.2022-12-12.1_2022-12-12'
nats stream view room-cleanup --subject='cleanup.1.2022-12-12.1_2022-12-12'

TODO :

  • Documentation
    • AsyncAPI request and sub
    • Websocket example
    • NATS cli command doc to debug (or docker GUI ?)
  • Event|Command validation
    • Use CloudEvent as base event interface on driver
    • Use CloudEvent as base command interface
    • Middleware validation
  • Idempotency
    • publish options per event's emit
    • Fix Expect last subject sequence not working (poc root)
  • Shared state with materialized views
    • allow access to nats JetStream KeyStore from client
    • mapper to nats Keystore table.id.attributes = bucket.key.value
    • watch in projection to compare with state
    • handle state modification automatically
  • QOS connection lost
  • Auth and security
    • configure nats accounts
    • Set websocket access limits solutions
  • Publishing
    • publish event
    • send message
    • simplify NatsJetStreamClient+Proxy
  • Subscribing
    • Pull Subscription
    • One specific consumer per destination
    • consumer
    • message handler with nats
    • auto stream creation

About

Goal, Make a working app from an event model

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published