A production-grade MERN stack financial management application with automated microservices for daily PDF email delivery, real-time expense analytics, Google OAuth, and multi-format data export.
βββββββββββββββββββββββββββββββββ
β User β
β (Web Browser) β
ββββββββββββββββ¬βββββββββββββββββ
β
HTTP / HTTPS
β
ββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββ
β React Frontend (SPA) β
β β
β β’ Authentication β
β β’ Dashboard & Analytics β
β β’ Expense Management β
β β’ Reports & Export β
β β’ Google OAuth Login β
βββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ
β
REST API (JWT)
β
βββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββ
β Express.js Backend API β
β β
β Routes β Middleware β Controllers β Services β Models β
βββββββββββββββββ¬ββββββββββββββββββββββββββββββββ¬βββββββββββββββββ
β β
β β
βββββββββββββΌβββββββββββ βββββββββββββΌβββββββββββββ
β MongoDB β β Authentication β
β β β β
β β’ Users β β β’ JWT β
β β’ Expenses β β β’ Google OAuth β
β β’ Categories β β β’ OTP Verification β
β β’ OTP Tokens β β β’ Password Reset β
β β’ Reset Tokens β βββββββββββββββββββββββββββ
βββββββββββββ²βββββββββββ
β
βββββββββββΌββββββββββ
β LangChain / β
β LangGraph β
β Workflow Engine β
β β
β β’ Orchestrates β
β report flow β
β β’ Coordinates β
β services β
βββββββββββ¬βββββββββ
β
ββββββββββββββββββββΌββββββββββββββββββββββββββββββ
β β β
ββββββββββββΌβββββββββββ ββββββΌβββββββββββββββββ ββββββββββββΌβββββββββββ
β PDF Service β β Email Service β β Scheduler Service β
β (PDFKit) β β (Nodemailer) β β (Node-Cron) β
β β β β β β
β β’ Generate Reports β β β’ OTP Emails β β β’ Daily 6:00 AM Job β
β β’ Export PDFs β β β’ Reset Emails β β β’ Trigger Workflow β
β β β β’ PDF Delivery β β β
ββββββββββββ¬βββββββββββ βββββββββββ¬βββββββββββ ββββββββββββ¬ββββββββββββ
ββββββββββββββββββββββββΌβββββββββββββββββββββββββ
β
SMTP (Gmail)
β
ββββββββββββΌβββββββββββ
β User's Email β
β β
β β’ OTP β
β β’ Password Reset β
β β’ Daily PDF Report β
ββββββββββββββββββββββ
This is not a basic CRUD expense app. The Expense Tracker is built around three production-grade microservices that automate the financial reporting experience:
The flagship feature of this application.
Every day at 8:00 AM, an automated background service powered by Node-Cron and Nodemailer runs a scheduled job that:
- π Queries MongoDB for all registered users
- π Fetches each user's expenses from the previous 24 hours
- π Generates a beautifully formatted PDF financial summary using PDFKit
- π§ Attaches the PDF and delivers it directly to each user's email inbox
- π Logs delivery status for debugging and monitoring
This is a fully automated, zero-user-interaction financial reporting pipeline β the same pattern used by banks and financial SaaS products to deliver statements to customers.
Cron Schedule (Daily 8AM)
β
βΌ
Query All Users
β
βΌ
Fetch Daily Expenses (MongoDB)
β
βΌ
Generate PDF Report (PDFKit)
β
βΌ
Send Email with Attachment (Nodemailer + Gmail)
β
βΌ
Log Delivery Result
On every new registration, a One-Time Password (OTP) is generated, stored with an expiry timestamp, and delivered to the user's inbox via Nodemailer. The user must verify their email before gaining access to the application. This microservice runs independently of the main Express request cycle.
User Registers β OTP Generated (6-digit) β Nodemailer Sends Email
β
User Enters OTP ββ
β
βββββββββββββββββ΄ββββββββββββββββ
Valid + Not Expired? Invalid / Expired
β β
Account Activated β
Error Returned β
A secure token-based password reset pipeline:
- User requests reset β unique token generated and stored in DB with expiry
- Nodemailer sends a time-limited reset link to the user's email
- User clicks the link β token verified β password updated and token invalidated
- Features
- Tech Stack
- Architecture
- Getting Started
- Environment Variables
- API Endpoints
- Screenshots
- Contributing
- π User registration with OTP email verification
- π Login with JWT authentication (access tokens)
- π Google OAuth 2.0 login via Passport.js
- π Forgot password email flow with secure token reset
- π‘οΈ Protected routes on both frontend and backend
- β Add, βοΈ Edit, ποΈ Delete expenses with category tagging
- π·οΈ Custom expense categories per user
- π Search expenses by name, category, or description
- π Filter by weekly / monthly / yearly date ranges
- π Real-time dashboard with pie and bar charts
- π° Income vs expense balance overview
- π Top spending category highlights
- π Day-by-day spending timeline
- π On-demand PDF export of expense history
- π Excel (XLSX) export for spreadsheet analysis
- π¬ Daily automated PDF email sent to every user (microservice)
| Layer | Technology | Purpose |
|---|---|---|
| Frontend | React.js 18 | SPA user interface |
| UI Library | Ant Design / Bootstrap | Components & layout |
| State | Context API | Global state management |
| Charts | Chart.js / Recharts | Data visualisation |
| Backend | Node.js + Express.js | REST API server |
| Database | MongoDB + Mongoose | Data persistence |
| Authentication | JWT + Passport.js | Auth & SSO |
| Nodemailer + Gmail | Transactional emails | |
| Scheduling | Node-Cron | Automated daily jobs |
| PDFKit | PDF generation | |
| Excel | xlsx / ExcelJS | Spreadsheet export |
| OAuth | Google OAuth 2.0 | Social login |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CLIENT (React SPA) β
β Dashboard β Auth β Expenses β Reports β Settings β
βββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββ
β HTTP / REST
βββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββ
β EXPRESS REST API β
β Routes β Controllers β Middleware β Mongoose Models β
ββββββββ¬ββββββββββββββββββββββββββββββββββββββ¬βββββββββββββ
β β
ββββββββΌβββββββ βββββββββββΌβββββββββββββ
β MongoDB β β MICROSERVICES β
β (Mongoose) β β β
β β β π¬ Daily PDF Emailer β
β β’ Users ββββββββββββββββββββββ (Node-Cron + PDFKit β
β β’ Expenses β β + Nodemailer) β
β β’ Categoriesβ β β
βββββββββββββββ β βοΈ OTP Verifier β
β π Password Reset β
ββββββββββββββββββββββββ
- Node.js 18+
- MongoDB (local or Atlas)
- Gmail account (for email features)
- Google Cloud Console project (for OAuth)
# 1. Clone the repository
git clone https://github.com/MuhammadHaris249518/Expense-tracker.git
cd Expense-tracker/Expense-tracker
# 2. Install backend dependencies
cd backend
npm install
# 3. Install frontend dependencies
cd ../frontend
npm install# Start MongoDB (if running locally)
mongod
# In one terminal β start the backend
cd backend
npm run dev
# In another terminal β start the frontend
cd frontend
npm startThe app will be available at http://localhost:3000 (frontend) and http://localhost:5000 (backend API).
Create a .env file in the /backend directory using the template below:
# βββ Server ββββββββββββββββββββββββββββββ
PORT=5000
NODE_ENV=development
# βββ Database ββββββββββββββββββββββββββββ
MONGODB_URI=mongodb://localhost:27017/expense-tracker
# βββ JWT βββββββββββββββββββββββββββββββββ
JWT_SECRET=your_strong_jwt_secret_here
JWT_EXPIRES_IN=7d
# βββ Email (Nodemailer) ββββββββββββββββββ
EMAIL_USER=your_gmail@gmail.com
EMAIL_PASS=your_gmail_app_password # Use App Password, NOT your main password
# βββ Google OAuth βββββββββββββββββββββββββ
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GOOGLE_CALLBACK_URL=http://localhost:5000/api/auth/google/callback
# βββ Frontend URL ββββββββββββββββββββββββ
CLIENT_URL=http://localhost:3000
β οΈ Never commit your.envfile. Make sure.envis listed in your.gitignore.
| Method | Endpoint | Description |
|---|---|---|
| POST | /register |
Register with OTP verification |
| POST | /verify-otp |
Verify OTP code |
| POST | /login |
Login with email + password |
| GET | /google |
Initiate Google OAuth |
| GET | /google/callback |
Google OAuth callback |
| POST | /forgot-password |
Send password reset email |
| POST | /reset-password/:token |
Reset password with token |
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Get all expenses (with filter) |
| POST | / |
Create a new expense |
| PUT | /:id |
Update an expense |
| DELETE | /:id |
Delete an expense |
| GET | /export/pdf |
Download PDF report |
| GET | /export/excel |
Download Excel export |
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Get all categories |
| POST | / |
Create category |
| DELETE | /:id |
Delete category |
Expense-tracker/
βββ backend/
β βββ controllers/ # Business logic
β β βββ authController.js
β β βββ expenseController.js
β β βββ categoryController.js
β βββ models/ # Mongoose schemas
β β βββ User.js
β β βββ Expense.js
β β βββ Category.js
β βββ routes/ # Express routes
β βββ middleware/ # Auth middleware
β βββ services/ # π¬ Microservices
β β βββ emailService.js # Nodemailer config
β β βββ pdfService.js # PDF generation
β β βββ cronJob.js # Daily scheduler
β βββ utils/ # Helper functions
β βββ server.js # Entry point
βββ frontend/
β βββ src/
β β βββ components/ # Reusable UI components
β β βββ pages/ # Page components
β β βββ context/ # State management
β β βββ utils/ # API helpers
β βββ public/
βββ README.md
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature-name - Commit your changes:
git commit -m 'feat: add your feature' - Push to the branch:
git push origin feature/your-feature-name - Open a Pull Request
This project is licensed under the MIT License.
Built with β€οΈ by Muhammad Haris
MERN Stack Β· Microservices Β· Automated Financial Reporting