Library Management

Level: Intermediate 30–60 min

Concepts: StateBusiness Rules

Solutions: C# | TypeScript | Python


Implement a library management system that handles book checkouts, returns, and reservations. The system should manage book inventory, track due dates, and handle various library policies.

Requirements

  1. Manage book inventory
    • Add and remove books
    • Track book status (available, checked out, reserved)
    • Handle multiple copies of the same book
    • Manage book categories and locations
  2. Handle checkouts and returns
    • Process book checkouts
    • Track due dates
    • Handle late returns
    • Calculate fines
  3. Manage reservations
    • Place and cancel reservations
    • Notify when reserved books are available
    • Handle reservation queues
    • Expire old reservations

Hint

Start by implementing the basic book management functionality, then add checkout and reservation features. Consider using a state machine to track book status. Think about:

  • Data consistency and validation
  • Concurrent access handling
  • Business rule enforcement
  • Error handling and edge cases

Bonus

The reference implementation deliberately scopes to the twenty core scenarios. The items below are stretch goals that are not modeled in the reference:

  • Implement a patron management system
  • Add support for different types of library materials
  • Create a recommendation system
  • Implement a search and filtering system
  • Add support for e-books and digital content

Reference Walkthrough

Full C#, TypeScript, and Python implementations live at tddbuddy-reference-katas/library-management. Twenty scenarios across books & copies, members, checkouts, returns, and reservations — shared across all three languages — with a Library aggregate, Book/Copy/Member/Loan/Reservation entities, Money and Isbn value types, Clock and Notifier collaborators, and three fluent builders (BookBuilder, MemberBuilder, LibraryBuilder) plus FixedClock and RecordingNotifier test doubles.

  • C# (.NET 8, xUnit, FluentAssertions) — walkthrough
  • TypeScript (Node 20, Vitest, strict types) — walkthrough
  • Python (3.11, pytest, dataclasses, Decimal) — walkthrough

This kata ships in Agent Full-Bake mode: one commit per language with the full domain design landing together. The walkthroughs read as design rationalewhy Copy is an entity rather than an available-count integer, why expireReservations() is an explicit sweep like video-club-rental’s MarkOverdueRentals, why fine calculation lives on Loan. See the repo’s Gears section for when middle gear is the right call.


  • TDD Already Does BDD, Without the Gherkin
    BDD wasn't a discovery. It was a rebrand of what disciplined TDD was already doing. Test data builders, factory hierarchies, and mock-driven collaboration tests are the scenarios, and they evolve alongside the code instead of rotting beside it.
  • The Test Pyramid Was an Economic Argument
    The test pyramid was not a quality law. It was a cost structure: unit tests were cheap, integration tests were expensive, so you wrote many of the first and few of the second. Agents collapsed the cost of writing tests at every level, and the cheapest test that still tells the truth is the one that pins a seam the agent cannot fake.
  • Agents Amplify Whatever Vocabulary They Find
    Agents do not bring vocabulary to your codebase. They mirror what's already there. Strong vocabulary gets agent contributions that read like the team. Weak vocabulary gets faster mediocrity. The work you did for craft reasons just became leverage.