Skip to content

divyanshrai1/Expense_tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

💰 Expense Tracker - Python CLI Application

A command-line expense tracking application built with Python that helps you manage your finances, analyze spending patterns, and generate beautiful visualizations.

Python SQLite Matplotlib License

🎯 Features

  • Add, View, and Delete Expenses - Full CRUD operations via command line
  • 📊 Spending Analysis - Category-wise breakdown with percentages
  • 📈 Data Visualization - Pie charts, bar charts, and trend graphs
  • 🗄️ SQLite Database - Persistent data storage with zero configuration
  • 🎨 Beautiful Terminal Output - Clean, formatted tables and reports
  • 📅 Date Filtering - View expenses by month, week, or custom periods
  • 💾 High-Quality Exports - Save charts as 300 DPI PNG images

🚀 Demo

Adding an Expense

python main.py add --amount 500 --category food --description "Lunch at restaurant"

Viewing Expenses

python main.py view

Analyzing Spending

python main.py analyze --period month

Creating Visualizations

python main.py visualize --type pie --period month

📁 Project Structure

expense-tracker/
├── main.py              # CLI interface and command routing
├── database.py          # SQLite database operations
├── analytics.py         # Data analysis and statistics
├── visualization.py     # Chart generation with Matplotlib
├── requirements.txt     # Project dependencies
└── README.md           # Documentation

Architecture

The application follows a modular design with separation of concerns:

  • main.py - Command-line interface using argparse
  • database.py - All SQLite operations (CREATE, INSERT, SELECT, DELETE)
  • analytics.py - Business logic for data analysis and calculations
  • visualization.py - Chart generation using Matplotlib

🛠️ Installation

Prerequisites

  • Python 3.7 or higher
  • pip (Python package manager)

Setup

  1. Clone the repository
git clone https://github.com/yourusername/expense-tracker.git
cd expense-tracker
  1. Install dependencies
pip install -r requirements.txt

Or install manually:

pip install matplotlib
  1. Run the application
python main.py --help

📖 Usage Guide

Add an Expense

# Basic usage
python main.py add --amount 500 --category food --description "Groceries"

# With custom date
python main.py add --amount 200 --category transport --date 2025-11-20

View Expenses

# View all expenses
python main.py view

# View expenses for specific month
python main.py view --month 11 --year 2025

Delete an Expense

python main.py delete --id 5

Analyze Spending

# Current month analysis
python main.py analyze --period month

# Last week analysis
python main.py analyze --period week

# All-time analysis
python main.py analyze --period all

Generate Visualizations

# Pie chart (spending distribution)
python main.py visualize --type pie --period month

# Trend chart (daily spending over time)
python main.py visualize --type trend --days 30

# Bar chart (category comparison)
python main.py visualize --type bar --period month

# Generate all charts
python main.py visualize --type all

Quick Summary

python main.py summary

Compare Periods

python main.py compare --period1 month --period2 week

🎨 Visualizations

The application generates three types of professional charts:

1. Pie Chart

Shows spending distribution across categories with percentages.

2. Trend Chart

Line graph displaying daily spending patterns over time.

3. Bar Chart

Category-wise comparison with labeled amounts.

All charts are:

  • Saved as high-resolution PNG files (300 DPI)
  • Color-coded for easy interpretation
  • Professionally formatted with titles and legends

💾 Database Schema

CREATE TABLE expenses (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    amount REAL NOT NULL,
    category TEXT NOT NULL,
    description TEXT,
    date TEXT NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

🧪 Example Workflow

# 1. Add some expenses
python main.py add --amount 300 --category food --description "Lunch"
python main.py add --amount 200 --category transport --description "Uber"
python main.py add --amount 1500 --category shopping --description "New clothes"

# 2. View all expenses
python main.py view

# 3. Analyze spending
python main.py analyze --period month

# 4. Generate visualizations
python main.py visualize --type pie
python main.py visualize --type trend --days 30

🔧 Technologies Used

Technology Purpose
Python 3.x Core programming language
SQLite Lightweight database (built-in)
Matplotlib Data visualization library
Argparse Command-line interface framework

📚 What I Learned

Building this project taught me:

  • 🗄️ Database Design - Creating schemas, writing SQL queries, managing data integrity
  • 📊 Data Analysis - Calculating statistics, grouping data, computing percentages
  • 🎨 Data Visualization - Creating professional charts with Matplotlib
  • 🏗️ Software Architecture - Modular design, separation of concerns
  • 🖥️ CLI Development - Building user-friendly command-line tools with argparse
  • 🐛 Error Handling - Validation, exception handling, user feedback

🚀 Future Enhancements

Planned features for future versions:

  • Budget limit alerts and notifications
  • Export data to Excel/CSV formats
  • Recurring expense tracking
  • Monthly PDF reports generation
  • Multi-currency support
  • Machine learning for spending predictions
  • Web dashboard interface
  • Mobile app integration

🤝 Contributing

Contributions are welcome! Feel free to:

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

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

👤 Author

Your Name

🙏 Acknowledgments

  • Python community for excellent documentation
  • Matplotlib developers for the powerful visualization library
  • Stack Overflow community for helpful discussions

📸 Screenshots

Terminal View

ID    Date         Category    Description              Amount
==========================================================================
1     2025-11-20   food        Lunch                    ₹300.00
2     2025-11-20   transport   Uber                     ₹200.00
3     2025-11-20   shopping    New clothes              ₹1,500.00
==========================================================================
TOTAL                                                   ₹2,000.00

Analysis Output

📊 SPENDING ANALYSIS (MONTH)
============================================================
Category            Amount        Percentage    Count
food                ₹500.00       25.0%        [2]
shopping            ₹1,500.00     75.0%        [1]
============================================================
TOTAL               ₹2,000.00

If you find this project helpful, please give it a star!


🐛 Known Issues

None at the moment. If you find any bugs, please open an issue!

📞 Support

If you have any questions or need help, feel free to:

  • Open an issue on GitHub
  • Reach out via email
  • Connect on LinkedIn

Made with ❤️ and Python

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages