sasuke1431/spring-microservice-backend
0
FinApp - Personal Lending Tracker
A complete full-stack application for tracking personal lending with interest calculations and payment management.
Technology Stack
Backend
- Java Spring Boot 3.0
- Spring Data JPA - ORM framework
- Spring Batch - Scheduled batch processing
- H2 Database - Embedded database
- Apache POI - Excel export functionality
- Lombok - Boilerplate reduction
- Gradle - Build automation
Frontend
- React 18 - UI framework
- React Router 6 - Client-side routing
- Axios - HTTP client
- Vite - Build tool
- CSS3 - Styling
Project Structure
untitled/
├── src/main/java/com/example/
│ ├── FinAppApplication.java # Main Spring Boot app
│ ├── controller/ # REST controllers
│ │ ├── BorrowerController.java
│ │ ├── LoanController.java
│ │ ├── PaymentController.java
│ │ ├── NotificationController.java
│ │ └── DashboardController.java
│ ├── service/ # Business logic
│ │ ├── BorrowerService.java
│ │ ├── LoanService.java
│ │ ├── PaymentService.java
│ │ └── NotificationService.java
│ ├── entity/ # JPA entities
│ │ ├── Borrower.java
│ │ ├── Loan.java
│ │ ├── PaymentHistory.java
│ │ └── InterestNotification.java
│ ├── repository/ # Data access layer
│ │ ├── BorrowerRepository.java
│ │ ├── LoanRepository.java
│ │ ├── PaymentHistoryRepository.java
│ │ └── InterestNotificationRepository.java
│ ├── dto/ # Data transfer objects
│ │ ├── BorrowerDTO.java
│ │ ├── LoanDTO.java
│ │ ├── PaymentHistoryDTO.java
│ │ └── InterestNotificationDTO.java
│ ├── batch/ # Spring Batch configuration
│ │ ├── InterestCalculationJobConfig.java
│ │ ├── ExcelBackupJobConfig.java
│ │ └── BatchSchedulingConfig.java
│ └── util/ # Utility classes
│ └── ExcelExportUtil.java
├── src/main/resources/
│ └── application.properties # Spring configuration
├── build.gradle # Gradle build config
├── frontend/
│ ├── src/
│ │ ├── components/
│ │ │ ├── Dashboard.jsx # Dashboard view
│ │ │ ├── LoanForm.jsx # Loan creation form
│ │ │ ├── BorrowerForm.jsx # Borrower creation form
│ │ │ ├── NotificationPanel.jsx # Interest notifications
│ │ │ └── RepaymentModal.jsx # Payment recording modal
│ │ ├── api/
│ │ │ └── api.js # API client
│ │ ├── hooks/
│ │ │ └── useAPI.js # Custom hooks
│ │ ├── styles/
│ │ │ ├── Dashboard.css
│ │ │ ├── LoanForm.css
│ │ │ ├── BorrowerForm.css
│ │ │ ├── NotificationPanel.css
│ │ │ └── RepaymentModal.css
│ │ ├── App.jsx # Main app component
│ │ ├── App.css # App styling
│ │ └── main.jsx # Entry point
│ ├── package.json # Dependencies
│ └── vite.config.js # Vite configurationFeatures
Backend Features
✅ CRUD Operations
- Create, Read, Update, Delete borrowers
- Create, Read, Update, Delete loans
- Record and track payments
✅ Interest Calculation
- Dynamic interest calculation based on current principal
- Support for multiple interest periods (Monthly, Quarterly, Semi-Annual, Yearly)
- Automatic interest cycle detection
✅ Payment Management
- Record interest payments
- Record principal reductions
- Automatic principal adjustment on payment
- Payment history tracking
✅ Notification System
- Automatic interest notification generation
- Mark notifications as completed
- Revert completed notifications to pending
✅ Scheduled Jobs
- Daily interest calculation job (runs at 00:00)
- Daily Excel backup job (runs at 02:00)
✅ Reporting
- Dashboard summary with key metrics
- Excel export of all data (Borrowers, Loans, Payments, Notifications)
Frontend Features
✅ Dashboard
- Total money lent summary
- Total remaining principal
- Total interest collected
- Active borrowers count
- Active loans display
- Borrower management table
✅ Borrower Management
- Add new borrowers with contact details
- View all borrowers
- Edit borrower information
✅ Loan Management
- Create loans for borrowers
- Set interest rates and periods
- View active and inactive loans
- Edit loan terms
✅ Payment Tracking
- Record interest payments
- Record principal reductions
- View payment history
- Payment modal for easy entry
✅ Interest Notifications
- View pending interest notifications
- Mark notifications as received/completed
- Revert completed notifications
- Filter by borrower
Setup Instructions
Prerequisites
- Java 17+
- Node.js 18+
- npm or yarn
- Maven or Gradle
Backend Setup
- Navigate to project root
cd "D:\HLD & LLD\untitled"- Build the project
./gradlew build- Run the application
./gradlew bootRun The backend will start on http://localhost:8080
- Access H2 Console Navigate to
http://localhost:8080/api/h2-consoleto view the database
Frontend Setup
- Navigate to frontend directory
cd frontend- Install dependencies
npm install- Start development server
npm run dev The frontend will start on http://localhost:5173
- Build for production
npm run buildAPI Endpoints
Borrowers
POST /api/borrowers- Create borrowerGET /api/borrowers- Get all borrowersGET /api/borrowers/{id}- Get borrower by IDPUT /api/borrowers/{id}- Update borrowerDELETE /api/borrowers/{id}- Delete borrower
Loans
POST /api/loans- Create loanGET /api/loans- Get all loansGET /api/loans/{id}- Get loan by IDGET /api/loans/active/all- Get active loansGET /api/loans/borrower/{borrowerId}- Get loans by borrowerPUT /api/loans/{id}- Update loanDELETE /api/loans/{id}- Delete loan
Payments
POST /api/payments/loan/{loanId}- Record paymentGET /api/payments/{id}- Get paymentGET /api/payments/loan/{loanId}- Get payments for loanGET /api/payments/loan/{loanId}/total-principal- Get total principal paidGET /api/payments/loan/{loanId}/range- Get payments by date range
Notifications
POST /api/notifications/loan/{loanId}- Create notificationGET /api/notifications- Get all notificationsGET /api/notifications/{id}- Get notificationGET /api/notifications/pending/all- Get pending notificationsGET /api/notifications/pending/loan/{loanId}- Get pending for loanGET /api/notifications/pending/uptodate- Get pending up to datePUT /api/notifications/{id}/complete- Mark as completedPUT /api/notifications/{id}/revert- Revert to pendingDELETE /api/notifications/{id}- Delete notification
Dashboard
GET /api/dashboard/summary- Get dashboard summary
Database Schema
Borrowers
id(Primary Key)name(String)phone(String)email(String)address(Text)created_at(Timestamp)updated_at(Timestamp)
Loans
id(Primary Key)borrower_id(Foreign Key)original_principal(BigDecimal)current_principal(BigDecimal)interest_rate(BigDecimal)interest_period(Enum: MONTHLY, QUARTERLY, SEMI_ANNUAL, YEARLY)start_date(Date)is_active(Boolean)created_at(Timestamp)updated_at(Timestamp)
Payment History
id(Primary Key)loan_id(Foreign Key)payment_date(Date)amount(BigDecimal)payment_type(Enum: INTEREST, PRINCIPAL)created_at(Timestamp)
Interest Notifications
id(Primary Key)loan_id(Foreign Key)due_date(Date)amount_due(BigDecimal)status(Enum: PENDING, COMPLETED)created_at(Timestamp)updated_at(Timestamp)
Configuration
application.properties
# Server
server.port=8080
server.servlet.context-path=/api
# H2 Database
spring.datasource.url=jdbc:h2:file:./data/finapp
spring.datasource.driverClassName=org.h2.Driver
spring.jpa.hibernate.ddl-auto=update
# Batch
spring.batch.job.enabled=true
# Excel Export
app.export.excel.path=./exports/
app.export.excel.filename=finapp-backup.xlsxScheduled Jobs
Daily Interest Calculation (00:00)
- Scans all active loans
- Checks if interest cycle is completed
- Generates InterestNotification records
- Uses Spring Batch for reliable processing
Daily Excel Backup (02:00)
- Exports all data to Excel
- Creates separate sheets for each entity
- Stores in
./exports/directory - Preserves data for disaster recovery
Error Handling
The application includes comprehensive error handling:
- Validation of input data
- Proper HTTP status codes
- Meaningful error messages
- Transaction rollback on failures
Security Considerations
For production deployment:
- Add Spring Security with JWT authentication
- Implement rate limiting
- Use HTTPS
- Validate and sanitize all inputs
- Implement CORS properly
- Use environment variables for sensitive config
Troubleshooting
Backend won't start
- Check if port 8080 is already in use
- Verify Java 17+ is installed
- Check for missing dependencies:
./gradlew clean build
Frontend connection errors
- Ensure backend is running on port 8080
- Check CORS configuration
- Verify API endpoints in
frontend/src/api/api.js - Check browser console for specific errors
Database issues
- H2 database file is stored in
./data/finapp.mv.db - To reset database, delete the file and restart
- Access H2 console at
http://localhost:8080/api/h2-console
Future Enhancements
- User authentication and multi-user support
- Email notifications for pending interest
- Advanced reporting and analytics
- Mobile app (React Native)
- Payment reminders
- Document upload for loans
- Audit logging
- Data encryption
License
This project is provided as-is for educational purposes.
Support
For issues and questions, please refer to the API documentation and component comments in the source code.
