Skip to content

refactor!: one source for stores, projections, models and hosts - #348

Open
patrickleet wants to merge 1 commit into
v5from
refactor/v5-review-28b-service-repetition
Open

patrickleet wants to merge 1 commit into
v5from
refactor/v5-review-28b-service-repetition

Conversation

@patrickleet

Copy link
Copy Markdown
Collaborator

Task 28 stage B: remove the repetition in the reference app's service layer (review 13 findings #4, #5, #6, #7, #8, #28), in both e2e-ui and e2e-celld.

Changes

  • feat: mutable find by id #4 trait-bound walls.
    • New distributed::microsvc::Stores { events, locks, read_models } and trait ServiceStores, with associated Events, Queued and ReadModels, and a blanket impl.
    • New aliases AggregateDependencies<St, A> and StoreDependencies<St>.
    • A module is now fn routes<St: ServiceStores>(stores: &St, projections: &LocalProjectionMounts) and Routes::for_aggregate(stores).
    • Deleted all six bounds.rs copies (236 lines), both deps.rs files and blob's dead _blob_direct parameter.
  • feat: Repository trait + HashMapRepository #5 projection name, epoch and model stated three times.
    • LocalProjectionMounts::builder(service, source).eventual(DESC).direct(DESC).build() reads them from the projection! descriptor, so a mismatch can no longer exist.
    • projector(DESC) replaces projector("name").
    • The four pass-through handler files are deleted; modules call .consume_projection(projections.projector(TODOS)).
    • Game callers are updated.
  • feat: refactor + outbox pattern support #6 manifest. application_manifest() comes from Service::application. Deleted MODULE_ID (×4), MODULE_IDS, MODULE_DECLARATIONS, E2E_UI_MODULE_IDS, COMMAND_PREFIX (×2) and the test that asserted a constant equals itself.
  • feat: boundaries #7 read-model list in six places.
    • AuthorizedReadModel::permissions() keeps permissions next to the model.
    • One ReadModels::new(name).model::<M>() catalog feeds schema bootstrap, grants, GraphqlEngineBuilder::read_models, the version-store table names and client export.
    • Client surfaces are declared once as ClientSurface constants, which the engine and the export both use.
  • feat: traits + macro + more complicated tests #8 SQLite/Postgres host fork.
    • One generic host over trait SqlStores, implemented by SqliteStores and PostgresStores.
    • The hosts' own spawn_outbox_publish_loop(.., 30s, 5) is removed. with_bus already starts a drainer that polls pending rows, and the two were competing for the same outbox.
    • _dispatcher is gone.
  • fix: harden outbox claim leases #28 duplicated helpers. HandlerError::rejected, guards::authenticated and guards::role(..) replace the per-domain copies. Also deleted ClientSurfaceLocks (×2), the empty handlers/commands/mod.rs and e2e-celld's dead handlers/util.rs.

The two demo trees lose 19 files (441 lines); overall the diff is +1,086 / −2,070.

Breaking:

  • Routes::for_aggregate takes &impl ServiceStores.
  • LocalProjectionMounts is built from descriptors; eventual_model, direct_model, direct_projection and projector(&str) are gone.
  • The e2e manifest's identity module is named zitadel, after its zitadel.* command namespace. No generated file changed.

Verification (local)

  • cargo check --workspace --all-targets --all-features: passes.
  • cargo check -p distributed --tests --no-default-features: passes, and each of the 19 features alone passes.
  • wasm32: check-wasm32-domains.sh passes, as do the 5 celld workers and examples/game/cells.
  • cargo test -p distributed --all-features: 2,196 passed, 0 failed.
  • make test-local: 2,865 passed, 0 failed.
  • e2e-ui cargo test --workspace: 98 passed. make ci-offline passes with UI 16/16 and no generated drift.
  • e2e-celld cargo test --workspace: 25 passed.
  • distributed build of e2e-ui and e2e-celld: drift: [].
  • Game server: fmt, clippy -D warnings, 68 tests and the build all pass. Game cells pass wasm32 clippy and fmt.
  • The mobpit_smoke tests pass 5/5 with CELLD_BIN and CELLD_ESBUILD set, as CI sets them.
  • cargo test -p distributed_cli: 323 passed, 0 failed.

Not done

  • e2e-celld's graphql-service still keeps copies of projections.rs, application.rs and the engine and export helpers. They are now identical to e2e-ui's; making e2e-celld a runner over the shared crates is stage C.
  • The live Zitadel stack and the browser Playwright suite are left to CI.

The reference app restated framework knowledge in every module: an
18-line trait-bound wall per `routes()` (and a `bounds.rs` copied six
times), each projection's name and epoch three times through a
pass-through handler, the read-model list in six places, a hand-built
manifest beside `Service::application`, and two 65-line SQLite and
Postgres hosts.

- `Stores { events, locks, read_models }` and the `ServiceStores`
  trait: a module is `fn routes<St: ServiceStores>(stores, projections)`
  and `Routes::for_aggregate(stores)`.
- `LocalProjectionMounts::builder(..).eventual(DESC).direct(DESC)`
  reads name, epoch and model from the `projection!` descriptor;
  modules mount `projections.projector(TODOS)` directly.
- `AuthorizedReadModel` keeps permissions next to the model, and one
  `ReadModels` catalog feeds schema bootstrap, grants, the engine, the
  version store and client export. Client surfaces are declared once.
- The application manifest is `Service::application`'s; the module id
  constants and their self-asserting test are gone.
- One generic host over `SqlStores` (SQLite and Postgres); the hosts'
  own outbox loop is gone, since `with_bus` already drains and polls.
- `HandlerError::rejected`, `guards::authenticated` and `guards::role`
  replace per-app helper copies.

Both demos: 19 files deleted (441 lines), +1,086 / -2,070 overall.

BREAKING CHANGE: `Routes::for_aggregate` takes `&impl ServiceStores`;
`LocalProjectionMounts` is built from descriptors (`eventual_model`,
`direct_model`, `direct_projection` and `projector(&str)` are gone).
The e2e manifest's identity module is named `zitadel`, after its
command namespace.

Implements [[tasks/v5-review-28]]
@coderabbitai

coderabbitai Bot commented Nov 25, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 72dedc02-cb59-46e3-9fc5-82bae5c3245b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

This branch has not been deployed

No deployments
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