Skip to content

Adoption: run effect-domain commands behind JSON:API endpoints and atomic operations #653

Open

Description

@thomasfosterau

Context

effect-domain is a backend-free aggregate kernel: commands, pure decide functions and events, with an all-or-nothing Transaction.atomically as the consistency boundary. Its core landed in effect-domain#1. The apps that adopt it expose JSON:API through this library, and that stays the only API.

Decided shape

  • JSON:API is the transfer layer, not the domain model. Resources stay hand-written with Resource.make. A resource often lines up with an entity and a collection with an aggregate, but the mapping is explicit.
  • The mapping lives in effect-domain, as @thomasfosterau/effect-domain-jsonapi. It maps a create, update, delete or atomic operation to commands, and an aggregate's state back to a resource (toResource, toCommand). effect-jsonapi never depends on effect-domain.
  • An atomic:operations request runs in one transaction: every operation commits, or none does. Several commands, often on several aggregates, inside one atomically.

What effect-jsonapi may need

The adapter should need only public API. While building it, check:

  • One boundary per atomic request. ResourceHandlers' Transact seam wraps each write. For an atomic request the adapter opens one transaction around the whole document; a per-write Transact must then join it (a savepoint, or a no-op) rather than open its own.
  • Server-side atomic processing. Endpoint and Atomic model the request and result documents; executing one (dispatch per operation, lid resolution across operations, atomic:results in order, errors pointed at /atomic:operations/<i>) is left to the application today. If every adopter would write the same loop, a small processor here with a per-operation callback would serve effect-domain-jsonapi and plain handlers alike.
  • Errors from tagged failures. A command's rejection is a Schema.TaggedError; the adapter maps it to a JSON:API error object (422 for a rule, 409 for VersionConflict, 404 for AggregateNotFound). Confirm ApiError / ServerErrors take that mapping without private imports.
  • Optional: a helper that drafts a Resource from an aggregate's state schema, as a convenience only. A hand-written Resource.make stays the definition.

Anything effect-jsonapi has to change gets its own PR here; the adapter itself goes in effect-domain.

Acceptance

effect-domain-jsonapi serves one aggregate's create, update and delete, and an atomic request spanning two aggregates that rolls back entirely when the second operation's command is rejected, using only effect-jsonapi's public exports.

Activity

  1. added
    enhancement
    on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions