Skip to content

Repository files navigation

πŸ’° Personal Expense Tracker

A full-stack web application to analyze and categorize monthly expenses from bank statements (CSV & PDF) with intelligent auto-categorization.

Python Flask Pandas License

🎯 Problem Statement

Managing personal finances is challenging when bank statements are just raw transaction data. This app transforms messy CSV exports and PDF bank statements into actionable insights by:

  • Automatically categorizing transactions using pattern matching (170+ merchant rules)
  • Extracting transactions from PDF bank statements (ICICI, HDFC, SBI, etc.)
  • Learning user preferences over time
  • Providing clear salary vs. spending analysis

✨ Features

Feature Description
πŸ“€ CSV Upload Upload any bank statement CSV
πŸ“„ PDF Upload Extract transactions from PDF bank statements
πŸ€– Auto-Categorization Rule-based engine with 170+ merchant rules
🧠 Learning System Remembers user categorizations for future transactions
πŸ“Š Dashboard Visual summary of income, expenses, and balance
✏️ Inline Editing Change categories with instant save
πŸ’΅ Credit Tracking Track money received from others

πŸ› οΈ Tech Stack

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      FRONTEND                           β”‚
β”‚  HTML5 β€’ CSS3 β€’ Responsive Design β€’ Dynamic Templates  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                      BACKEND                            β”‚
β”‚  Python 3 β€’ Flask β€’ Pandas β€’ RESTful Routes            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                    DATA LAYER                           β”‚
β”‚  CSV Parsing β€’ PDF Extraction β€’ Regex Matching β€’ JSON  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Core Technologies

  • Python 3.8+ - Core programming language
  • Flask - Lightweight WSGI web framework
  • Pandas - Data manipulation and analysis
  • pdfplumber - PDF text extraction
  • camelot-py - PDF table extraction (stream mode)
  • Gunicorn - Production WSGI HTTP server
  • HTML5/CSS3 - Responsive UI with modern gradients

πŸ—οΈ Architecture

expense-tracker/
β”œβ”€β”€ webapp.py              # Main Flask application (1400+ lines)
β”‚   β”œβ”€β”€ Routes             # 8 API endpoints
β”‚   β”œβ”€β”€ Data Processing    # CSV parsing, PDF extraction, categorization
β”‚   └── Template Rendering # Dynamic HTML generation
β”œβ”€β”€ create_sample_pdf.py   # Generate sample PDF for testing
β”œβ”€β”€ test_pdf_processing.py # PDF extraction tests
β”œβ”€β”€ sample_statement.csv   # Sample CSV bank statement
β”œβ”€β”€ user_mappings.json     # Persistent learned mappings (JSON)
β”œβ”€β”€ uploads/               # Temporary file storage (git-ignored)
β”œβ”€β”€ requirements.txt       # Python dependencies
β”œβ”€β”€ Procfile              # Production deployment config
└── README.md

Key Components

1. Auto-Categorization Engine

GLOBAL_RULES = {
    'SWIGGY': 'Food', 'ZOMATO': 'Food', 'HUNGERBOX': 'Food',
    'AMAZON': 'Shopping', 'FLIPKART': 'Shopping', 'MYNTRA': 'Shopping',
    'UBER': 'Transport', 'OLA': 'Transport', 'RAPIDO': 'Transport',
    'ZERODHA': 'Investments', 'GROWW': 'Investments',
    'BOOKMYSHOW': 'Entertainment', 'NETFLIX': 'Entertainment',
    'BIGBASKET': 'Groceries', 'BLINKIT': 'Groceries',
    # 170+ merchant rules across 12 categories
}

2. PDF Extraction Pipeline

  • Camelot (stream mode) - Extracts tabular data from PDF bank statements
  • pdfplumber (fallback) - Text-based extraction when table detection fails
  • Handles multi-row headers, merged columns, and multi-line transactions
  • Supports date formats: DD/MM/YYYY, DD-MM-YYYY, DD.MM.YYYY
  • Deduplication to handle overlapping page extractions

3. Learning System

  • Stores user corrections in JSON
  • Prioritizes learned mappings over global rules
  • Persists across sessions

4. Smart Detection

  • Auto-detects salary (credits > β‚Ή50,000)
  • Identifies auto/transport transactions by amount patterns
  • Calculates overspending and net balance

πŸš€ Quick Start

Clone & Run Locally

# Clone the repository
git clone https://github.com/harininaik/expense-tracker.git
cd expense-tracker

# Install dependencies
pip install -r requirements.txt

# Run the application
python webapp.py

# Open in browser
# http://127.0.0.1:5000

πŸ“Š API Endpoints

Method Endpoint Description
GET / Dashboard with expense summary
GET /transactions All transactions with inline editing
GET /mappings View/edit saved category mappings
GET /upload Upload page for new CSV/PDF
POST /upload Process uploaded CSV or PDF file
POST /categorize Batch save new categorizations
POST /update_mapping Update single mapping
GET /delete_mapping/<name> Remove a mapping

πŸ“ Supported File Formats

PDF Bank Statements

Upload your bank statement PDF directly β€” the app extracts transactions automatically.

Supported banks: ICICI, HDFC, SBI, Axis, Kotak, and most Indian banks with tabular PDF statements.

How it works:

  1. Camelot (stream mode) detects table structure in the PDF
  2. Multi-row headers are scanned and mapped to standard columns
  3. Multi-line transactions are merged (UPI/NEFT/IMPS descriptions)
  4. Duplicate rows from overlapping pages are removed
  5. Falls back to pdfplumber if Camelot finds no tables

CSV Format Guide

Required Format

Your bank statement CSV must have these columns in this order:

Column 1 Column 2 Column 3 Column 4 Column 5 Column 6 Column 7
Date Date Description - Debit Credit Balance

Example CSV File

Date,Date,Description,-,Debit,Credit,Balance
28/01/2026,28/01/2026,UPI/CR/123456789/SALARY/COMPANY NAME/REF123,-,-,93260.00,93260.00
28/01/2026,28/01/2026,UPI/DR/987654321/SWIGGY/SWIGGY/Payment for order,-,450.00,-,92810.00
29/01/2026,29/01/2026,UPI/DR/456789123/AMAZON/Amazon Pay/Shopping,-,1299.00,-,91511.00
29/01/2026,29/01/2026,UPI/DR/789123456/RAPIDO/Rapido/Ride payment,-,85.00,-,91426.00
30/01/2026,30/01/2026,UPI/CR/321654987/FRIEND NAME/Payment received,-,-,500.00,91926.00
30/01/2026,30/01/2026,UPI/DR/654987321/ZEPTO/Zepto/Groceries,-,320.00,-,91606.00

How to Get Your CSV

PhonePe:

  1. Open PhonePe β†’ Profile β†’ Transaction History
  2. Click "Download Statement" β†’ Select date range
  3. Download as CSV

Google Pay:

  1. Open Google Pay β†’ Tap profile picture
  2. Go to "Transaction history" β†’ Export
  3. Download CSV file

Bank Apps (HDFC, ICICI, SBI, etc.):

  1. Login to net banking
  2. Go to Accounts β†’ Statement
  3. Select date range β†’ Download as CSV

Important Notes

  • Date format: DD/MM/YYYY (e.g., 28/01/2026)
  • Debit = Money spent (outgoing)
  • Credit = Money received (incoming)
  • Use - for empty debit/credit fields
  • Description should contain merchant/person name

πŸ“„ See sample_statement.csv for a complete working example!

Compatible with: PhonePe, Google Pay, Paytm, HDFC, ICICI, SBI, Axis Bank, Kotak

🎨 Screenshots

Dashboard View

  • Summary Cards - Salary, Spent, Overspent, From Others, Balance
  • Category Breakdown - Visual spending by category with percentages
  • Credits Section - Money received from others
  • Quick Categorize - Dropdowns for uncategorized transactions

Expense Categories

Rent Food Groceries Shopping Transport Entertainment Investments Family Friends Maid/Cook Travel Others

πŸ”§ Configuration

Add Merchant Rules

# webapp.py - GLOBAL_RULES dictionary
GLOBAL_RULES = {
    'NEW_MERCHANT': 'Category',
}

Modify Categories

# webapp.py - CATEGORIES list
CATEGORIES = [
    "Rent", "Food", "NewCategory",
]

Adjust Salary Threshold

# webapp.py - Line 195
salary = df[df['Credit'] > 50000]['Credit'].sum()  # Change 50000

πŸ“ˆ Future Roadmap

  • πŸ“Š Monthly comparison charts (Chart.js)
  • πŸ”” Budget alerts and spending limits
  • πŸ“± Progressive Web App (PWA)
  • πŸ” User authentication (Flask-Login)
  • πŸ“€ Export to PDF/Excel
  • 🏦 Direct bank API integration
  • 🏦 Support more bank PDF formats

🀝 Contributing

Contributions are welcome! Here's how:

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/NewFeature)
  3. Commit changes (git commit -m 'Add NewFeature')
  4. Push to branch (git push origin feature/NewFeature)
  5. Open a Pull Request

πŸ“„ License

Distributed under the MIT License. See LICENSE for more information.

πŸ‘©β€πŸ’» Author

Harini Naik

GitHub


Built with Python & Flask
Made with ❀️ for better personal finance management

⭐ Star this repo if you found it helpful!

About

Personal Expense Tracker - Flask Web App

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages