# nayak-sahil/bookshelf-system architecture

> Architecture diagram of the GitHub repository nayak-sahil/bookshelf-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nayak-sahil/bookshelf-system
- Repository: https://github.com/nayak-sahil/bookshelf-system

## Overview

##### Project type and purpose
- This is a backend library management system implemented in Node.js.
- Core functionality revolves around managing books, inventory operations, library operations (borrow/return), and transaction logging.
- No external UI or database is included—data is held in memory within the modules.

##### Main components
a. Data Models (Domain Layer)
- Book Module (book.js) – defines the Book entity (ISBN, title, author, year, copies)
- Transaction Module (transaction.js) – defines borrow/return transaction details
b. Business-Logic Services (Service Layer)
- Inventory Module (inventory.js) – add/find/modify Book instances, check availability
- Library Module (library.js) – borrowBook(), returnBook(), listAvailable()
- TransactionManager Module (transactionManager.js) – record and retrieve Transaction logs
c. (Optionally) Test Suite

##### Relationships & interactions
- Inventory → Book
- Library → Inventory
- Library → TransactionManager
- TransactionManager → Transaction

##### Important architectural patterns & principles
- SOLID: Each module has a single responsibility.
- Dependency Injection (at runtime, modules import only what they need).
- Layered architecture: Domain → Services → (Client).

##### Technologies & environment
- Node.js runtime (CommonJS modules)
- In-memory data structures (no external DB in code)
- Jest/Mocha (test framework; coverage reports).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Domain Layer
    subgraph "Domain Layer"
        direction TB
        Book["Book Module (book.js)"]:::domain
        Transaction["Transaction Module (transaction.js)"]:::domain
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        Inventory["Inventory Service (inventory.js)"]:::service
        Library["Library Service (library.js)"]:::service
        TransactionManager["TransactionManager Service (transactionManager.js)"]:::service
    end

    %% Test Suite
    subgraph "Test Suite"
        direction TB
        TestSuite["Test Suite (test/)"]:::test
        bookTest["book.test.js"]:::test
        transactionTest["transaction.test.js"]:::test
        inventoryTest["inventory.test.js"]:::test
        libraryTest["library.test.js"]:::test
        transactionManagerTest["transactionManager.test.js"]:::test
    end

    %% Client
    Client["Client (CLI/API)"]:::client

    %% Relationships
    Inventory -->|"constructs/uses"| Book
    TransactionManager -->|"creates/reads"| Transaction
    Library -->|"checkAvailability()/updates"| Inventory
    Library -->|"logTransaction()"| TransactionManager
    Client -->|"invokes operations"| Library

    %% Test relationships (dashed)
    TestSuite --..--> bookTest
    TestSuite --..--> transactionTest
    TestSuite --..--> inventoryTest
    TestSuite --..--> libraryTest
    TestSuite --..--> transactionManagerTest

    bookTest --..--> Book
    transactionTest --..--> Transaction
    inventoryTest --..--> Inventory
    libraryTest --..--> Library
    transactionManagerTest --..--> TransactionManager

    %% Click Events
    click Book "https://github.com/nayak-sahil/bookshelf-system/blob/main/app/book.js"
    click Transaction "https://github.com/nayak-sahil/bookshelf-system/blob/main/app/transaction.js"
    click Inventory "https://github.com/nayak-sahil/bookshelf-system/blob/main/app/inventory.js"
    click Library "https://github.com/nayak-sahil/bookshelf-system/blob/main/app/library.js"
    click TransactionManager "https://github.com/nayak-sahil/bookshelf-system/blob/main/app/transactionManager.js"
    click TestSuite "https://github.com/nayak-sahil/bookshelf-system/tree/main/test/"
    click bookTest "https://github.com/nayak-sahil/bookshelf-system/blob/main/test/book.test.js"
    click transactionTest "https://github.com/nayak-sahil/bookshelf-system/blob/main/test/transaction.test.js"
    click inventoryTest "https://github.com/nayak-sahil/bookshelf-system/blob/main/test/inventory.test.js"
    click libraryTest "https://github.com/nayak-sahil/bookshelf-system/blob/main/test/library.test.js"
    click transactionManagerTest "https://github.com/nayak-sahil/bookshelf-system/blob/main/test/transactionManager.test.js"

    %% Styles
    classDef domain fill:#cce5ff,stroke:#004085,color:#004085;
    classDef service fill:#d4edda,stroke:#155724,color:#155724;
    classDef test fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
    classDef client fill:#fff3cd,stroke:#856404,color:#856404;
```
