Skip to content

This repository is backend service that must follow this requirements:

License

Notifications You must be signed in to change notification settings

matheusfcorocher/shopping-cart

Repository files navigation

shopping-cart

This repository is backend service that must follow this requirements:

  • return available products list and its quantitity in stock.
  • return the actual cart(which products and how many products it has, applied voucher if has some, subtotal value, delivery cost, ...)
  • add products in cart(when adding it for the first time or adding more times)
  • remove products from cart(if quantity is 0 of product, should be remove from cart)
  • apply voucher in cart
  • remove applied voucher from cart
  • finish purchase

In short answer, must attend this gist: Gist

Features

Clean Architecture
This project architecture use principles of Clean Architecture focused on codebase scalability.
Domain Driven Design(DDD)
Uses DDD approach to reduce domain complexity and focus the development in domain model.
Uses Money Pattern
Uses Dinero.js for money exchange that follows the Money Pattern of Martin Fowler in the book Patterns of Enterprise Application Architecture.
Dependency injection
Use the technique dependency injection for code not be coupled and make easy to mock dependencies during the tests.
Web Framework
Use Fastify for requests routing and middlewares. And also uses fastify-swagger for creating a doc with SwaggerUI.
Database
Use Postgres as relational database.
Database integration
Objection, an ORM for SQL databases, is already integrated. But needs to configure some aspects to use it.
CLI integration
Use Knex for both the application and Objection have command-line tools to make it easy to work with them. Check the Scripts section to know more about this feature.
Configurations
Use Config for easily switch development and test environments, Dotenv package for loading environmental variables from .env file for config file. And uses Cross-env to run linux commands style in any OS.
Prepared for testing
The test suite uses Jest as test runner and is prepared to run unit, integration and functional tests right from the beginning. In integration and functional testes use Supertest to make HTTP tests. There are helpers to make it easy to make requests to the web app during the tests and for cleaning the database after each test.
Compile Tyscript to Javascript
Use ts-node-dev for compile typescript code to javascript to NodeJS runs it. And also to automatically reload the server after a file change when on development mode, makes the development faster and easier

Quick start

  1. Do you need a POSTGRES server installed in your machine. I suggest to use this tools: Postbird for verify your Postgres Database and Postman to access the routes of API.
  2. Clone the repository with git clone https://github.com/matheusfcorocher/shopping-cart.git
  3. Setup the database on .env and also ./src/infra/database/config.ts.
  4. Install the dependencies with yarn (click here if you don't have Yarn installed) in your bash terminal
  5. Create the development and test databases you have setup on ./src/infra/database/config.ts.
  6. Run the database migrations with yarn knex migrate:latest. The default environment is dev. To create database for test, change development env for testing env.
  7. Add some seed data to the development database with knex seed:run
  8. Run the application in development mode with yarn build then yarn start
  9. Access http://localhost:5000/api/ and you're ready to go!

Aditional info:

  • Don't forget to run the migrations for the test environment as well (including when you create a new migration) with yarn knex migrate:latest

Scripts

This api comes with a collection of npm scripts to make your life easier, you'll run them with npm run <script name> or yarn <script name>:

  • knex: Run commands with knex.
  • build: Transpile the ts files to js in builder folder.
  • start: Start the development server with Node.js
  • tsnd: Run a file with typescript ts-node-dev
  • test: Run all tests suite with option --runInBand and NODE_ENV=test

Endpoints of this api and requirements

  1. To see all endpoints of this api, you should run yarn build then yarn start.
  2. After initialize the server you go to address http://localhost:5000/api/docs to see all routes of api in Swagger UI.

About

This repository is backend service that must follow this requirements:

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages