A modern library management system built with TypeScript, featuring type-safe error handling and a clean OOP architecture. This system allows you to manage books, members, and borrowing operations with built-in business rules enforcement.
- Book Management: Add, search, and track book availability
- Member Management: Register and manage library members
- Borrowing System: Handle book checkouts and returns with automatic availability tracking
- Smart Search: Find books by title, author, or both (case-insensitive)
- Business Rules: Enforce borrowing constraints (e.g., books can't be borrowed if already checked out)
- Type-Safe Error Handling: Leverages Effect library for functional error management
- Comprehensive Testing: Full test suite covering all major behaviors
- Runtime: Bun - Fast all-in-one JavaScript runtime
- Language: TypeScript - Type-safe JavaScript
- Effect Library: Effect - Powerful library for type-safe error handling and dependency management
- Database: SQLite (bun:sqlite) - Embedded, serverless database
- Testing: Bun's built-in test runner
lbs/
├── README.md
├── bun.lock
├── docs
│ └── roadmap.md
├── package.json
├── src
│ ├── database # place for database configuration
│ ├── index.ts # main entry point of the application
│ ├── lib # place for utility functions and helpers
│ ├── modules # place for business logic modules
│ │ ├── book
│ │ ├── borrow-record
│ │ ├── member
│ └── types.ts # place for type definitions
├── tests
│ └── setup.ts # place for test setup and teardown
└── tsconfig.json
- Bun >= 1.0.0
- Clone the repository:
git clone https://github.com/erickhilda/lbs
cd lbs- Install dependencies:
bun install- Initialize the database:
bun run startThe SQLite database will be automatically created with the necessary tables.
bun run start# Run all tests
bun run test
# Run specific test file
bun run test tests/book.test.ts
bun run buildThis creates a standalone binary called library (or library.exe on Windows) that includes everything needed to run - no Bun or Node.js runtime required!
# Linux (x64)
bun run build:linux
# macOS (Intel)
bun run build:mac
# macOS (Apple Silicon)
bun run build:mac-arm
# Windows (x64)
bun run build:windows
# Build for all platforms
bun run build:allThe compiled binary is approximately 50-60MB and includes:
- Your application code
- Bun runtime
- SQLite database engine
- All dependencies
After building, you can run the binary directly:
# On Linux/macOS
./library --help
# On Windows
library.exe --help./library add-book --title "The Great Gatsby" --author "F. Scott Fitzgerald"Aliases:
./library add-book -t "1984" -a "George Orwell"./library add-member --name "John Doe"Aliases:
./library add-member -n "Jane Smith"./library borrow --book-id 1 --member-id 1Aliases:
./library borrow -b 1 -m 1./library return --book-id 1 --member-id 1Aliases:
./library return -b 1 -m 1Search by title:
./library search --title "Gatsby"Search by author:
./library search --author "Orwell"Search by both:
./library search --title "Great" --author "Fitzgerald"Aliases:
./library search -t "1984" -a "Orwell"./library member-books --member-id 1Aliases:
./library member-books -m 1./library stats./library list-books# General help
./library --help
# Command-specific help
./library add-book --help
./library borrow --help# 1. Add some books
./library add-book -t "To Kill a Mockingbird" -a "Harper Lee"
./library add-book -t "1984" -a "George Orwell"
./library add-book -t "The Great Gatsby" -a "F. Scott Fitzgerald"
# 2. Add members
./library add-member -n "Alice Johnson"
./library add-member -n "Bob Smith"
# 3. View library stats
./library stats
# 4. Search for books
./library search -a "Orwell"
# 5. Borrow a book
./library borrow -b 1 -m 1
# 6. Check member's borrowed books
./library member-books -m 1
# 7. List all books (see availability status)
./library list-books
# 8. Return the book
./library return -b 1 -m 1
# 9. View updated stats
./library statsThe CLI uses SQLite and stores data in library.db in the same directory as the binary. The database is automatically created on first run.
To start fresh, simply delete the library.db file:
rm library.db