Skip to content

Repository files navigation

Loan Management System API

Java Spring Boot MySQL Maven

This is a comprehensive REST API built with Spring Boot to simulate the full lifecycle of a loan, from origination and payment tracking to closure and default. It's designed with a clean, layered architecture (Controller-Service-Repository) and follows best practices for API design and data handling.


Features

  • Loan Lifecycle Management: Create, track, and close loans.
  • Payment Tracking: Record individual payments against a loan.
  • Automated Business Rules:
    • EMI Calculation: Automatically calculates the Simple Interest, Total Repayable Amount, and Monthly EMI when a loan is created.
    • Overpayment Prevention: The API rejects any payment that would exceed the loan's remaining balance.
    • Auto-Closure: Automatically transitions a loan's status from ACTIVE to CLOSED when the final payment is made.
    • Auto-Default: A daily scheduled job checks for overdue payments. If a loan is past its grace period (10 days) and is underpaid, its status is automatically set to DEFAULTED.
  • Pagination & Filtering: The GET /loans endpoint supports full pagination and sorting, as well as filtering by LoanStatus.
  • Error Handling: Provides clear, JSON-based error messages for common issues (e.g., resource not found, invalid payments, validation errors).

Tech Stack

  • Framework: Spring Boot 3+
  • Language: Java 17+
  • Data: Spring Data JPA (Hibernate)
  • API: Spring Web (REST Controllers)
  • Database: MySQL
  • Scheduling: Spring Task (@Scheduled)
  • Utilities: Lombok
  • Build: Apache Maven

Getting Started

Prerequisites

  • Java 17 or higher
  • Apache Maven 3.6+
  • A running MySQL server

1. Database Configuration

  1. Create a new database in MySQL:

    CREATE DATABASE loan_db;
  2. Update the src/main/resources/application.properties file with your MySQL username and password:

    # MySQL Database Connection
    spring.datasource.url=jdbc:mysql://localhost:3306/loan_db?createDatabaseIfNotExist=true
    spring.datasource.username=root
    spring.datasource.password=your_mysql_password
    spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
    
    # JPA Configuration
    spring.jpa.hibernate.ddl-auto=update
    spring.jpa.show-sql=true
    spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect

2. Run the Application

You can run the application using the Spring Boot Maven plugin:

mvn spring-boot:run

About

Loan Management

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages