An open API service indexing awesome lists of open source software.

https://github.com/abdulrhmangoni/am-store-server

The server side (API) of "AM Store" project
https://github.com/abdulrhmangoni/am-store-server

api apitesting backend database docker docker-compose e-commerce-project javascript jest-tests mongodb mongoose nodejs server-side web web-application web-development

Last synced: 3 months ago
JSON representation

The server side (API) of "AM Store" project

Awesome Lists containing this project

README

        

# AM Store's Server (API)

## Description

This is the server side or the **Back End** of **AM Store** project (e-commerce),

Which is the server that handles the business logic of the e-commerce and provides the services to the clients
([**AM Store** Client site](https://github.com/AbdulrhmanGoni/AM-store-client) and
[**AM Store** Admin Pandel](https://github.com/AbdulrhmanGoni/AM-store-admin)).

## Technologies :hammer_and_wrench:

- JavaScript
- Node.js
- Express.js
- MongoDB
- Mongoose
- Docker
- Jest
- Supertest

## Architecture :memo:

This **API** is a `RESTful API`, And it follows the `MVC` architectural pattern for separation of concerns and organizing the code to make it more modular, maintainable and easier to test.

## Install and Get Started :rocket:

### Requirements

This project built with the Javascript Runtime Environment `Node.js` and `Docker`,

So you need to have `Node.js` and `Docker` installed in your machine to be able to install the project and run it.

- If you don't have `Node.js`, Go to [the official website of Node.js](https://nodejs.org/en/download) and install it.

- If you don't have `Docker`, Go to [Docker official website](https://docs.docker.com/engine/install/) and install it.


Follow these steps to install and run AM Store's Server in your machine :point_down::

### Clone the repository on your machine

Open the terminal on your machine whenever you want and run the following command to clone the repository:

```
git clone https://github.com/AbdulrhmanGoni/AM-store-server.git
```

### Prepare running environment

First open `AM-store-server` folder by running this command

```
cd AM-store-server
```

And then create `.env.development` files using the following command:

If you use **Linux** or **Mac** operating systems run this command:

```
touch .env.development
```

If you use **Windows** operating system run this command:

```
echo "" > .env.development
```

Open `.env.development` file and add these variables to it:

> [!NOTE]
> You can left these variables empty and go to [run the server](#run-the-server) directlty in development mode
> and it will work, but know that there are some features and functionalites may don't work because the variables
> that they depend on are missing.

```
HASHING_SALT_ROUNDS=
JWT_SECRET_KEY=""
STORE_EMAIL=""
EMAIL_APP_PASSWORD=""
VERIFY_EMAIL_API_KEY=""
DB_CONNECTION_TYPE=""
DB_USERNAME=""
DB_PASSWORD=""
DB_NAME=""
DB_HOST=""
REDIS_CONNECTION_TYPE=""
REDIS_USERNAME=""
REDIS_PASSWORD=""
REDIS_HOST=""
REDIS_PORT=
```

A quick description of these environment variable:
| VARIABLE | DESCRIPTION |
| --- | --- |
| HASHING_SALT_ROUNDS | The number rounds that hashing algorithm should take to encrypt users paswords |
| JWT_SECRET_KEY | The secret key of the tokens that will used to generat users access tokens |
| STORE_EMAIL | The official email of the store |
| EMAIL_APP_PASSWORD | The pasword of the app that should be created from Google cloud platform for store's email |
| VERIFY_EMAIL_API_KEY | The API key of [hunter.io platform](https://hunter.io/) for using **Email Verifier** service to verify users emails existence |
| DB_CONNECTION_TYPE | Specifies how the server connects to the database (use "remote" or let it empty) |
| DB_USERNAME | The name of the user who has access to the mongo database of the project (**it used only if `DB_CONNECTION_TYPE` variable is specified to "remote"**) |
| DB_PASSWORD | The password of the user who has access to the mongo database of the project (**it used only if `DB_CONNECTION_TYPE` variable is specified to "remote"**) |
| DB_NAME | The name of the mongo database of the project (**it used only if `DB_CONNECTION_TYPE` variable is specified to "remote"**) |
| DB_HOST | The host name of the database of the project, in other words, where is the database hosted?, (**it used only if `DB_CONNECTION_TYPE` variable is specified to "remote"**) |
| REDIS_CONNECTION_TYPE | Specifies how the server connects to redis database (use "remote" or let it empty) |
| REDIS_USERNAME | The name of redis database that used for caching in the project (**it used only if `REDIS_CONNECTION_TYPE` variable is specified to "remote"**) |
| REDIS_PASSWORD | The password of redis database that used for caching in the project (**it used only if `REDIS_CONNECTION_TYPE` variable is specified to "remote"**) |
| REDIS_HOST | The host name of redis database, in other words, where is redis database hosted?, (**it used only if `REDIS_CONNECTION_TYPE` variable is specified to "remote"**) |
| REDIS_PORT | The port that redis database should listen to (**it used only if `REDIS_CONNECTION_TYPE` variable is specified to "remote"**) |

### Run the server

Run the server using the following command:

```
npm run docker-dev
```

And congratulations 🎉, Your AM Store Server is up and running on your http://localhost:7000.

## Endpoints & Documentation :ledger:

You can browse the **Endpoints** and the **Documentation** of the **API** on **Postman** :point_down:

[Run In Postman](https://app.getpostman.com/run-collection/27040994-2b37c7cf-3a2d-4022-9dfa-6b850399d269?action=collection%2Ffork&source=rip_markdown&collection-url=entityId%3D27040994-2b37c7cf-3a2d-4022-9dfa-6b850399d269%26entityType%3Dcollection%26workspaceId%3Db9135996-e8d9-4c02-bc81-d0b278bfc9ff)

## Authentication :key:

This **API** uses **JSON Web Tokens ( JWT JWT Icon )** for users authentication.

Users can log in or sign up with their credentials (e.g., email and password or google authentication)
to obtain a **JWT token**, And then this token will be included in subsequent requests to authenticate the user
and authorize him to access the protected resources (e.g his data, orders, shopping cart, favorites, etc. ).

## Tests :test_tube:

This project uses a combination of unit and integration tests written with [`Jest`](https://jestjs.io)
to test the functionality of the API.

### Running The Tests:

To run all tests use the following command:

```
npm test
```

To run specific tests files add an argumant matches files names, For example `orders`

```
npm test orders
```

To run a specific tests file add the full name of the file as an argumant, For example `products_addDiscount_post`

```
npm test products_addDiscount_post
```

### Tests Code Coverage Report:

![code coverage badges](https://raw.githubusercontent.com/AbdulrhmanGoni/AM-store-server-tests-code-coverage-report/main/tests-code-coverage-report/badges.svg)

You can go to [tests code coverage report stie](https://abdulrhmangoni.github.io/AM-store-server-tests-code-coverage-report) to see the full information about tests code coverage report of this project.

> [!NOTE]
> The tests code coverage report created by [`Jest`](https://jestjs.io) and [`Istanbul`](https://istanbul.js.org/).

### Tests in CD pipline:

Tests process is included in `continuous-deployment.yml` workflow to ensure that all tests passed successfully
and the new changes didn't make any errors before building and deploying the project to production environment.

If all tests in `continuous-deployment.yml` workflow passed successfully, `Jest` using `istanbul` will create
a new code coverage report for the tests and this new report will be pushed to [`AM-store-server-tests-code-coverage-report`](https://github.com/AbdulrhmanGoni/AM-store-server-tests-code-coverage-report) repository.

## Feedbacks :incoming_envelope:

I welcome any feedback or suggestions you might have!

if you faced any problem in the project or you have any suggestion improves it,
or even you have some advices to improve me and my skills,

Please feel free to open an issue and discuss it with me or contact me directly on [my LinkedIn account](https://www.linkedin.com/in/abdulrhman-goni-857a36275/)
or throuth my email [email protected]

Thank you for stopping by! 🌟