/Books-Directory-v2

Full stack MERN Book Directory web app with JWT authentication. Uses RESTful API in the backend.

Primary LanguageTypeScriptApache License 2.0Apache-2.0

Welcome to Book Directory (RESTful API version)👋

Book Directory is a full stack MERN app with the following features:
  • Provides user signup and sign in.
  • Provides features which lets the user add, edit, remove and view books.
  • Provides protected APIs that means no unauthorized user can have access to protected resources.


Table of contents

  1. Getting Started
  2. Demo
  3. The src folder
  4. The database
  5. Installation
  6. Configuration
  7. Start up
  8. Launching in browser
  9. License
  10. Author



Getting started


The backend

The app uses a Mysql database, TypeORM,and RESTful APIs in the backend. The backend is structured using MVC pattern, and uses entities and repository pattern.

Some of the backend endpoints are public and others are protected. That means no unauthorized user can have access to protected resources. This is achieved by the use of access token for authorizing client requests.


The frontend

The frontend is build using react and uses react router dom library for navigating between different web pages without reload. And it also usese the axios library for making client requests to the server.


Authorization

The app uses JWT (Json Web Token) for authoirzing the client/user requests to the server. Each client request to the server contains an access token which is used by the server to identify the user.



Demo



The src folder

Backend folder structure:

Backend folder structure


Frontend folder structure:

Frontend folder structure



The database

Users table

CREATE TABLE `Users` (
  `userID` int NOT NULL AUTO_INCREMENT,
  `username` varchar(45) NOT NULL,
  `email` varchar(45) NOT NULL,
  `password` varchar(256) NOT NULL,
  PRIMARY KEY (`userID`)
)

Books table

CREATE TABLE `books` (
  `id` int NOT NULL AUTO_INCREMENT,
  `title` varchar(250) NOT NULL,
  `description` varchar(2000) NOT NULL,
  `coverImage` varchar(250) NOT NULL,
  `userID` varchar(45) NOT NULL,
  PRIMARY KEY (`id`)
)



Installation

  1. Installing dependencies for backend
npm install
  1. Installing dependencies for frontend
cd src/frontend
npm install



Configuration (Enviroment Variables)

Add these keys as environment variable in a .env file.

DB_HOST: loclhost or website url
DB_NAME: Database name
DB_USER: Database user
DB_PASSWORD: Database password
PORT: API server port (8080)
ACCESS_TOKEN_SECRET: Use to sign jwt tokens



Start up


Development mode

To start the project in development mode.

Starting backend:

npm run dev

Starting frontend:

cd src/frontend
npm start

Production

To start the project in production.

Starting backend:

npm run build   <!-- To generate the build -->
npm start

Starting frontend

cd src/frontend
npm start

ES Lint

For generating errors and warnings:

npm run lint



Launching in browser

  1. Frontend: http://localhost:3000/
  2. Backend: http://localhost:8080/
  3. Backend Swagger API docs: http://localhost:8080/api-docs



License

Read more about the license here:
Apache License 2.0



Author

Lokesh Bisht