Problem
Pages fetch data independently with ad-hoc query usage and no shared cache
strategy. After a mutation (deposit, vouch, product CRUD) other views keep
showing stale data until a manual refresh, there are no optimistic updates
or rollback, and query keys are inconsistent across services. This produces
visible inconsistencies (e.g. a new product not appearing on the vendor
detail page, pool stats not updating after a deposit).
Before Starting
Read ALL of these before writing any code:
- context/architecture-context.md
- context/code-standards.md
What To Build
A React Query cache architecture standardized across the services layer:
- A central query-key factory so every entity (pool, loans, vouches,
vendors, reputation) has canonical, hierarchical keys.
- A mutation → invalidation map so each mutation invalidates exactly the
affected query subtrees on success.
- An optimistic-update pattern with rollback for the high-frequency
mutations (vouch accept/decline, product CRUD, deposit/withdraw).
- Sensible
staleTime / gcTime defaults and a documented convention that
new services must follow.
Files To Touch
- src/services/queryKeys.ts (new)
- src/services/*.service.ts (adopt keys + invalidation)
- src/hooks/* (optimistic mutation helpers)
- relevant page components
Acceptance Criteria
Mandatory Checks Before Opening PR
Problem
Pages fetch data independently with ad-hoc query usage and no shared cache
strategy. After a mutation (deposit, vouch, product CRUD) other views keep
showing stale data until a manual refresh, there are no optimistic updates
or rollback, and query keys are inconsistent across services. This produces
visible inconsistencies (e.g. a new product not appearing on the vendor
detail page, pool stats not updating after a deposit).
Before Starting
Read ALL of these before writing any code:
What To Build
A React Query cache architecture standardized across the services layer:
vendors, reputation) has canonical, hierarchical keys.
affected query subtrees on success.
mutations (vouch accept/decline, product CRUD, deposit/withdraw).
staleTime/gcTimedefaults and a documented convention thatnew services must follow.
Files To Touch
Acceptance Criteria
Mandatory Checks Before Opening PR