Help us measure site usage?

With your permission, we use self-hosted analytics to understand page usage. It is optional and does not affect the Service. Learn more.

JavabeginnercliAI generated

Library Checkout CLI

Build a console app in Java for a small library's front desk: register books and members, lend a book (with a due date 14 days later), record returns, and print which loans are overdue and by how many days. Data is stored in PostgreSQL, and the app is built with Spring Boot, which is a gentle way to meet the framework: it wires the pieces together for you, and Spring's JdbcTemplate makes database access simple. Rules are enforced carefully: a book already on loan can't be lent again, and members with overdue books can't borrow more. You'll learn a Spring Boot console app (CommandLineRunner), SQL with JdbcTemplate, working with dates using java.time, validating input, and testing with a real database.

Estimate
~9h
Steps
6
Completed by
0
Proposed by
codeseed.app

Spring Boot · PostgreSQL

Project roadmap

  1. 01

    Plan the commands and data

    ~1h

    Write README.md: the commands (add-book, add-member, lend BOOK MEMBER, return BOOK, list-loans, overdue and help), the data (books with a unique code, members, and loans with loaned, due and returned dates) and the rules (one open loan per book, 14-day loans, no new loans for members with overdue books, and at most 5 books per member). Run PostgreSQL with Docker. Done when: README.md defines the commands, data and rules.

  2. 02

    Set up Spring Boot and the database

    ~1.5h

    Create a Spring Boot project (with spring-boot-starter-jdbc, the PostgreSQL driver and Flyway). Write a Flyway migration creating the three tables with foreign keys and a partial unique index allowing only one open loan per book. Configure the database connection in application.properties. Done when: the app starts and Flyway creates the tables.

  3. 03

    Write the data access

    ~1.5h

    Create repository classes using JdbcTemplate with parameterized queries (never building SQL from user input): add and find books and members, create a loan, close a loan, and list open and overdue loans. Map rows to Java records. Done when: repository methods work in a quick test against the database.

  4. 04

    Implement the rules

    ~1.5h

    Write a LibraryService with the rules from README.md, throwing clear exceptions when a rule is broken (book already lent, member has overdue books, or too many loans). Use java.time.LocalDate for dates, and take a Clock as a dependency so tests can set today's date. Make lending a single transaction (@Transactional). Done when: each rule is enforced with a clear message.

  5. 05

    Build the console

    ~1.5h

    Implement a CommandLineRunner with a read-command loop using Scanner: parse each command and its arguments, call the service, and print results as aligned tables (with the overdue report showing member, book, due date and days overdue). Catch exceptions and show their messages without stopping the program. Done when: every command works from the console, and mistakes show clear messages.

  6. 06

    Test it

    ~2h

    Write JUnit tests for the service with a fixed Clock: lending, returning, every rule, and overdue calculations (due today, one day late and returned late). Add a Spring Boot test using Testcontainers PostgreSQL for the repositories. Done when: all tests pass.

Ready to build this?

Get a GitHub repo and start building. Your AI reviewer checks each step as you go.

~9h · 6 steps

Tech stack

Spring BootPostgreSQL