Skip to content

Latest commit

Β 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 

Repository files navigation

πŸ’° AI-Powered Personal Expense Tracker

A full-stack, intelligent expense management system that combines a modern PHP web application with machine learning–driven category prediction, smart spending insights, and Apache Spark–powered big data analytics.

🌐 Live Demo Β Β·Β  πŸš€ Quick Start Β Β·Β  πŸ€– ML Pipeline Β Β·Β  ⚑ Spark Analytics


πŸ“‹ Table of Contents


πŸ” Overview

The AI-Powered Personal Expense Tracker is a comprehensive financial management application built as a major academic project. It goes far beyond basic CRUD operations, integrating a complete machine learning pipeline for automatic expense categorization and a distributed Apache Spark engine for large-scale spending analytics.

What Makes This Different?

Traditional Trackers This Project
Manual category selection AI auto-predicts category from description
Static reports Spark-powered real-time analytics & trend detection
Basic password login OTP-based authentication with rate limiting
No spending intelligence Smart Insights Engine with anomaly detection
Single-table summaries Multi-dimensional weekly/monthly/yearly trend analysis

✨ Key Features

🧠 AI & Machine Learning

  • Automatic Category Prediction β€” TF-IDF + Logistic Regression model predicts expense categories from text descriptions with high accuracy
  • Smart Spending Insights β€” Statistical anomaly detection using IQR method, trend analysis, and savings recommendations
  • Confidence Scoring β€” Each prediction returns probability scores across all 8 categories
  • Batch Prediction API β€” Process multiple expenses in a single API call

⚑ Big Data Analytics (Apache Spark)

  • Monthly Summary Aggregation β€” Per-user monthly totals, averages, min/max breakdowns
  • Category-wise Analysis β€” Spending distribution with percentage calculations using Spark window functions
  • Trend Detection β€” Weekly (ISO 8601), monthly, and yearly trend computation with daily burn rates
  • Spike Detection β€” Month-over-month spending surge alerts (>25% threshold)
  • End-of-Month Projections β€” Predictive spending forecasts based on current daily rate vs. last month
  • Weekend vs. Weekday Patterns β€” Spending habit analysis with actionable savings recommendations

πŸ“Š Financial Dashboard

  • Real-time Metrics β€” Total spending, average monthly, transaction count, top category
  • Interactive Charts β€” 7-day expense trends and category distribution (Chart.js)
  • Recent Transactions β€” Live feed with category badges and timestamps
  • Monthly Budget Tracking β€” Set per-category budgets with visual progress bars and overspend alerts

πŸ” Authentication & Security

  • Dual Login Modes β€” Traditional password + Email OTP (one-time password)
  • Guest Mode β€” Try the app without registration (localStorage-based)
  • Rate Limiting β€” Account lockout after 5 failed attempts (15-minute cooldown)
  • OTP Rate Limiting β€” Max 3 OTP requests per 10-minute window
  • Remember Me β€” Secure 30-day persistent sessions with hashed tokens
  • CSRF Protection β€” Token-based protection on all forms

πŸ’Ό Expense Management

  • Full CRUD operations β€” Add, edit, delete, search expenses
  • Advanced Filtering β€” By category, date range (today, week, month, year, custom), and search text
  • Sortable Columns β€” Click headers to sort by date or amount
  • Custom Categories β€” Create, edit, and color-code your own categories with icons
  • Notes Field β€” Add optional notes to any transaction

πŸ› οΈ Tech Stack

Backend

Technology Purpose
PHP 8.x Server-side logic, RESTful API
MySQL 8.0 Relational database (XAMPP)
Python 3.11 ML pipeline & Spark analytics
Flask 3.0 ML prediction REST API server
Apache Spark 3.5 Distributed data processing
PySpark Spark's Python API

Frontend

Technology Purpose
HTML5 / CSS3 Semantic markup, modern styling
Vanilla JavaScript Dashboard interactivity, AJAX calls
Chart.js Financial data visualization
Lucide Icons Consistent iconography

ML & Data Science

Library Purpose
scikit-learn Logistic Regression, TF-IDF, model evaluation
pandas / NumPy Data manipulation & analysis
matplotlib / seaborn EDA visualizations
WordCloud Text feature visualization

πŸ— System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                          CLIENT (Browser)                          β”‚
β”‚   Dashboard  β”‚  Expenses  β”‚  Categories  β”‚  Reports  β”‚  Spark UI  β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
       β”‚             β”‚            β”‚             β”‚            β”‚
       β–Ό             β–Ό            β–Ό             β–Ό            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        PHP REST API Layer                          β”‚
β”‚  auth.php β”‚ expenses.php β”‚ categories.php β”‚ budget.php β”‚ spark_.phpβ”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
       β”‚           β”‚               β”‚              β”‚            β”‚
       β–Ό           β–Ό               β–Ό              β–Ό            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   MySQL DB   β”‚ β”‚  Flask ML API      β”‚ β”‚  Apache Spark Engine     β”‚
β”‚              β”‚ β”‚  (:5000)           β”‚ β”‚  (PySpark + JDBC)        β”‚
β”‚  β€’ users     β”‚ β”‚  β€’ /predict        β”‚ β”‚  β€’ Monthly Summary       β”‚
β”‚  β€’ expenses  β”‚ β”‚  β€’ /predict/batch  β”‚ β”‚  β€’ Category Summary      β”‚
β”‚  β€’ categoriesβ”‚ β”‚  β€’ /insights       β”‚ β”‚  β€’ Trend Analysis        β”‚
β”‚  β€’ budgets   β”‚ β”‚  β€’ /health         β”‚ β”‚  β€’ Smart Insights        β”‚
β”‚  β€’ spark_*   β”‚ β”‚                    β”‚ β”‚  β€’ Recommendations       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          β”‚                         β”‚
                          β–Ό                         β”‚
                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                β”‚
                 β”‚  Trained Models β”‚                 β”‚
                 β”‚  (.pkl files)   β”‚β—„β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚  β€’ category_modelβ”‚        (reads MySQL via JDBC,
                 β”‚  β€’ tfidf_vectorizerβ”‚       writes summaries back)
                 β”‚  β€’ scaler        β”‚
                 β”‚  β€’ label_encoder β”‚
                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Prerequisites

1. Clone & Setup

git clone https://github.com/Unknown-user-555/expense-tracker.git
# Place in your XAMPP htdocs directory as 'personal_expense'

2. Database Setup

Open phpMyAdmin (http://localhost/phpmyadmin) and run:

-- Create database and tables
SOURCE C:/xampp/htdocs/personal_expense/database/schema.sql;

-- Run auth migration (adds OTP + rate limiting columns)
SOURCE C:/xampp/htdocs/personal_expense/database/migrate_auth.sql;

-- Add Spark analytics tables
SOURCE C:/xampp/htdocs/personal_expense/database/spark_tables.sql;

Or import each SQL file via phpMyAdmin's Import tab.

3. Configure Database

Edit config/database.php if your MySQL credentials differ:

define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', '');  // Your MySQL password
define('DB_NAME', 'personal_expense_tracker');

4. Install ML Dependencies

cd ml
pip install -r requirements.txt

5. Train the ML Model

python expense_ai.py

This will:

  • Load and merge the 602-record training dataset
  • Perform exploratory data analysis with 8 visualizations
  • Train a Logistic Regression model with TF-IDF features
  • Run 5-fold cross-validation and regularization analysis
  • Save 4 .pkl model files to ml/models/

6. Start the Prediction API

python predict_api.py
# Server starts at http://localhost:5000

7. Launch the App

  1. Start Apache and MySQL from XAMPP Control Panel
  2. Navigate to: http://localhost/personal_expense

πŸ€– ML Pipeline

Model Architecture

Input: (description: str, amount: float)
  β”‚
  β”œβ”€β”€ Text Branch ──► TF-IDF Vectorizer (500 features, 1-2 ngrams)
  β”‚                    └── Sublinear TF scaling, English stop words removed
  β”‚
  └── Numeric Branch β–Ί StandardScaler (z-score normalization)
  β”‚
  β–Ό
scipy.sparse.hstack β†’ Combined Feature Matrix (501 features)
  β”‚
  β–Ό
Logistic Regression (multinomial, L-BFGS solver, C=1.0)
  β”‚
  β–Ό
Output: Predicted Category + Confidence Scores (8 classes)

Training Details

Parameter Value
Dataset 602 expense records across 8 categories
Features TF-IDF text (500) + normalized amount (1)
Model Logistic Regression (multinomial)
Train/Test Split 80% / 20% (stratified)
Solver L-BFGS with max 1000 iterations
Cross-Validation 5-fold Stratified K-Fold
Regularization C=1.0 (analyzed across [0.01, 0.1, 0.5, 1.0, 5.0, 10.0])

Categories Predicted

# Category Description
1 🍽️ Food & Dining Restaurants, groceries, food delivery
2 πŸš— Transportation Uber, fuel, public transit
3 πŸ›οΈ Shopping Clothing, electronics, online orders
4 🎬 Entertainment Movies, subscriptions, events
5 πŸ“„ Bills & Utilities Electricity, internet, phone bills
6 πŸ₯ Healthcare Pharmacy, doctor visits, insurance
7 πŸ“š Education Tuition, books, courses
8 🏷️ Other Miscellaneous expenses

EDA Visualizations Generated

The pipeline generates 8 publication-quality visualizations during training:

Visualization Description
class_distribution.png Bar chart of expense category distribution
word_cloud.png Word cloud from expense descriptions
amount_distribution.png Box plot of amounts per category
monthly_spending.png Monthly spending trend with area fill
spending_trends.png Stacked bar β€” monthly spending by category
category_pie.png Donut chart of total spending distribution
confusion_matrix.png Heatmap of model prediction performance
cross_validation.png CV scores + regularization analysis

Model Artifacts

After training, 4 serialized model files are saved to ml/models/:

File Purpose
category_model.pkl Trained Logistic Regression classifier
tfidf_vectorizer.pkl Fitted TF-IDF vectorizer (vocabulary)
scaler.pkl Fitted StandardScaler (mean, std)
label_encoder.pkl Category label ↔ integer mapping

Smart Insights Engine

The SmartInsightsEngine class (ml/smart_insights.py) performs 7 types of statistical analysis:

  1. High Spending Alerts β€” Flags categories >1.5Οƒ above mean
  2. Unusual Transaction Detection β€” IQR-based outlier detection per category
  3. Monthly Trend Analysis β€” Detects rising/falling spending patterns
  4. Category Dominance β€” Alerts when a single category exceeds 30% of total
  5. Weekend vs. Weekday Patterns β€” Compares average daily spending
  6. Savings Recommendations β€” Suggests 10–20% reductions on discretionary categories
  7. Spending Velocity β€” Monitors transaction frequency for impulse detection

⚑ Apache Spark Analytics

Overview

The Spark module (spark/spark_analytics.py) connects to the MySQL database via JDBC, ingests raw expense data into distributed DataFrames, and computes 5 types of analytics which are written back to dedicated summary tables.

Setup

  1. Install PySpark:

    cd spark
    pip install -r requirements.txt
  2. Download MySQL JDBC driver:

    • Get mysql-connector-j-8.x.x.jar from MySQL Downloads
    • Place in Spark's jars/ directory or specify via --jars flag
  3. Run the pipeline:

    spark-submit --jars <path-to-mysql-connector-j.jar> spark_analytics.py

    Or use the convenience script:

    run_spark.bat

Analytics Computed

1. Monthly Summary (monthly_summary table)

  • Per-user monthly aggregation: total, average, min, max, transaction count
  • Uses Spark UDFs for month name mapping

2. Category Summary (category_summary table)

  • Category-wise spending per user per month
  • Window functions calculate percentage share within each user-month

3. Trend Summary (trend_summary table)

  • Weekly: ISO 8601 week-based trends (last 12 weeks) with date range labels
  • Monthly: Calendar month trends (last 12 months)
  • Yearly: Full calendar year comparisons
  • Includes average daily burn rate at each granularity

4. Smart Insights (spark_insights table)

  • Spending Spike Detection β€” Compares current month vs. previous month per category; alerts on >25% increases with severity levels (warning at 25%+, critical at 75%+)
  • End-of-Month Projection β€” Projects total spending from daily burn rate and compares against last month's actual total

5. Smart Recommendations (spark_recommendations table)

  • Category Optimization β€” Identifies highest growth category and suggests capped budgets (110% of last month)
  • Weekend vs. Weekday Pattern β€” Analyzes spending ratio and estimates monthly savings potential

Spark Architecture

MySQL (XAMPP)                Apache Spark (local[*])
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    JDBC     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  expenses  │────────────►│  DataFrame: expenses_df   β”‚
β”‚  categories│────────────►│  DataFrame: categories_df β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜             β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                       β”‚
                           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                           β”‚   Spark Transformations   β”‚
                           β”‚   β€’ groupBy / agg         β”‚
                           β”‚   β€’ Window functions      β”‚
                           β”‚   β€’ UDFs                  β”‚
                           β”‚   β€’ Joins                 β”‚
                           β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                       β”‚
                           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
MySQL (XAMPP)    JDBC       β”‚   Computed DataFrames     β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β—„β”€β”€β”€β”€β”€β”€β”€β”€β”‚   β€’ monthly_summary       β”‚
β”‚ monthly_summaryβ”‚         β”‚   β€’ category_summary      β”‚
β”‚ category_summaryβ”‚        β”‚   β€’ trend_summary         β”‚
β”‚ trend_summary  β”‚         β”‚   β€’ spark_insights        β”‚
β”‚ spark_insights β”‚         β”‚   β€’ spark_recommendations β”‚
β”‚ spark_recommen.β”‚         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ” Authentication System

The application supports three authentication modes:

1. Password Login

Traditional email + password authentication with:

  • bcrypt password hashing (PASSWORD_DEFAULT)
  • Brute-force protection β€” 5 failed attempts β†’ 15-minute lockout
  • Remember Me β€” 30-day persistent session using SHA-256 hashed tokens

2. Email OTP Login

Passwordless authentication flow:

  1. User enters email β†’ system generates 6-digit OTP
  2. OTP is hashed with bcrypt and stored in the database
  3. OTP expires after a configurable window (default: 10 minutes)
  4. Rate limited to 3 sends per 10-minute window

3. Guest Mode

  • No registration required
  • Data stored in localStorage (browser-only)
  • Full dashboard access with limited features
  • Seamless upgrade path to registered account

πŸ“‘ API Reference

Authentication Endpoints

Method Endpoint Description
POST /api/auth.php?action=signup Register new user
POST /api/auth.php?action=login Password login
POST /api/auth.php?action=send_otp Send OTP to email
POST /api/auth.php?action=verify_otp Verify OTP & login
POST /api/auth.php?action=resend_otp Resend OTP
GET /api/auth.php?action=logout Logout & clear session
GET /api/auth.php?action=guest Activate guest mode

Expense Endpoints

Method Endpoint Description
GET /api/expenses.php Get all expenses (with filters)
POST /api/expenses.php Create new expense
PUT /api/expenses.php?id={id} Update expense
DELETE /api/expenses.php?id={id} Delete expense

Category Endpoints

Method Endpoint Description
GET /api/categories.php List all categories
POST /api/categories.php Create category
PUT /api/categories.php?id={id} Update category
DELETE /api/categories.php?id={id} Delete category

Budget Endpoints

Method Endpoint Description
GET /api/budget.php Get budget data
POST /api/budget.php Set / update budget

ML Prediction API (Flask β€” Port 5000)

Method Endpoint Description
GET /health Health check & model info
POST /predict Predict category (single)
POST /predict/batch Batch category prediction
GET /insights Demo insights (training data)
POST /insights Custom data insights

Example: Predict Category

curl -X POST http://localhost:5000/predict \
  -H "Content-Type: application/json" \
  -d '{"description": "swiggy lunch", "amount": 350}'
{
  "predicted_category": "Food",
  "confidence": 0.9234,
  "all_probabilities": {
    "Food": 0.9234,
    "Shopping": 0.0312,
    "Entertainment": 0.0198,
    "...": "..."
  }
}

Spark Analytics Endpoints (PHP)

Method Endpoint Description
GET /api/spark_summary.php?type=monthly Monthly aggregated data
GET /api/spark_summary.php?type=category Category breakdown
GET /api/spark_summary.php?type=trends Spending trends
GET /api/spark_summary.php?type=insights Spark-generated insights
GET /api/spark_summary.php?type=recommendations Smart recommendations

πŸ—„ Database Schema

Core Tables

users           β€” User accounts with OTP & rate-limit fields
β”œβ”€β”€ id, username, email, password
β”œβ”€β”€ otp_code, otp_expires_at, otp_attempts, otp_last_sent_at
β”œβ”€β”€ login_attempts, login_locked_until
└── remember_token, remember_expires_at

categories      β€” User-defined expense categories
β”œβ”€β”€ id, user_id (FK), name, color, icon
└── budget (per-category monthly budget)

expenses        β€” Individual expense transactions
β”œβ”€β”€ id, user_id (FK), category_id (FK)
β”œβ”€β”€ amount, description, notes
└── expense_date, created_at, updated_at

Spark-Generated Tables

monthly_summary       β€” Monthly totals per user
category_summary      β€” Category-wise spending per user/month
trend_summary         β€” Weekly/monthly/yearly trends
spark_insights        β€” AI-generated spending insights
spark_recommendations β€” Personalized savings recommendations

πŸ“‚ Project Structure

expense-tracker/
β”‚
β”œβ”€β”€ api/                          # RESTful API endpoints (PHP)
β”‚   β”œβ”€β”€ auth.php                  # Authentication (signup, login, OTP, guest)
β”‚   β”œβ”€β”€ expenses.php              # Expense CRUD operations
β”‚   β”œβ”€β”€ categories.php            # Category management
β”‚   β”œβ”€β”€ budget.php                # Budget management
β”‚   β”œβ”€β”€ budget_alerts.php         # Budget overspend alerts
β”‚   β”œβ”€β”€ ml_suggestions.php        # ML-powered suggestions (PHP β†’ Flask bridge)
β”‚   β”œβ”€β”€ predict_category.php      # Category prediction proxy
β”‚   └── spark_summary.php         # Spark analytics data API
β”‚
β”œβ”€β”€ assets/
β”‚   β”œβ”€β”€ css/                      # Stylesheets
β”‚   β”‚   β”œβ”€β”€ style.css             # Global styles (Shadcn-inspired design system)
β”‚   β”‚   β”œβ”€β”€ auth.css              # Authentication pages
β”‚   β”‚   β”œβ”€β”€ dashboard.css         # Dashboard layout
β”‚   β”‚   β”œβ”€β”€ expenses.css          # Expense management
β”‚   β”‚   β”œβ”€β”€ categories.css        # Category management
β”‚   β”‚   β”œβ”€β”€ reports.css           # Reports page
β”‚   β”‚   └── spark_analytics.css   # Spark analytics UI
β”‚   └── js/                       # Client-side JavaScript
β”‚       β”œβ”€β”€ dashboard.js          # Dashboard logic & charts
β”‚       β”œβ”€β”€ expenses.js           # Expense CRUD & filtering
β”‚       β”œβ”€β”€ categories.js         # Category management
β”‚       β”œβ”€β”€ reports.js            # Reports & visualizations
β”‚       β”œβ”€β”€ guest.js              # Guest mode (localStorage)
β”‚       β”œβ”€β”€ spark_analytics.js    # Spark analytics UI
β”‚       β”œβ”€β”€ main.js               # Shared utilities
β”‚       └── theme.js              # Dark/light theme toggle
β”‚
β”œβ”€β”€ config/                       # Server configuration
β”‚   β”œβ”€β”€ database.php              # MySQL connection (PDO)
β”‚   β”œβ”€β”€ session.php               # Session management & auth helpers
β”‚   β”œβ”€β”€ mail.php                  # Email (OTP delivery) configuration
β”‚   └── sidebar.php               # Shared navigation sidebar component
β”‚
β”œβ”€β”€ database/                     # SQL schema & migrations
β”‚   β”œβ”€β”€ schema.sql                # Base schema (users, categories, expenses)
β”‚   β”œβ”€β”€ migrate_auth.sql          # OTP & rate-limiting columns
β”‚   β”œβ”€β”€ spark_tables.sql          # Spark analytics summary tables
β”‚   β”œβ”€β”€ add_budget_column.sql     # Budget field migration
β”‚   β”œβ”€β”€ add_budget_alerts.sql     # Alert tables
β”‚   β”œβ”€β”€ add_notes_column.sql      # Notes field migration
β”‚   β”œβ”€β”€ complete_update.sql       # Consolidated migration
β”‚   └── import_csv_data.sql       # Sample data import
β”‚
β”œβ”€β”€ ml/                           # Machine Learning module
β”‚   β”œβ”€β”€ expense_ai.py             # Full ML pipeline (EDA β†’ Train β†’ Evaluate β†’ Save)
β”‚   β”œβ”€β”€ predict_api.py            # Flask REST API for predictions
β”‚   β”œβ”€β”€ smart_insights.py         # Statistical insights engine (7 analysis types)
β”‚   β”œβ”€β”€ requirements.txt          # Python dependencies
β”‚   β”œβ”€β”€ dataset/                  # Training data
β”‚   β”‚   β”œβ”€β”€ expense_dataset1.csv  # 302 records
β”‚   β”‚   └── expense_dataset2.csv  # 300 records
β”‚   β”œβ”€β”€ models/                   # Serialized trained models
β”‚   β”‚   β”œβ”€β”€ category_model.pkl
β”‚   β”‚   β”œβ”€β”€ tfidf_vectorizer.pkl
β”‚   β”‚   β”œβ”€β”€ scaler.pkl
β”‚   β”‚   └── label_encoder.pkl
β”‚   └── visualizations/           # Generated EDA charts (8 plots)
β”‚
β”œβ”€β”€ spark/                        # Apache Spark analytics module
β”‚   β”œβ”€β”€ spark_analytics.py        # Main Spark pipeline (5 analytics)
β”‚   β”œβ”€β”€ generate_sample_data.py   # Test data generator
β”‚   β”œβ”€β”€ run_spark.bat             # Windows launch script
β”‚   └── requirements.txt          # PySpark dependencies
β”‚
β”œβ”€β”€ index.php                     # Login page (split-screen UI)
β”œβ”€β”€ signup.php                    # Registration page
β”œβ”€β”€ dashboard.php                 # Main dashboard
β”œβ”€β”€ expenses.php                  # Expense management page
β”œβ”€β”€ categories.php                # Category management page
β”œβ”€β”€ reports.php                   # Reports & analytics page
β”œβ”€β”€ spark_analytics.php           # Spark analytics dashboard
β”œβ”€β”€ migrate_account.php           # Account migration utility
β”‚
β”œβ”€β”€ Dockerfile                    # Docker deployment config
β”œβ”€β”€ .htaccess                     # Apache URL rewriting
β”œβ”€β”€ LICENSE                       # MIT License
└── README.md                     # This file

πŸ”’ Security

Feature Implementation
Password Hashing bcrypt via password_hash() (cost factor 10)
SQL Injection Prevention Prepared statements on all queries
XSS Protection Output escaping with htmlspecialchars()
CSRF Protection Token-based validation on forms
Session Security Secure session configuration, regeneration on login
Rate Limiting Login (5 attempts / 15-min lock), OTP (3 sends / 10-min window)
OTP Security Hashed storage (bcrypt), configurable expiry, auto-invalidation
Remember Me SHA-256 hashed tokens with 30-day expiry
Input Validation Server-side + client-side validation on all inputs

πŸ“Έ Screenshots

The application features a modern, dark-themed UI inspired by Shadcn design principles with glassmorphism effects, smooth animations, and responsive layouts.

Pages

Page Description
Login Split-screen layout with password + OTP tabs
Dashboard Financial overview with charts, metrics, and AI insights
Expenses Searchable, filterable transaction table with inline editing
Categories Color-coded category cards with budget progress bars
Reports Date-range reports with exportable charts
Spark Analytics Big data insights dashboard with trend visualizations

πŸ›£οΈ Roadmap

  • Core expense CRUD with categories
  • Interactive dashboard with Chart.js
  • ML-based category prediction
  • Smart spending insights engine
  • Apache Spark analytics pipeline
  • OTP-based authentication
  • Guest mode with localStorage
  • Monthly budget management
  • Dark/light theme toggle
  • Recurring expenses
  • Export to CSV / PDF
  • Multi-currency support
  • Mobile-responsive PWA
  • Receipt OCR scanning

πŸ“„ License

This project is licensed under the MIT License β€” see the LICENSE file for details.


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

Built with ❀️ as a major academic project β€” combining full-stack web development, machine learning, and big data analytics.

If you found this useful, consider giving it a ⭐

About

A web-based expense tracker to manage daily spending

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors