feat(wallet): add wallet management API and migration
Summary
- Add authenticated wallet management APIs following the project layer structure:
route → validation → controller → service → repository. - Enforce wallet ownership using the authenticated user ID.
- Support wallet listing, creation, retrieval, updates, default selection, archiving, and restoration.
- Preserve monetary precision by handling wallet balances as decimal strings.
- Add serializable transactions with retry handling for default-wallet consistency.
- Add a Wallet-specific Prisma migration and regenerate Prisma Client types.
- Document all Wallet endpoints and schemas in Swagger.
- Update agent guidelines to require migration-history and generated-client verification after Prisma changes.
API Changes
GET /api/v1/walletsPOST /api/v1/walletsGET /api/v1/wallets/:idPUT /api/v1/wallets/:idPATCH /api/v1/wallets/:id/defaultPATCH /api/v1/wallets/:id/restoreDELETE /api/v1/wallets/:id
DELETE archives the wallet instead of deleting it permanently. A default wallet must be replaced before it can be archived.
Database Changes
- Add Wallet metadata fields:
currency,icon,color, anddescription. - Add
is_defaultandis_archivedstate fields. - Change wallet balance to
DECIMAL(18, 2). - Add an index on
wallets.user_id. - Change the transaction-wallet foreign key to
ON DELETE RESTRICT.
Verification
pnpm run prisma:generatepnpm exec prisma validatepnpm build- Applied the complete migration chain successfully to a temporary PostgreSQL database.
git diff --check
Notes
- The primary development database was not reset or migrated during implementation.
- Older migration history still has unrelated Auth, Category, and Budget schema debt. Those changes were intentionally excluded because the full diff contains destructive operations outside this feature's scope.