Skip to content

Backend: Escrow service decomposition into focused services #198

@KuchiMercy

Description

@KuchiMercy

Summary

escrow.service.ts is 1,219 lines handling creation, funding, release, disputes, queries, and expiration in a single file. Decomposing this into focused services improves maintainability and makes all subsequent escrow feature work easier.

Requirements

  • Split escrow.service.ts into focused service classes:
    • EscrowLifecycleService — create, cancel, expire, state transitions
    • EscrowFundingService — fund, release milestones, refund
    • EscrowDisputeService — file dispute, resolve dispute, evidence management
    • EscrowQueryService — findAll, findOne, findOverview, search, filter
  • Maintain the existing EscrowController API surface (no breaking changes to endpoints)
  • Extract shared validation logic into the existing EscrowStateMachine
  • Update the escrow module to register all new services
  • Ensure all existing tests still pass after decomposition

Acceptance Criteria

  • escrow.service.ts is replaced by 4 focused service files
  • No public API or endpoint changes (backward compatible)
  • All existing unit tests pass without modification (or with minimal import path updates)
  • Each new service file is under 400 lines
  • Controller injects the appropriate service for each endpoint
  • State machine validation is shared across services

Context

  • Current service: apps/backend/src/modules/escrow/services/escrow.service.ts (1,219 lines)
  • State machine: apps/backend/src/modules/escrow/escrow-state-machine.ts
  • Controller: apps/backend/src/modules/escrow/escrow.controller.ts

Points: 150

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions