Empowering Your Readings, One Backend at a Time
Developed with the software and tools below.
BookStore-backend is a server-side application that powers an online bookstore. It leverages Node.js and Express for handling HTTP requests, interfaces with MongoDB for data management, and utilizes JSON Web Tokens for user authentication. Hosted on fly.io, and dockerized for streamlined deployment, the project ensures secure, responsive browsing, user authentication and interaction with diverse book inventory via Google Books API integration. Live demo
Feature | Description | |
---|---|---|
βοΈ | Architecture | The project follows an MVC architecture, with a clear separation between data management and application layers. Built on Node.js and Express.js |
π© | Code Quality | Logical layout, consistent coding style, and clear comments suggest good code quality. |
π | Documentation | Lacks proper documentation, explanations about the API routes, or comments in the code make it a challenge to understand the business logic. |
π | Integrations | Key integrations include MongoDB for data storage, Google Books API for book searching, and fly.io platform for deployment. |
𧩠| Modularity | Code is structured into modules for ease of maintenance and reuse, promoting good modularity and reusability. |
π§ͺ | Testing | Uses Jest for testing in conjunction with supertest for endpoint testing and jsdom for JavaScript testing in a browser-like environment. |
β‘οΈ | Performance | CPU and memory allocation managed by the fly.toml configuration file ensuring good performance. |
π‘οΈ | Security | Implemented security measures include jsonwebtoken for access control, bcrypt for password hashing, and cors to prevent cross-site request forgery attacks. |
π¦ | Dependencies | Key dependencies: toml, axios, mongodb-memory-server, mongoose, express, jsonwebtoken, and bcrypt. |
π | Scalability | Able to handle increased traffic due to event-driven, non-blocking nature of Node.js. Architecture allows easy scaling horizontally. |
βββ BookStore-backend/
βββ Dockerfile
βββ README.md
βββ dist
β βββ assets
β β βββ bookStoreListTransparent-xv8MKAH4.gif
β β βββ bookStoreSearchResultTransparent-0kovegeJ.gif
β β βββ bookStoreSearchTransparent-Ft5nrM7Q.gif
β β βββ favicon-mnqlIUdA.ico
β β βββ fewBooksLeftTransparent-nOddKqCy.png
β β βββ fewBooksRightTransparent-3BRpY0za.png
β β βββ index-Vetnxr0g.js
β β βββ index-viiGMvsL.css
β β βββ stackOfBooksTransparent-325Lcrd2.png
β β βββ stack_of_books_transparent-65z_GRK_.png
β βββ index.html
βββ fly.toml
βββ index.js
βββ jest.config.js
βββ package-lock.json
βββ package.json
βββ requests
β βββ get_all_books.rest
β βββ post_new_book.rest
βββ src
βββ controllers
β βββ GoogleBooks.js
β βββ History.js
β βββ Login.js
β βββ Users.js
β βββ Wishlist.js
βββ models
β βββ user.js
βββ utils
βββ verify.js
.
File | Summary |
---|---|
fly.toml | This code is a configuration file for the bookstore-backend application, hosted on the fly.io platform. It determines the primary server region, server ports, and other environment variables, like Google Books API's URL. It aids in managing HTTP services, like enforcing HTTPS and controlling server behavior. Plus, it sets parameters for the virtual machine, such as CPU and memory allocation. All these contribute to maintaining the backend's performance and functionality. |
Dockerfile | The code snippet is a Dockerfile that defines the process for creating a Docker image for the BookStore-backend application. It adopts a multi-stage build process to reduce the final image size. After setting a working directory, defining environment variables, and installing necessary dependencies, it copies and installs the application code. Lastly, it exposes port 3000 and sets the default command to start the server using Node.js. |
package.json | The specified code represents the package.json from the BookStore-backend repository. It outlines key details about this application, including its name, version, and main file. It also contains the scripts for development and testing. The projectβs dependencies highlight that it is a Node.js application, using express for handling requests, mongoose for interacting with MongoDB, and jsonwebtoken for user authentication. The devDependencies specify tools used for development, including jest for testing and nodemon for continuous server updates. |
index.js | The code initiates the backend of a Bookstore application, which links to a MongoDB database and enables different API routes for GoogleBook search, user management, login, browsing history, and wishlist. It uses Express for server operations, applies middlewares for CORS, static file serving, and JSON parsing, and depends on environment variables for configuration. |
jest.config.js | This jest.config.js file is the configuration setup for the Jest testing framework used in the BookStore-backend repository. Its purpose is to specify running Jest tests in a Node.js environment, crucial for testing the Node.js backend functionalities such as controllers for GoogleBooks, History, Login, Users, and Wishlist, and the utility functions. |
package-lock.json | This code snippet is part of the structure of BookStore-backend. It defines the organization of various elements and files, like the Dockerfile for containerization, README, and a dist directory that contains assorted assets such as imagery and icons. It is crucial for understanding and navigating the repository's structure as it provides a visual overview of the backend codebase for the BookStore application. |
requests
File | Summary |
---|---|
get_all_books.rest | This code snippet details an API endpoint that's central to the BookStore's backend repository. Its primary function is to retrieve all books in the database, serving as a crucial medium for any front-end calls desiring a full list of the available books. It structures the server's responses and its interactions with the book data model. |
post_new_book.rest | The code snippet is a RESTful request script from the BookStore-backend repository. It is used for adding a new book to the database using the POST method. This occurs via the /api/books endpoint and is integral for updating the repository's content dynamically. The data structure includes key book fields like title, authors, and identification. |
src.utils
File | Summary |
---|---|
verify.js | This code snippet is found in the verify.js file under utils in the BookStore-backend repository. The function verifyRequest is crucial as it authenticates requests by checking if the incoming request has a valid JSON Web Token. If the token is valid, the function allows the request to proceed; if not, it sends a 401 Unauthorized response. This contributes to the secure operation of the system, ensuring only authorized transactions occur. |
src.models
File | Summary |
---|---|
user.js | This code snippet, located in src/models/user.js, outlines the data model for a User within the BookStore-backend repository. Each User has unique username, password hash, history and wishlist attributes. The history and wishlist both include arrays of book objects. A special transformation occurs when converting a User object to JSON to safeguard sensitive data, such as password hashes, from exposure. The User schema uses a unique validator to ensure usernames are distinct. |
src.controllers
File | Summary |
---|---|
History.js | This code in History.js is part of the BookStore-backend repository, which predominantly serves as the backend for a book store application. Specifically, History.js handles operations related to a user's books history in the Book Store. |
Users.js | The Users.js in the src/controllers directory handles user-related functionalities in the BookStore-backend repository. It includes critical features like user creation with hashed passwords, retrieval of all users, deletion of all users, or a single user by id. The code mainly helps in managing user data with proper security measures and exposes necessary routes for the app's frontend. |
Login.js | The referenced snippet, found in src/controllers/Login.js, is integral to user authentication in the BookStore-backend repository. It securely handles user login requests by verifying the user's credentials, generates a JWT for authenticated users, and returns the token along with user information in response. Incorrect credentials result in an error message. The JWT expiration time is set to one hour. |
GoogleBooks.js | The GoogleBooks.js script is an integral part of the backend application within the context of the BookStore system. This file creates a router leveraging Express.js to fetch book data from Google Books API based on user's search keywords or a specific book ID. Besides the basic information, it also scrapes and manipulates raw HTML data to extract book descriptions. In case of errors, it responds with an internal server error message. |
Wishlist.js | The code in the Wishlist.js file plays a key role in the BookStore-backend repository, primarily responsible for managing user wishlists. Within the broader architecture, it interfaces with the user model and handles fetch, add, and delete operations for books on the user's wishlist. |
Requirements
Ensure you have the following dependencies installed on your system:
- JavaScript:
version x.y.z
- Clone the BookStore-backend repository:
git clone https://github.com/uliba3/BookStore-backend
- Change to the project directory:
cd BookStore-backend
- Install the dependencies:
npm install
Use the following command to run BookStore-backend:
node app.js
To execute tests, run:
npm test
-
βΊ INSERT-TASK-1
-
βΊ INSERT-TASK-2
-
βΊ ...
Contributions are welcome! Here are several ways you can contribute:
- Submit Pull Requests: Review open PRs, and submit your own PRs.
- Join the Discussions: Share your insights, provide feedback, or ask questions.
- Report Issues: Submit bugs found or log feature requests for Bookstore-backend.
Contributing Guidelines
- Fork the Repository: Start by forking the project repository to your GitHub account.
- Clone Locally: Clone the forked repository to your local machine using a Git client.
git clone https://github.com/uliba3/BookStore-backend
- Create a New Branch: Always work on a new branch, giving it a descriptive name.
git checkout -b new-feature-x
- Make Your Changes: Develop and test your changes locally.
- Commit Your Changes: Commit with a clear message describing your updates.
git commit -m 'Implemented new feature x.'
- Push to GitHub: Push the changes to your forked repository.
git push origin new-feature-x
- Submit a Pull Request: Create a PR against the original project repository. Clearly describe the changes and their motivations.
Once your PR is reviewed and approved, it will be merged into the main branch.
This project is protected under the SELECT-A-LICENSE License. For more details, refer to the LICENSE file.
- List any resources, contributors, inspiration, etc. here.