CoolFace
Apppublic

sasuke1431/spring-microservice-backend

sourceHugging Faceupdated 21d agoView on Hugging Face
0likes
App README

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 configuration

Features

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

  1. 1.Navigate to project root
bash
   cd "D:\HLD & LLD\untitled"
  1. 1.Build the project
bash
   ./gradlew build
  1. 1.Run the application
bash
   ./gradlew bootRun

The backend will start on http://localhost:8080

  1. 1.Access H2 Console Navigate to http://localhost:8080/api/h2-console to view the database

Frontend Setup

  1. 1.Navigate to frontend directory
bash
   cd frontend
  1. 1.Install dependencies
bash
   npm install
  1. 1.Start development server
bash
   npm run dev

The frontend will start on http://localhost:5173

  1. 1.Build for production
bash
   npm run build

API Endpoints

Borrowers

  • —POST /api/borrowers - Create borrower
  • —GET /api/borrowers - Get all borrowers
  • —GET /api/borrowers/{id} - Get borrower by ID
  • —PUT /api/borrowers/{id} - Update borrower
  • —DELETE /api/borrowers/{id} - Delete borrower

Loans

  • —POST /api/loans - Create loan
  • —GET /api/loans - Get all loans
  • —GET /api/loans/{id} - Get loan by ID
  • —GET /api/loans/active/all - Get active loans
  • —GET /api/loans/borrower/{borrowerId} - Get loans by borrower
  • —PUT /api/loans/{id} - Update loan
  • —DELETE /api/loans/{id} - Delete loan

Payments

  • —POST /api/payments/loan/{loanId} - Record payment
  • —GET /api/payments/{id} - Get payment
  • —GET /api/payments/loan/{loanId} - Get payments for loan
  • —GET /api/payments/loan/{loanId}/total-principal - Get total principal paid
  • —GET /api/payments/loan/{loanId}/range - Get payments by date range

Notifications

  • —POST /api/notifications/loan/{loanId} - Create notification
  • —GET /api/notifications - Get all notifications
  • —GET /api/notifications/{id} - Get notification
  • —GET /api/notifications/pending/all - Get pending notifications
  • —GET /api/notifications/pending/loan/{loanId} - Get pending for loan
  • —GET /api/notifications/pending/uptodate - Get pending up to date
  • —PUT /api/notifications/{id}/complete - Mark as completed
  • —PUT /api/notifications/{id}/revert - Revert to pending
  • —DELETE /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

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.xlsx

Scheduled 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.