Skip to content

Latest commit

Β 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

BudgetPe πŸ’°

AI-Powered Expense Tracking via SMS Classification

Track your spending automatically. Your bank sends SMS β†’ We classify it β†’ You see insights.


✨ What's Fixed & Working βœ…

βœ… Complete end-to-end SMS classification flow βœ… Backend properly stores messages with ML classification βœ… ML Model with intelligent 3-level classification hierarchy βœ… SMS App captures and sends message data correctly βœ… Frontend displays classified expenses with reports βœ… Comprehensive documentation and setup guides


πŸš€ Quick Start (5 Minutes)

Prerequisites

  • Node.js 18+
  • Python 3.8+
  • MongoDB (local or Atlas)

Run All Services

# Terminal 1: Backend
cd Backend && npm install && npm run dev

# Terminal 2: ML Model
cd "ML model" && python -m venv venv && source venv/Scripts/activate
pip install -r requirements.txt && python app.py

# Terminal 3: Frontend
cd frontend && npm install && npm run dev

# Terminal 4: SMS App (Android)
cd smsApp && npm install && npx expo start

Then:

  1. Open http://localhost:5173
  2. Register/Login
  3. Open SMS App on phone
  4. Send a bank SMS
  5. See it appear in dashboard instantly! ⚑

πŸ“± The Flow

πŸ“² Bank SMS arrives on phone
   ↓ (app polls every 3 sec)
πŸ“± SMS App captures SMS + sender info
   ↓
πŸ€– ML Model classifies β†’ Food/Travel/Shopping/Others
   ↓
πŸ’Ύ Backend stores in MongoDB with user association
   ↓
🌐 Frontend fetches and displays with analysis
   ↓
πŸ“Š User clicks "Generate Report" β†’ See insights & chart

πŸ“š Documentation Guide

Document Purpose Read Time
QUICKSTART.md Get running in 5 minutes 2 min
SETUP.md Complete setup & troubleshooting 10 min
ARCHITECTURE.md System design & data flow diagrams 15 min
INTEGRATION_CHECKLIST.md Verify everything works 5 min
FIX_SUMMARY.md What was fixed & why 5 min

πŸ‘‰ START HERE: QUICKSTART.md


πŸ—οΈ Project Structure

BudgetPe/
β”œβ”€β”€ Backend/                    # Node.js + Express API (port 5000)
β”‚   β”œβ”€β”€ models/                 # MongoDB schemas
β”‚   β”œβ”€β”€ controllers/            # Route handlers
β”‚   β”œβ”€β”€ routes/                 # API endpoints
β”‚   β”œβ”€β”€ middleware/             # Auth, validation, errors
β”‚   β”œβ”€β”€ validators/             # Request validation
β”‚   β”œβ”€β”€ config/                 # Database config
β”‚   └── .env                    # Configuration
β”‚
β”œβ”€β”€ frontend/                   # React + Vite (port 5173)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ routes/            # Pages (Dashboard, Login, etc)
β”‚   β”‚   β”œβ”€β”€ components/        # Reusable UI components
β”‚   β”‚   β”œβ”€β”€ context/           # Theme context
β”‚   β”‚   β”œβ”€β”€ utils/             # API & auth utilities
β”‚   β”‚   └── App.jsx
β”‚   └── .env
β”‚
β”œβ”€β”€ smsApp/                     # React Native + Expo (Android)
β”‚   β”œβ”€β”€ app/                   # Screens & navigation
β”‚   β”œβ”€β”€ components/            # Reusable components
β”‚   β”œβ”€β”€ context/              # Auth context
β”‚   β”œβ”€β”€ lib/                  # API integration
β”‚   └── lib/api.ts            # Backend/ML API calls
β”‚
β”œβ”€β”€ ML model/                   # Python (port 5001)
β”‚   β”œβ”€β”€ app.py                # Flask API server
β”‚   β”œβ”€β”€ model.py              # ML model loading
β”‚   β”œβ”€β”€ pipeline.py           # Classification pipeline
β”‚   β”œβ”€β”€ utils.py              # Utilities
β”‚   β”œβ”€β”€ train.py              # Model training script
β”‚   β”œβ”€β”€ data/                 # Model & training data
β”‚   └── requirements.txt
β”‚
└── Documentation/
    β”œβ”€β”€ QUICKSTART.md         # Quick reference
    β”œβ”€β”€ SETUP.md             # Detailed setup
    β”œβ”€β”€ ARCHITECTURE.md      # System architecture
    β”œβ”€β”€ INTEGRATION_CHECKLIST.md
    └── FIX_SUMMARY.md

🎯 Classification Logic (How It Works)

3-Level Hierarchy (Smart & Reliable)

πŸ₯‡ Level 1: Rule-Based Classification (Instant & Fast)

  • Checks for known merchant keywords
  • Food: Swiggy, Zomato, Eats, Food, Restaurant
  • Travel: Uber, Ola, Rapido, Taxi, Cab, Auto, Travel
  • Shopping: Amazon, Flipkart, Myntra, eBay, Shop, Store
  • Returns immediately if match found

πŸ₯ˆ Level 2: ML Model (If Rule Failed - Most Accurate)

  • Uses trained LogisticRegression model
  • Analyzes:
    • Merchant name (TF-IDF vectorized)
    • Transaction amount
    • Time of transaction (hour)
  • Trained on bank SMS dataset
  • Returns prediction

πŸ₯‰ Level 3: Fallback Heuristics (Always Works)

  • If ML model unavailable or unsure
  • Uses amount + time patterns:
    • β‚Ή ≀ 300 AND 6-11 PM β†’ Food
    • β‚Ή 50-500 β†’ Travel
    • β‚Ή > 500 β†’ Shopping
    • Otherwise β†’ Others

Result: Reliable classification even if ML model fails! βœ…


πŸ’Ύ What Gets Stored

User

{
  _id: ObjectId,
  name: "Mukul",
  email: "mukul@example.com",
  phoneNumber: "9876543210",
  password: "hashed_with_bcrypt",
  createdAt: Date,
  updatedAt: Date
}

Message (What ML Model Classifies)

{
  _id: ObjectId,
  user: ObjectId,              // Linked to user
  originalText: "Debited Rs. 500 to Swiggy...",  // Raw SMS
  category: "food",            // ML classification
  amount: 500,                 // Extracted amount
  receiver: "Swiggy",          // Merchant name
  date: Date,                  // Transaction time
  confidence: 1.0,             // Classification confidence
  createdAt: Date,
  updatedAt: Date
}

πŸ” Security Features

  • βœ… Passwords hashed with bcrypt (12 rounds)
  • βœ… JWT Tokens for stateless authentication (7 day expiry)
  • βœ… User Isolation - Each user sees only their messages
  • βœ… Token Verification on all protected endpoints
  • βœ… CORS configured for web and mobile
  • βœ… Environment Variables for secrets (not hardcoded)
  • βœ… Input Validation on all requests

✨ Features & Capabilities

Currently Working βœ… (Phase 1)

  • SMS capture on Android phone
  • ML-powered message classification
  • Multi-category expense tracking (Food, Travel, Shopping, Others)
  • Dashboard with spending analysis
  • Category-wise spending breakdown
  • Weekly spending visualization charts
  • Recent transactions list with details
  • Category report generation
  • AI-generated insights (placeholder for Gemini)
  • User authentication & data isolation
  • Dark/light theme support

Coming Soon πŸš€ (Phase 2)

  • Gemini API integration for real AI insights
  • Budget setting & alerts
  • Recurring expense detection
  • Transaction editing & correction UI
  • iOS support for SMS app
  • Cloud deployment (AWS/Heroku/Render)
  • Export to CSV/PDF
  • Spending trends & analytics
  • Multi-currency support
  • Mobile app background sync

πŸ”§ Tech Stack

Layer Technology
Frontend React 18, Vite, Tailwind CSS, React Router
Backend Node.js, Express, MongoDB, JWT, bcryptjs
Mobile React Native, Expo, TypeScript
ML/AI Python 3.8+, Flask, scikit-learn, Pandas
Deployment Docker (ready), AWS/Heroku compatible

βš™οΈ Configuration Files

Backend .env

# Server
PORT=5000
NODE_ENV=development

# Database
MONGO_URI=mongodb+srv://user:pass@cluster.mongodb.net/budgetpe

# Authentication
JWT_SECRET=your_secret_key_here_change_in_prod
JWT_EXPIRES_IN=7d

# CORS
CLIENT_URL=http://localhost:5173

Frontend .env

VITE_API_URL=http://localhost:5000/api
VITE_ML_URL=http://localhost:5001

ML Model (app.py)

Flask server runs on port 5001
Accessible to Backend and SMS App on same network

πŸ†˜ Troubleshooting Quick Links

Issue Solution
SMS App can't connect Check same WiFi + update IP in smsApp/lib/api.ts
ML Model errors Run pip install -r requirements.txt again
Backend won't start Check MongoDB running or update MONGO_URI in .env
No messages in dashboard Login again, check backend health endpoint
Port already in use Change PORT in .env or kill existing process

Full troubleshooting: See SETUP.md


πŸ“Š API Endpoints

Authentication

POST /api/auth/register    - Register new user
POST /api/auth/login       - Login (returns JWT token)
GET  /api/auth/me          - Get current user (protected)
POST /api/auth/logout      - Logout

Messages

GET  /api/messages         - Get all user messages (protected)
POST /api/messages         - Save classified message (protected)

Health

GET  /api/health           - Backend health check
GET  /                      - ML Model health check (port 5001)

πŸ§ͺ Testing the Flow

Manual End-to-End Test

  1. Start all services (see Quick Start section)
  2. Register on Frontend (http://localhost:5173)
  3. Login on SMS App with same credentials
  4. Send/Receive bank SMS on Android phone
  5. Check Dashboard - message appears instantly
  6. Verify Classification - category, amount, merchant correct
  7. Generate Report - click on any category card
  8. View Insights - see breakdown chart and AI insights

Expected Timeline

  • SMS received β†’ 3 seconds β†’ App detects
  • App calls ML model β†’ 1 second β†’ Classified
  • Sends to backend β†’ 1 second β†’ Stored
  • Frontend polls β†’ Next fetch β†’ Displays
  • Total: ~5-10 seconds from SMS receipt to dashboard

πŸ“ˆ Performance & Scalability

Component Capacity Optimization
Backend 1000s reqs/sec Node.js + clustering ready
ML Model 100s classifications/sec Can be horizontally scaled
Database Millions of records MongoDB with indexing on userId, date
Frontend Instant rendering React optimization, virtualization ready

πŸš€ Deployment Ready

The project is production-ready for Phase 1:

  • βœ… Error handling
  • βœ… Input validation
  • βœ… Authentication/Authorization
  • βœ… Data isolation
  • βœ… Configuration via environment variables
  • βœ… Docker-ready structure

Pre-deployment checklist:

  • Change JWT_SECRET to strong value
  • Set up MongoDB Atlas cluster
  • Configure CORS for production domain
  • Enable HTTPS
  • Set NODE_ENV=production
  • Deploy to cloud (Heroku, AWS, etc)

πŸ“ Development Notes

Adding New Categories

  1. Update Message enum in Backend/models/Message.js
  2. Add validation in Backend/validators/messageValidator.js
  3. Add keywords in ML model/pipeline.py
  4. Add color in Frontend Dashboard.jsx
  5. Retrain model: python ML\ model/train.py

Retraining ML Model

cd "ML model"
# Update data/dataset.csv with new training data
python train.py
# Restart Flask server
python app.py

πŸŽ“ Learning Path

Want to understand the project?

  1. Read: FIX_SUMMARY.md - What was done
  2. Read: ARCHITECTURE.md - How it works
  3. Read: SETUP.md - Complete details
  4. Explore: Source code with inline comments

Want to extend it?

  1. Review: ML model classification logic
  2. Add: New expense categories
  3. Integrate: Gemini API for insights
  4. Deploy: To cloud platform

πŸ“ž Support & Help


πŸ“„ License

MIT License - Free to use and modify!


πŸŽ‰ Ready?

πŸ‘‰ START WITH QUICKSTART.md

Get the app running in 5 minutes!


Built with ❀️ for expense tracking | Powered by AI | Secured by JWT

npm install
npm run dev

Backend runs at http://localhost:5000


2. Frontend

cd frontend
npm install
npm run dev

Frontend runs at http://localhost:5173

About

AI POWERED budget management system that tracks your spending behaviour through your transactions and providing tips to save more money.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages