📄 This README is also available in Spanish 🇪🇸
A simple and interactive Library Booking Single Page Application (SPA) built with vanilla JavaScript, HTML, and CSS. Users can register, log in, reserve books, and manage reservations. Librarians can add, edit, and delete books. Uses json-server as a mock backend.
View of the SPA as a visitor (role: visitor).
- User registration and login with role validation.
- Interface adapts to a user role (
visitororlibrarian). - Book reservation with automatic stock updates.
- Cancel reservations.
- Full CRUD for books (librarians only).
- Global view of reservations with filters by book or user.
git clone https://github.com/your-username/library-booking-spa.git
cd library-booking-spanpm installnpm run serverThis will launch a JSON server at: http://localhost:3000
In another terminal, run:
npm run devThis will start the SPA in development mode using Vite. Open your browser at: http://localhost:5173
- Displays two buttons: Log In and Register.
- Direct navigation to protected routes is blocked if not logged in.
- Anyone can register with:
- Name
- Password
- Role (
visitororlibrarian)
- The email must be unique.
- After registering, the session is saved and the user is redirected to the dashboard.
- User must enter email and password.
- If credentials are valid, the user is redirected to the dashboard.
The content varies depending on the user role:
- Available Books: lists all available books.
- If a book has copies (
available > 0) and hasn't been reserved by the user, it can be reserved. - When reserving:
- The available count is decreased by 1.
- The reservation is stored for the user.
- If a book has copies (
- My Reservations: shows books reserved by the visitor.
- Reservations can be canceled (increasing availability).
- Book Catalog:
- Lists all registered books.
- Allows creation, editing, and deletion of books.
- Deleting a book also removes its reservations.
- All Book Reservations:
- Displays a grouped list of reservations by book.
- Supports filtering by book title or user.
- Each group shows the book and users who reserved it.
- Email:
carlos@library.com - Password:
admin123
- Email:
ana@books.com - Password:
visitor123
- Vite for development tooling.
- Vanilla JavaScript (no frameworks).
- json-server for a mock backend.
- SweetAlert2 for interactive alerts.
library-booking-spa/
├── public/ # Public static files
├── src/ # Main source code
│ ├── assets/ # Static assets (e.g., images)
│ │ └── img/
│ ├── auth/ # User login and registration
│ │ ├── login.js
│ │ └── register.js
│ ├── books/ # Book management
│ │ ├── bookForm.js
│ │ └── bookList.js
│ ├── reservations/ # Reservation features
│ │ ├── myReservations.js
│ │ ├── reservationAdmin.js
│ │ └── reservationList.js
│ ├── router/ # SPA routing system
│ │ └── router.js
│ ├── services/ # API functions
│ │ └── api.js
│ ├── utils/ # Helpers (e.g., session management)
│ │ └── session.js
│ ├── views/ # Main views
│ │ ├── dashboard.js
│ │ ├── home.js
│ │ └── notFound.js
│ ├── main.js # Main entry point
│ └── style.css # Global styles
├── db.json # Mock database (json-server)
├── index.html # Main HTML file
├── .gitignore # Git ignored files
├── package.json # Project dependencies and scripts
├── package-lock.json # Locked dependencies
├── README.md # This file
└── README.es.md # README in Spanish
- Node.js ≥ 18
- npm ≥ 9
- Session is stored in
localStorage. - Users can't reserve the same book more than once.
This project is licensed under the MIT License.
