hicommonwealth / commonwealth

A platform for decentralized communities
https://commonwealth.im
GNU General Public License v3.0
69 stars 44 forks source link

Reduce Event Boilerplate #9416

Open rbennettcw opened 1 month ago

rbennettcw commented 1 month ago

As of recently, almost every feature we build requires creating new events/policies/projections passed via the Outbox/RMQ system. But there's a lot of boilerplate required to produce a working event pipeline:

- Create event schema in `events.schemas.ts`
- Add event to `EventNames` enum and `EventPairs` union type in `events.ts`
- Add event to Outbox zod union schema in `outbox.schema.ts`
- Add event to `inputs` object when defining a policy/projection
- Add event to `RascalRoutingKeys` enum and `allBindings` record in `rascalConfig.ts`
- Add policy/projection to `allQueues` record in `rascalConfig.ts`
- Potentially add event to `getRoutingKey` if routing is dynamic
- Bind subscription in consumer

With so many steps, making an error or forgetting a step is almost inevitable.

The ideal approach would be:

With all the improvements that have been made to the framework, this is the last major bottleneck for development velocity. We can make development faster and safer by abstracting away all event-handling logic.

Rotorsoft commented 1 month ago

How much of this boilerplate can be derived from the basic schema structure? In other words, given a list of policies/projections (event handlers) with their respective schemas (input events/schemas), how much integration (wiring) can we build by establishing some sensible conventions (naming, bindings, queues, routing, strategies, etc).