AI-Powered Expense Tracking via SMS Classification
Track your spending automatically. Your bank sends SMS β We classify it β You see insights.
β 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
- Node.js 18+
- Python 3.8+
- MongoDB (local or Atlas)
# 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 startThen:
- Open http://localhost:5173
- Register/Login
- Open SMS App on phone
- Send a bank SMS
- See it appear in dashboard instantly! β‘
π² 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
| 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
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
π₯ 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! β
{
_id: ObjectId,
name: "Mukul",
email: "mukul@example.com",
phoneNumber: "9876543210",
password: "hashed_with_bcrypt",
createdAt: Date,
updatedAt: Date
}{
_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
}- β 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
- 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
- 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
| 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 |
# 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:5173VITE_API_URL=http://localhost:5000/api
VITE_ML_URL=http://localhost:5001Flask server runs on port 5001
Accessible to Backend and SMS App on same network| 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
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
GET /api/messages - Get all user messages (protected)
POST /api/messages - Save classified message (protected)
GET /api/health - Backend health check
GET / - ML Model health check (port 5001)
- Start all services (see Quick Start section)
- Register on Frontend (http://localhost:5173)
- Login on SMS App with same credentials
- Send/Receive bank SMS on Android phone
- Check Dashboard - message appears instantly
- Verify Classification - category, amount, merchant correct
- Generate Report - click on any category card
- View Insights - see breakdown chart and AI insights
- 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
| 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 |
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)
- Update Message enum in
Backend/models/Message.js - Add validation in
Backend/validators/messageValidator.js - Add keywords in
ML model/pipeline.py - Add color in Frontend
Dashboard.jsx - Retrain model:
python ML\ model/train.py
cd "ML model"
# Update data/dataset.csv with new training data
python train.py
# Restart Flask server
python app.pyWant to understand the project?
- Read: FIX_SUMMARY.md - What was done
- Read: ARCHITECTURE.md - How it works
- Read: SETUP.md - Complete details
- Explore: Source code with inline comments
Want to extend it?
- Review: ML model classification logic
- Add: New expense categories
- Integrate: Gemini API for insights
- Deploy: To cloud platform
- Quick start help: QUICKSTART.md
- Setup help: SETUP.md
- Architecture questions: ARCHITECTURE.md
- What was changed: FIX_SUMMARY.md
- Verify everything works: INTEGRATION_CHECKLIST.md
MIT License - Free to use and modify!
Get the app running in 5 minutes!
Built with β€οΈ for expense tracking | Powered by AI | Secured by JWT
npm install
npm run devBackend runs at http://localhost:5000
cd frontend
npm install
npm run devFrontend runs at http://localhost:5173