Skip to content

AbdulrhmanGoni/AM-store-server

Repository files navigation

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 and AM Store Admin Pandel).

Technologies 🛠️

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

Architecture 📝

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 🚀

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.


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

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 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=""
DATABASE_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 for using Email Verifier service to verify users emails existence
DB_USERNAME The name of the user who has access to the mongo database of the project
DB_PASSWORD The password of the user who has access to the mongo database of the project
DB_NAME The name of the mongo database of the project
ATLAS_CLUSTER The name of the atlas cluster that hosts the mongo database
REDIS_USERNAME The name of redis database that used for caching in the project
REDIS_PASSWORD The password of redis database that used for caching in the project
REDIS_HOST The host name of redis database
REDIS_PORT The port that redis database should listen to

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 📒

You can browse the Endpoints and the Documentation of the API on Postman 👇

Run In Postman

Authentication 🔑

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 🧪

This project uses a combination of unit and integration tests written with Jest 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

You can go to tests code coverage report stie to see the full information about tests code coverage report of this project.

Note

The tests code coverage report created by Jest and Istanbul.

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 repository.

Feedbacks 📨

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 or throuth my email abdulrhmangoni@gmail.com

Thank you for stopping by! 🌟