For a long time I tracked my money in an Excel workbook: a dashboard, a budget sheet, a daily expense log, weekly summaries and a savings tracker, all in Pakistani Rupees (PKR). It worked, but it had the usual spreadsheet problems: one user, no real validation, formulas that quietly break, and nothing I could show anyone as a "real" project.

So I rebuilt it as a full-stack web application that runs with a single docker compose up.

Source code: https://github.com/mubeen780/Expense-Tracker

What it does

Every sheet of the workbook became a page:

Workbook sheet Page Highlights
Dashboard Dashboard Month/year picker, KPI cards, over-budget banner, budget vs actual per category, Need vs Want (50/30/20), payment method breakdown, charts
Expenses Expenses Add/edit/delete, search and filters, pagination, CSV export
Income Income Sources × 12 months grid with inline editing
Budget Budget Categories, salary, warning threshold, savings target
Weekly Weekly Week 1–5 summary and per-week category detail
Savings Savings Target vs actual saved, cumulative total, savings goals

On top of the spreadsheet's features I added multi-user login (JWT), so each account's data is private.

The stack and why I picked it

Layer Choice Why
Frontend React 18 + Vite + Recharts Fast dev loop, easy charts, no framework overhead
Backend Node 20 + Express Small REST API, easy to read and extend
Database PostgreSQL 16 Real relational constraints, NUMERIC for money, powerful aggregation queries
Auth JWT + bcryptjs Stateless and simple for a single-page app
Packaging Docker Compose + nginx One command to run all three services

Architecture

Browser ──► nginx (port 3000) ├─ / → static React build └─ /api/* → proxy to Express (port 4000) │ ▼ PostgreSQL 16 (volume: pgdata) 

nginx serves the compiled React app and proxies /api to the backend, so the browser only ever talks to one origin. There are no CORS headaches in production.

Project structure

expense-tracker/ ├── docker-compose.yml ├── backend/ │ └── src/ │ ├── index.js # Express app, middleware, startup │ ├── schema.sql # idempotent schema │ ├── report.js # dashboard / weekly / savings calculations │ ├── seed.js # demo account │ └── routes/ # auth, expenses, income, budget, savings... └── frontend/ ├── Dockerfile # multi-stage: build → nginx ├── nginx.conf └── src/pages/ # Dashboard, Expenses, Income, Budget, Weekly, Savings 

Data model

Eight tables, all scoped by user_id: users, settings, categories, payment_methods, expenses, income, savings_actual and savings_goals.

Two decisions mattered here.

Categories are data, not a hard-coded list. In the spreadsheet, a few sample expenses used categories that didn't exist on the Budget sheet, so they silently never appeared on the dashboard. In the app, categories are rows in a table. If you delete one, its expenses become "Uncategorised" and still count towards totals (ON DELETE SET NULL).

Money is NUMERIC(14,2) with CHECK (amount >= 0). The pg driver returns NUMERIC as a string, so I register a type parser once:

const { types } = require('pg'); types.setTypeParser(1700, (v) => (v === null ? null : parseFloat(v))); // NUMERIC types.setTypeParser(20, (v) => (v === null ? null : parseInt(v, 10))); // COUNT types.setTypeParser(1082, (v) => v); // DATE stays 'YYYY-MM-DD', no timezone shifts 

Keeping DATE as a plain string avoids the classic bug where an expense logged on the 1st shows up on the 31st of the previous month for users in other timezones.

Porting the Excel formulas to SQL

The most interesting part was translating spreadsheet formulas into queries.

Week number. The workbook groups days 1–7 as Week 1, 8–14 as Week 2, and so on. In SQL that is integer division:

((EXTRACT(DAY FROM spent_on)::int - 1) / 7) + 1 AS week 

Weekly budget. Each week gets a share of the monthly budget proportional to its days, so a 2-day Week 5 doesn't look "under budget":

const budget = round2((totalBudget * w.days) / daysInMonth); 

Budget status. Each category is "On track", "Near limit" or "Over budget", depending on a configurable warning threshold (85% by default):

function budgetStatus(budget, actual, warn) { if (!budget) return actual > 0 ? 'over_nobudget' : 'none'; const pct = actual / budget; if (pct > 1) return 'over'; if (pct >= warn) return 'near'; return 'ok'; } 

All of this lives in one backend module (report.js), so the frontend only renders what the API returns. The calculation logic stays in one place and is easy to test.

Security basics

Even for a personal project I wanted the fundamentals covered:

  • Parameterised queries everywhere, so no SQL injection.
  • Passwords hashed with bcrypt, JWT sessions expire after 7 days.
  • Every query is filtered by user_id, so one account can never read or delete another's data. I tested this by trying to delete another user's expense and getting a 404.
  • Rate limiting on login and register.
  • CSV export neutralises formula injection. Cells starting with =, +, - or @ get a leading apostrophe so Excel doesn't execute them.
  • helmet for secure HTTP headers, and strict server-side validation for dates, amounts and ranges.

Dockerizing it

The whole app is three containers.

services: db: image: postgres:16-alpine volumes: [pgdata:/var/lib/postgresql/data] healthcheck: test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-expense}"] interval: 5s retries: 20 backend: build: ./backend depends_on: db: condition: service_healthy environment: DATABASE_URL: postgres://expense:expense@db:5432/expense_tracker JWT_SECRET: ${JWT_SECRET:-change-me-to-a-long-random-string} frontend: build: ./frontend depends_on: [backend] ports: ["3000:80"] volumes: pgdata: 

A few things worth noting:

  1. depends_on with service_healthy means the API only starts once Postgres actually accepts connections. The backend also retries for about a minute as a second safety net.
  2. Idempotent migrations. schema.sql uses CREATE TABLE IF NOT EXISTS and runs on every start, so there is no migration tool to install for a project this size.
  3. Multi-stage frontend build. Node compiles the React app, and only the static files get copied into a tiny nginx:alpine image.
  4. A named volume (pgdata) keeps your data across restarts. docker compose down -v wipes it.

The nginx config does two jobs: it proxies the API and falls back to index.html so client-side routes work on refresh:

location /api/ { proxy_pass http://backend:4000; } location / { try_files $uri $uri/ /index.html; } 

Run it locally

You only need Docker Desktop.

git clone https://github.com/YOUR_GITHUB_USERNAME/expense-tracker.git cd expense-tracker cp .env.example .env # optional: set a strong JWT_SECRET docker compose up --build 

Open http://localhost:3000 and sign in with the demo account (demo@example.com / demo12345), or create your own.

The first build takes a few minutes. After that, docker compose up starts in seconds.

Useful commands:

docker compose logs -f backend # API logs docker compose exec db psql -U expense expense_tracker # SQL shell docker compose exec db pg_dump -U expense expense_tracker > backup.sql docker compose down -v # reset all data 

How I tested it

I ran the API against a real PostgreSQL instance and checked the numbers by hand: category totals, weekly sums, week boundaries, and the savings maths. I also tested validation (invalid dates like Feb 30, unknown category IDs, missing tokens), cross-user isolation, and CSV escaping. Finally, I clicked through every page in a headless browser and watched the console for errors.

Pushing it to GitHub

git init git add . git commit -m "Initial commit: full-stack expense tracker" git branch -M main git remote add origin https://github.com/YOUR_GITHUB_USERNAME/expense-tracker.git git push -u origin main 

.env is in .gitignore, so your secrets never leave your machine. Only .env.example is committed.

What I'd add next

  • Automated tests (Jest for the API, Playwright for the UI)
  • Import from the original .xlsx file
  • Recurring expenses and monthly email summaries
  • Deploying a hosted demo (Render or Fly.io plus managed Postgres)
  • Dark/light theme toggle (it currently follows the OS setting)

Takeaways

  • Moving from a spreadsheet to a database forces you to define your rules (what counts as "over budget"?), and that clarity is half the value.
  • Doing the calculations in SQL and one backend module keeps the UI simple.
  • Docker Compose makes a three-tier app feel like a single command, which is great for portfolios because reviewers can actually run it.

I used an AI assistant (Claude) to help scaffold and iterate on parts of this project, and I reviewed and tested the result myself.

If you try it or have ideas, I'd love feedback. The repo is here: https://github.com/mubeen780/Expense-Tracker. A star helps a lot ⭐