Skip to main content

Loan Application Evaluator

A runnable Spring Boot 4 project that shows how a real loan-evaluation backend is structured — from REST API to JPA persistence and Mockito unit tests.

What You'll Find Here

NoteDescription
Project OverviewWhat the project does, tech stack, and how to run it locally.
Domain ModelEntities, DTOs (Records), and the five enums that drive business rules.
API ContractThe single REST endpoint, request/response shapes, and Bean Validation rules.
Service & Business LogicRisk classification, interest-rate formula, EMI calculation, and the two-tier eligibility check.
Persistence LayerJPA @Embeddable value objects, @ElementCollection for rejection reasons, and H2 schema.
Exception Handling@RestControllerAdvice catching validation failures and mapping them to structured JSON errors.
Testing StrategyMockito-based unit tests with @Nested grouping by concern.

Learning Path

Work through the notes in this order for the clearest mental model:

  1. Project Overview — run the app first; get a feel for what it does.
  2. Domain Model — understand the data before the logic.
  3. API Contract — see what input the API accepts and what it returns.
  4. Service & Business Logic — the core: risk, rate, EMI, eligibility.
  5. Persistence Layer — how the domain objects map to H2 tables.
  6. Exception Handling — how invalid requests are turned into useful error responses.
  7. Testing Strategy — how unit tests verify each business rule in isolation.

Source Code

The full source lives at projects/loan-application-evaluator/ in the repository root.

projects/loan-application-evaluator/
├── src/main/java/com/dileephegde/loanapplicationevaluator/
│ ├── LoanApplicationEvaluator.java ← @SpringBootApplication entry point
│ ├── controller/
│ │ └── LoanApplicationController.java ← POST /applications
│ ├── service/
│ │ └── LoanApplicationService.java ← all business logic
│ ├── entity/
│ │ ├── LoanApplication.java ← aggregate root (@Entity)
│ │ ├── Applicant.java ← @Embeddable value object
│ │ ├── Loan.java ← @Embeddable value object
│ │ ├── Offer.java ← @Embeddable value object
│ │ └── enums/
│ │ ├── ApplicationStatus.java
│ │ ├── EmploymentType.java
│ │ ├── LoanPurpose.java
│ │ ├── RejectionReason.java
│ │ └── RiskBand.java
│ ├── dto/
│ │ ├── LoanApplicationRequest.java ← record (input)
│ │ ├── LoanApplicationResponse.java ← record (output)
│ │ ├── ApplicantDTO.java ← record with @Valid annotations
│ │ ├── LoanDTO.java ← record with @Valid annotations
│ │ └── OfferDTO.java ← record (read-only output)
│ ├── repository/
│ │ └── ILoanApplicationRepository.java ← JpaRepository
│ └── exception/
│ ├── GlobalExceptionHandler.java ← @RestControllerAdvice
│ └── ErrorResponse.java ← record
└── src/test/java/…/service/
└── LoanApplicationServiceTest.java ← @Nested Mockito tests
  • Spring Boot — auto-configuration, starters, @SpringBootApplication.
  • Spring Data — JPA repositories, @Embeddable, @ElementCollection.
  • Testing — JUnit 5 and Mockito patterns used in this project.
  • Web — REST controller patterns, @RestControllerAdvice.