# Getting Started

## What This Project Does

This project is a small console-based library management app. It lets users add books, register members, borrow and return books, and view active loans. The code is intentionally lightweight and uses in-memory storage, so it is easy to understand and extend.

## Recommended Reading Order

1. **`overview.md`** — start with the big-picture description of the application and module layout.
2. **`ui.md`** — read next to understand the menu flow and how user actions enter the system.
3. **`service.md`** — then review the business logic that powers book, member, and loan operations.
4. **`repository.md`** and **`model.md`** — finish with the storage and domain objects that the services depend on.
5. **`util.md`** — read this last for the console input helper used by the UI.

## Key Entry Points

The most important classes to understand first are:

- [`Main.java`](Main.java) — application bootstrap and wiring.
- [`ui/ConsoleUI.java`](ui/ConsoleUI.java) — console menu and request handling.
- [`service/LibraryService.java`](service/LibraryService.java) — book and member operations.
- [`service/LoanService.java`](service/LoanService.java) — borrow/return workflow and active loan tracking.
- [`repository/BookRepository.java`](repository/BookRepository.java) — in-memory book storage.
- [`repository/MemberRepository.java`](repository/MemberRepository.java) — in-memory member storage.
- [`model/Book.java`](model/Book.java) — book state and availability.
- [`model/Loan.java`](model/Loan.java) — loan lifecycle and return behavior.
- [`model/Member.java`](model/Member.java) — member identity and contact data.
- [`util/InputUtils.java`](util/InputUtils.java) — shared console input helper.

A quick way to orient yourself is to trace one flow end-to-end: `Main.java` -> `ui/ConsoleUI.java` -> `service/*` -> `repository/*` -> `model/*`.

## Project Structure

The codebase is organized into a simple layered structure:

```mermaid
flowchart TD
    Start["Start here"] --> Main["Main.java"]
    Main --> UI["ui/ConsoleUI.java"]
    UI --> Service["service/LibraryService.java and service/LoanService.java"]
    Service --> Repo["repository/BookRepository.java and repository/MemberRepository.java"]
    Service --> Model["model/Book.java, model/Loan.java, model/Member.java"]
```

- **Top level**: `Main.java` creates repositories and services, seeds sample data, and starts the console UI.
- **`ui/`**: interactive terminal flow and menu actions.
- **`service/`**: application rules, validation, and orchestration.
- **`repository/`**: in-memory lists and lookup helpers.
- **`model/`**: the core domain objects.
- **`util/`**: small shared helpers for input handling.

## Configuration

There is no large framework configuration in this repository. The main things to know are:

- **`Main.java`** — wires repositories, services, and the UI together.
- **Seed data in `Main.java`** — the app starts with a few example books and members already loaded.
- **`util/InputUtils.java`** — controls how console input is read and validated.

Because persistence is in memory, no database or external config file is required for the current app behavior.

## Common Patterns

A few patterns appear throughout the codebase:

- **Layered design** — UI calls services, services call repositories, repositories work with models.
- **Dependency injection by constructor** — services and the UI receive their dependencies in constructors instead of creating them internally.
- **In-memory collections** — repositories store data in `List` instances, so state is lost when the process exits.
- **Optional for lookups** — repository methods return `Optional` rather than `null` when a record may be missing.
- **Simple console messaging** — services return user-facing success or error strings, and the UI prints them directly.
- **Readable `toString()` methods** — models format themselves for console output, so list views stay simple.

## Where to Start Changing Code

If you are adding a feature, the safest place to begin is usually the service layer. Add or adjust behavior in `service/`, then update `ui/ConsoleUI.java` only if the user flow needs a new menu action or prompt. If you are changing how data is stored or queried, update the repository layer next and keep the models focused on state.
