Skip to content

alelit4/pokemon-loopback-api

Repository files navigation

💦🐢 Pokemon api loopback 🔖V.1.0

This application is generated using LoopBack 4 CLI with the initial project layout. The main objective of this is try to solve Challenges Coding Exercise Backend.

With this api you can control all your Pokemons due to some queries related to them, such as: name, type or even if it is one of your favourites or not.

📐 Architecture

The design of this app is based on Clean Architecture. Specific I use Hexagonal Architecture based on the book Growing Object Oriented Software, but with some limitations based on some restrictions of LoopBack framework.

This repository contains the main code of the application in the path /src. However, there is some data related to the model of the api in the path /data/db (that is the base of this). The project has the following layers in /src:

  • controllers: This is the entry-point layer where all the controllers are defined based on the use cases.
  • datasources: This is an infrastructure layer where all the information related with the data source is in. Note that for this application, it's used MongoDB.
  • domain: Here is where the logic of the app goes, such us: models/entities or repository interfaces.
  • repositories: In this layer are the implementations of repositories, this is an infrastructure layer.
  • usecases: This is the layer where is located the communication of infrastructure components and domain elements. In this layer the use cases are located related to the services that allow the communication between ports and adapters.

💡 Note: There is a special file called TechnicalDebt.md where is all the information about some technical debt that appears in the development of this project. I try to keep this file clean, but depends on time limitations.

🚀 Get started

This project is ready to be used with 🐳Docker just changing the name of .env.sample file to .env to load some demo environment variables and then run:

npm run docker:build:run

💡 If you have any problem importing data in mongodb, check the line separator of ./mongo-init.sh, it has to be in Unix/Mac format (\n).

If you want to use this project without 🐳Docker be sure you have installed NodeJs and npm and MongoDB, change the .env and launch the app with npm

📦 Pre-requirements

💡 Tip: Use 🐳Docker, with docker compose you have all the requirements added, but if you want to launch the app isolated without docker read this.

By default, dependencies were installed when this application was generated. Whenever dependencies in package.json are changed, run the following command:

npm install

To only install resolved dependencies in package-lock.json:

npm ci

🔧 Run the application

npm start

You can also run node . to skip the build step.

Open http://127.0.0.1:3000 in your browser.

To incrementally build the project:

npm run build

To force a full build by cleaning up cached artifacts:

npm run rebuild

🌩 Other useful commands

  • npm run lint: Fix code style and formatting issues
  • npm run lint:fix: To automatically fix code style and formatting issues
  • npm run migrate: Migrate database schemas for models
  • npm run openapi-spec: Generate OpenAPI spec into a file
  • npm run docker:build: Build a Docker image for this application
  • npm run docker:run: Run this application inside a Docker container

✔️Tests

In this application all tests are over the path src/__tests__. All the tools related needed to launch them are in src/__tests__/helpers. If you want to run all tests run:

npm run tests

🧨 Unit tests

There are some unit tests in src/__tests__/unit to test specific functionalities of the app. To launch them run:

npm run test:unit

💣 Acceptance tests

Acceptance tests are in src/__tests__/acceptance to test the application end-to-end. To launch them run:

npm run test:acceptance

📊 Coverage

The project has 🛕nyc integrated lib to see the test coverage of the application. To see the coverage run:

npm run coverage

The report is generated in /coverage/index.html, open it in your browser.

🩺 Test suit

There is a command to execute all the test suit with the linter and code tests. To run them execute:

npm test

💡 Note: If you have some errors related to linter run npm run lint:fix --fix to automatically fix code style and formatting issues

🛠️ Tools and dependencies

  • 🦄 LoopBack 4 CLI - The main generator
  • 🍃 MongoDb - The database used
  • 🐳 Docker - For an easy deploy
  • 🛕 nyc - Lib to see the test coverage of the application.

What's next

Please check out LoopBack 4 documentation to understand how you can continue to add features to this application.

LoopBack

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors