# (DD03) Business Logic — ConsoleUI.addBook() [6 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `ui.ConsoleUI` |
| Layer | UI / Presentation |
| Module | `ui` (Package: `ui`) |

## 1. Role

### ConsoleUI.addBook()

This method implements the console-driven book registration entry point for the library application. It prompts the user for the three business attributes required to create a book record: title, author, and ISBN, and then forwards those values to the application service layer for persistence and object creation. In business terms, it is the user-facing intake step for adding a new catalog item to the library inventory.

The method follows a simple routing/delegation pattern: collect user input in the UI layer, invoke `libraryService.addBook(...)`, and immediately display the created book returned by the service. It does not perform validation, branching, or transformation beyond passing the captured text fields through to the service. As a result, its role in the system is primarily orchestration at the presentation layer, keeping business logic out of the console screen and delegating record creation to `LibraryService`.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START["addBook()"]
    READ_TITLE["Read title from console"]
    READ_AUTHOR["Read author from console"]
    READ_ISBN["Read ISBN from console"]
    CALL_SERVICE["Call libraryService.addBook(title, author, isbn)"]
    PRINT_RESULT["Print Added message with returned book"]
    END_NODE["Return / Next"]
    START --> READ_TITLE
    READ_TITLE --> READ_AUTHOR
    READ_AUTHOR --> READ_ISBN
    READ_ISBN --> CALL_SERVICE
    CALL_SERVICE --> PRINT_RESULT
    PRINT_RESULT --> END_NODE
```

The method executes a straight-line flow with no conditional branches. It reads the book title, author, and ISBN from the console, delegates the create operation to `libraryService.addBook(...)`, and then writes a confirmation message containing the returned book object.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | - |

This method has no formal parameters. It depends on instance state, specifically the injected `libraryService`, and on runtime console input gathered through `InputUtils.readLine(...)`.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|-----------------------|
| C | `libraryService.addBook(title, author, isbn)` | `-` | `Book` | Creates a new book domain object, assigns a generated book ID, and persists it through the repository layer. |

`ConsoleUI.addBook()` itself does not access the database directly. The only business call is the create operation delegated to `LibraryService.addBook(...)`, which constructs the `Book` object and stores it via `BookRepository.add(...)`.

## 5. Dependency Trace

### Pre-computed evidence from code analysis graph:

No screen/batch entry points found within 8 hops. Direct callers found: 2 methods.
Terminal operations from this method: -

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Screen:ConsoleUI | `Main.main` -> `ConsoleUI.menu` -> `ConsoleUI.addBook` | `libraryService.addBook [C] Book` |
| 2 | Screen:ConsoleUI | `ConsoleUI.menu` -> `ConsoleUI.addBook` | `libraryService.addBook [C] Book` |

The method is invoked from the console menu flow in `ConsoleUI`, and the business endpoint reached from this method is the book creation routine in `LibraryService`.

## 6. Per-Branch Detail Blocks

**Block 1** — [SEQUENCE] `(straight-line execution)` (L56-L61)

> Collects book details from the user, delegates creation to the service layer, and prints a confirmation message.

| # | Type | Code |
|---|------|------|
| 1 | SET | `String title = InputUtils.readLine("Title: ");` |
| 2 | SET | `String author = InputUtils.readLine("Author: ");` |
| 3 | SET | `String isbn = InputUtils.readLine("ISBN: ");` |
| 4 | CALL | `libraryService.addBook(title, author, isbn);` |
| 5 | EXEC | `System.out.println("Added: " + ...);` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `title` | Field | Book title entered by the user for catalog registration. |
| `author` | Field | Book author name entered by the user. |
| `isbn` | Field | International Standard Book Number — the external identifier used to uniquely identify the book edition. |
| `libraryService` | Component | Application service that performs book and member business operations. |
| `InputUtils.readLine` | Utility method | Console input helper that captures a line of text from the user. |
| `Book` | Domain entity | Library catalog record representing a book available for storage and retrieval. |
| `Main.main` | Entry point | Application bootstrap method that starts the console UI flow. |
| `ConsoleUI.menu` | UI method | Console menu dispatcher that routes the user to book or member actions. |
