Skip to content

Add event-bus-dto crate: shared envelope + schema generation#4583

Open
jmg-duarte wants to merge 4 commits into
mainfrom
jmgd/event-bus-dto
Open

Add event-bus-dto crate: shared envelope + schema generation#4583
jmg-duarte wants to merge 4 commits into
mainfrom
jmgd/event-bus-dto

Conversation

@jmg-duarte

@jmg-duarte jmg-duarte commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Description

Extracts the events into a separate crate so we can provide a JSONSchema for downstream usage (like analytics).
Generation style is similar to that of contracts, checks on CI are included.

Context: https://nomevlabs.slack.com/archives/C0B2X0Q7ERK/p1782315064424599

Related to BE-44

Changes

  • Extract event types to a new crate
  • Added JSONSchema generation

How to test

cargo r -p event-bus-dto

Introduce a dependency-light crate holding the DTOs for events published
on the NATS event bus, the shared `Envelope` wire format (moved out of
observe so it has a single source of truth) and an `event-bus-schemas` CLI
that emits a JSON schema per subject (the full envelope-wrapped shape
downstream consumers receive).

Ports the existing `priceEstimate` event into the crate unchanged and wires
price-estimation and observe to it. New events are added in follow-up
commits.
@jmg-duarte jmg-duarte requested review from a team as code owners July 1, 2026 16:08
@claude

claude Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Claude finished @jmg-duarte's task in 3m 23s —— View job


PR Review: Add event-bus-dto crate

Reviewed the new crate, the schema-generation tooling, the CI check, and the migration out of observe / price-estimation. This is a clean, well-scoped refactor — the wire-format tests moved along with the types, the envelope logic is now single-sourced in Envelope::new, and the CI up-to-date check (git diff --exit-code) is logically correct.

Two non-blocking points posted inline:

  • schemas() can silently drift — it's a hand-maintained list, so a new Event impl that isn't added here just won't appear in events.json, and CI won't catch it. (lib.rs:32)
  • version isn't pinned in the schema — it's the field the envelope contract is built around, but the schema only says type: string. A schemars const/enum would make it machine-checkable. (envelope.rs:15)

Minor observations, not worth blocking on:

  • observe::event_bus::publish is now only reached via publish_event; could be made private, but it's a reasonable public escape hatch for ad-hoc events.
  • This adds schemars 1.2 while serde_with already pulls a (feature-gated) schemars 0.9, so two versions coexist in the graph. Fine given the crate is tiny.
  • The AddressString change in emit_quote_event (from.to_string()) preserves the prior checksummed serialization, so no observable wire change.

Nice work — LGTM.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new event-bus-dto crate to centralize wire-format event types (DTOs) and their JSON schemas, separating them from the event producers. It extracts the Envelope and PriceEstimateEvent structures from the observe and price-estimation crates, and adds a schema generation binary (event-bus-schemas) along with a Justfile command to output the JSON schemas. The observe and price-estimation crates have been updated to use these shared types. No critical issues found.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread crates/event-bus-dto/src/lib.rs
Comment thread crates/event-bus-dto/src/envelope.rs
@linear-code

linear-code Bot commented Jul 1, 2026

Copy link
Copy Markdown

BE-44

jmg-duarte and others added 2 commits July 1, 2026 17:28
Constrain the `version` field's generated schema to the current
ENVELOPE_VERSION so downstream consumers can validate the wire-format
version against the schema instead of just `type: string`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant