Case study
Funds Grid
Portfolio tracker for PSX stocks, ETFs and Pakistani mutual funds: cost basis, profit and loss, tax, dividends and a KSE-100 benchmark in one view.
- Role
- Sole designer and engineer. I own the product, the frontend, the API, the database and the deployment.
- Stack
- Next.js · NestJS · Prisma · MySQL · TanStack Query

01Project
What the system is
Funds Grid is a multi-user portfolio tracker for Pakistani retail investors, covering PSX-listed stocks, ETFs and mutual funds. I designed and built it end to end on my own time: the Next.js frontend, the NestJS API and the data model behind them.
02Problem
What needed solving
Investors who hold shares through a broker and mutual funds through several fund managers only ever see one statement at a time. None of them shows a combined cost basis, realised and unrealised profit, dividend income after withholding tax, or how the whole portfolio compares with the KSE-100.
03My role
What I was responsible for
- Designed the data model for portfolios, holdings, transactions, cash movements and daily price history, built with Prisma on MySQL.
- Built the NestJS API in controller, service and repository layers, with session auth and ownership guards on every portfolio, asset and transaction.
- Built the Next.js frontend as a backend-for-frontend, so the browser never calls the API directly.
- Integrated a market-data provider for prices, fund NAVs, the KSE-100 index, dividend payouts and corporate announcements.
- Wrote reconciliation tests and a read-only diagnostic that check the portfolio figures against accounting invariants.
04Engineering
What I built
- 01
Transaction engine
Buys, sells, dividends and cash movements are replayed in order to derive weighted average cost and realised profit, and a sale can never exceed the quantity held.
- 02
Tax by filer status
Capital gains tax on each sale and withholding tax on each dividend are worked out at the investor's filer or non-filer rate.
- 03
Dividend Center
Announced payouts are matched to the shares each investor holds, then confirmed, snoozed or marked as not received.
- 04
KSE-100 benchmark
Time-weighted return, alpha, volatility and maximum drawdown against the KSE-100 for portfolios that hold stocks or ETFs.
- 05
Admin console
User management, data sync triggers and targeted push notifications, with every account action written to an audit log.
- 06
Installable app
A progressive web app that installs on a phone, with web push notifications and an offline fallback page.
05Technologies
How the pieces fit
Frontend (BFF)
- Next.js
- React
- TanStack Query
API
- NestJS
- better-auth
- Zod
Data
- Prisma
- MySQL
Integrations
- Market data provider
- Web Push
- Google sign-in
06Complexity
Engineering challenges
- Cost basis, realised profit and tax all come from replaying the transaction history, so entries recorded out of order or on the same day must still produce the same result.
- Portfolio totals must satisfy accounting identities, such as total value minus net invested capital equalling unrealised plus realised profit plus dividends, within a defined rounding tolerance.
- Prices for funds, stocks and the index arrive from an external provider and are stored as daily history, so every valuation has to show how fresh its price is.
- No investor may read or change another's portfolios, so ownership is checked on every route, including for soft-deleted records.