Skip to content

Build a Storefront Backend - Advanced Web Development egFWD - Second Project

Notifications You must be signed in to change notification settings

ibrahimelmokhtar/ts-online-store-api

Repository files navigation

Online Store API

Build a Storefront Backend - Advanced Web Development egFWD - Second Project

This project was structured from scratch, with ZERO starter files.

Table of Contents

Installation

(Back to top)

To use this project, you need to follow the commands below:

  1. Clone the repository into your local machine:

    git clone https://github.com/ibrahimelmokhtar/ts-online-store-api.git
  2. Redirect inside the cloned repository:

    cd ts-online-store-api/
  3. Install the required packages:

    npm install
  4. Copy example.env file into .env file.

  5. Fill the created .env file with corresponding/appropriate information.

  6. For applying configured styling, run the following commands:

    • Prettier styling:

      npm run prettier
    • ESLint styling:

      npm run lint
  7. For manipulating the database, run the following commands:

    • Run Up Migrations:

      npm run migration:run
    • Run Down Migrations:

      npm run migration:reset
  8. For working on the development phase, run the following commands:

    • Live debugging while development:

      npm run watch
    • Jasmine Testing:

      npm run test
  9. For working with the production phase, run the following commands:

    • Build the project:

      npm run build

      Then, Run the compiled server:

      node build/server.js
    • OR simply, Start the server with one command:

      npm run start
  10. Open the local website on http://127.0.0.1:5000/{endpoint}/{:queryParameters}, more information about {endpoint} and {:queryParameters} will be explained in API Docmentation

Development

(Back to top) This section will explain how the code works and how everything is put together.

Architecture

(Back to top)

This project has the structure shown below:

Project Structure
├─── docs/
    ├─── REQUIREMENTS.md
├─── migrations/
    ├─── sqls/
        ├─── 20220505125703-users-table-down.sql
        ├─── 20220505125703-users-table-up.sql
        ├─── 20220507132301-products-table-down.sql
        ├─── 20220507132301-products-table-up.sql
        ├─── 20220508135120-orders-table-down.sql
        ├─── 20220508135120-orders-table-up.sql
        ├─── 20220508135656-order-products-table-down.sql
        ├─── 20220508135656-order-products-table-up.sql
    ├─── 20220505125703-users-table.js
    ├─── 20220507132301-products-table.js
    ├─── 20220508135120-orders-table.js
    ├─── 20220508135656-order-products-table.js
├─── spec/
    ├─── support/
        ├─── jasmine.json
├─── src/
    ├─── config/
        ├─── env.config.ts
        ├─── server.config.ts
    ├─── constants/
        ├─── order.type.constant.ts
        ├─── orderProduct.type.constant.ts
        ├─── product.type.constant.ts
        ├─── unique.uuid.constant.ts
        ├─── user.type.constant.ts
    ├─── controllers/
        ├─── dashboard.controller.ts
        ├─── orderProducts.controller.ts
        ├─── orders.controller.ts
        ├─── products.controller.ts
        ├─── users.controller.ts
    ├─── database/
        ├─── __tests__/
            ├─── index.spec.ts
        ├─── index.ts
    ├─── helpers/
        ├─── guards/
            ├─── compare.ts
            ├─── encrypt.ts
        ├─── testing/
            ├─── reporter.ts
    ├─── middlewares/
        ├─── authentication.middleware.ts
        ├─── validation.middleware.ts
    ├─── models/
        ├─── __tests__/
            ├─── index.spec.ts
            ├─── order.model.spec.ts
            ├─── orderProduct.model.spec.ts
            ├─── product.model.spec.ts
            ├─── user.model.spec.ts
        ├─── order.model.ts
        ├─── orderProduct.model.ts
        ├─── product.model.ts
        ├─── user.model.ts
    ├─── routes/
        ├─── __tests__/
            ├─── dashboard.routes.spec.ts
            ├─── index.spec.ts
            ├─── orderProducts.routes.spec.ts
            ├─── orders.routes.spec.ts
            ├─── products.routes.spec.ts
            ├─── users.routes.spec.ts
        ├─── api/
            ├─── dashboard.routes.ts
            ├─── orderProducts.routes.ts
            ├─── orders.routes.ts
            ├─── products.routes.ts
            ├─── users.routes.ts
        ├─── index.ts
    ├─── schemas/
        ├─── orderProducts.schemas.ts
        ├─── orders.schemas.ts
        ├─── products.schemas.ts
        ├─── users.schemas.ts
    ├─── services/
        ├─── __tests__/
            ├─── dashboard.services.spec.ts
        ├─── dashboard.services.ts
    ├─── types/
        ├─── __tests__/
            ├─── index.spec.ts
            ├─── order.type.spec.ts
            ├─── orderProduct.type.spec.ts
            ├─── product.type.spec.ts
            ├─── user.type.spec.ts
        ├─── dashboard/
            ├─── ordersPerUser.type.ts
            ├─── productsInOrder.type.ts
            ├─── topProduct.type.ts
        ├─── order.type.ts
        ├─── orderProduct.type.ts
        ├─── product.type.ts
        ├─── user.type.ts
    ├─── server.ts
├─── .eslintrc
├─── .gitignore
├─── .prettierrc
├─── database.json
├─── example.env
├─── package.json
├─── README.md
├─── tsconfig.json

API Documentation

(Back to top)

For more information about available endpoints, check this REQUIREMENTS.md file.

Installed NPM Packages

(Back to top)

These packages are required to run this project smoothly without any errors.

Production Packages

These packages can be found in the "dependencies" object inside the package.json file.

  • bcrypt - A bcrypt library for NodeJS.
  • cors - Node.js CORS middleware.
  • db-migrate - Database migration framework for node.js.
  • db-migrate-pg - A postgresql driver for db-migrate.
  • dotenv - Loads environment variables from .env file.
  • express - Fast, unopinionated, minimalist web framework.
  • express-validator - Express middleware for the validator module.
  • helmet - Help secure Express/Connect apps with various HTTP headers.
  • jsonwebtoken - JSON Web Token implementation (symmetric and asymmetric).
  • morgan - HTTP request logger middleware for node.js.
  • pg - PostgreSQL client.
  • uuid - RFC4122 (v1, v4, and v5) UUIDs.

Development Packages

These packages can be found in the "devDependencies" object inside the package.json file.

Useful Resources

(Back to top)