Finance Core — Finance API
A REST API for a personal finance system: users, accounts (cash, checking and credit card), categories and income, expense and transfer transactions, with installments, filters and a financial summary. Auth uses JWT access/refresh with revocable tokens and e-mail password reset.
On this project I was responsible for the API only. It's now consumed by a third-party product: the front end and the product itself aren't mine. That's why this page covers the backend only.
Role
Backend developer — responsible for the API only
Period
Mar 2026
Status
In use by a third-party product
22
REST endpoints
6
entities
3
transaction types
2
supported databases
The challenge
The product needed a backend you can trust with money: balances that are always right, installment purchases that never vanish or duplicate, and transfers between accounts that don't create money out of thin air.
The API also had to deliver, in a single call, everything a statement screen needs: a filtered list, pagination and period totals.
Architecture
Modules & layers
One NestJS module per resource (users, accounts, categories, transactions, mail), with validated DTOs and DTO-to-entity mappers. A global interceptor wraps every response as { success, message, data, timestamp }, and an exception filter standardizes errors.
Strategy per transaction type
Income, expense and transfer follow different rules. Each type has its own validation strategy: a transfer, for instance, requires a destination account different from the source. A new type means a new strategy, without touching the others.
Atomic installments
An N-installment purchase becomes N entries sharing an installments_group_id, created in a single database transaction with a pessimistic lock on the account. The leftover cents from the split go to the last installment, and dates move month by month without overflowing month ends. Editing or deleting can apply to the whole group.
Revocable auth
Access/refresh tokens are persisted per user, so logout really kills the session instead of relying on JWT expiry alone. Passwords use bcrypt. The password-reset token is 32 random bytes, stored hashed, expires in 15 minutes and can be used only once.
Endpoints
Users
- POST
/users/registerpublicSign up, seeding starter accounts and categories
- POST
/users/loginpublicReturns the access/refresh pair
- POST
/users/refreshRenews the access token
- GET
/users/meCurrent user's profile
- PATCH
/users/updateUpdates name and full name
- POST
/users/logoutRevokes active tokens
- POST
/users/forgot-passwordpublicE-mails a reset link
- POST
/users/reset-passwordpublicSets a new password using the token
Accounts
- POST
/accounts/createCash, checking or credit card (closing day, due day, limit)
- GET
/accountsLists accounts with computed balance
- GET
/accounts/:idOne account and its balance
- PATCH
/accounts/update/:idUpdates an account
- DELETE
/accounts/:idRemoves an account
Categories
- POST
/categories/createIncome or expense category, with icon and color
- GET
/categoriesLists the user's categories
- GET
/categories/:idCategory detail
- PATCH
/categories/update/:idUpdates a category
- DELETE
/categories/:idRemoves a category
Transactions
- POST
/transactions/createIncome, expense or transfer, single or in installments
- GET
/transactionsFilters, search, sorting, pagination and period summary
- GET
/transactions/:idOne entry's detail
- PATCH
/transactions/:idEdits one entry or its whole installment group
- DELETE
/transactions/:installmentsGroupIdDeletes every installment in the group
Sample request
March statement filtered by category. List, pagination and totals in a single call.
Request
GET /transactions
?startDate=2026-03-01
&endDate=2026-03-31
&categoryIds=2
&sort=date&order=DESC
&page=1&limit=10
Authorization: Bearer <accessToken>Response
{
"success": true,
"message": "request successful",
"data": {
"summary": { "income": 8200, "expense": 3145.9, "balance": 5054.1 },
"transactions": [
{
"id": 418,
"description": "Notebook",
"value": 450,
"type": "expensive",
"status": "pending",
"installment": 3,
"amount_installments": 10,
"transaction_date": "2026-03-12T00:00:00.000Z"
}
],
"meta": { "total": 37, "page": 1, "limit": 10, "totalPages": 4 }
},
"timestamp": "2026-03-15T14:02:11.000Z"
}Data model
Relational model with TypeORM. Postgres in production and SQLite in development, switched by NODE_ENV:
Identity
UserUserTokenPasswordResetUser with a bcrypt password, persisted sessions (access/refresh + expiries) and hashed, expiring, single-use reset tokens.
Finances
AccountCategoryTransactionAccounts with a type (cash, checking, card) and billing data. Categories per type, with icon and color. Transactions with account, category, destination account (transfers), status (pending or completed) and installment data.
Modeling decisions
- Amounts stored as integer cents, with a TypeORM transformer converting on the way in and out.
- Balances computed with SQL aggregation (SUM with CASE per type) instead of being stored, so they're never stale.
- Composite indexes designed for the real queries, such as (user_id, transaction_date) for statements and (user_id, is_active) for accounts.
- Every row belongs to a user_id, and queries always filter by the token's user.
Highlights
Ready onboarding
New users get starter accounts and categories on sign-up, so they can start right away.
Rich filters
Date range, accounts, categories, type, status, value range, text search and sorting by date, value or creation.
Credit cards
Card accounts store closing day, due day and credit limit.
Ready to run
Dockerfile and docker-compose with Postgres. In development it starts on SQLite with zero setup.
Stack
Backend
Data
Security
DevOps
Want to build something like this?
I build custom websites, APIs and systems, from discovery to deployment. Let's talk.
Get in touch