Getting everything ready for you…

Loading courses, problems and your progress. This takes just a moment.

0s

Projects › Intermediate

Library Management REST API

A production-style REST API to manage books, members, issues and returns with fines — the go-to Spring Boot portfolio project.

Level: Intermediate · Time: 1–2 weeks · Tech stack: Spring Boot, Spring Data JPA, MySQL, Spring Security

Features to build

What you will learn

Step-by-step guide

1. Start

Spring Initializr with Web, Data JPA, Validation, MySQL Driver, Security, Lombok.

2. Entities

Book (isbn, title, author, copies), Member, Loan (book, member, issuedOn, dueOn, returnedOn, fine) with @ManyToOne relations.

3. Issue a book safely

@Transactional
public Loan issue(Long bookId, Long memberId) {
    Book b = books.findById(bookId).orElseThrow(() -> new NotFoundException("Book not found"));
    if (b.getCopies() == 0) throw new BadRequestException("No copies left");
    if (loans.countByMemberIdAndReturnedOnIsNull(memberId) >= 3) throw new BadRequestException("Limit reached");
    b.setCopies(b.getCopies() - 1);
    return loans.save(new Loan(b, members.getReferenceById(memberId), LocalDate.now(), LocalDate.now().plusDays(14)));
}

@Transactional keeps the copy count and the loan consistent.

4. Fines

On return: fine = max(0, days late) × ₹5, using ChronoUnit.DAYS.between(dueOn, today).

5. DTOs + validation + errors

Request records with @NotBlank/@Min, and a @RestControllerAdvice returning clean JSON errors.

6. Security

JWT filter; /api/books/** GET public, write operations hasRole('ADMIN').

7. Docs & tests

springdoc-openapi for Swagger UI; @WebMvcTest for controllers, @DataJpaTest for repositories.

Level it up

On your resume

Learn on Codify