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.
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.
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
💡 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 installTo only install resolved dependencies in package-lock.json:
npm cinpm startYou 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 buildTo force a full build by cleaning up cached artifacts:
npm run rebuildnpm run lint: Fix code style and formatting issuesnpm run lint:fix: To automatically fix code style and formatting issuesnpm run migrate: Migrate database schemas for modelsnpm run openapi-spec: Generate OpenAPI spec into a filenpm run docker:build: Build a Docker image for this applicationnpm run docker:run: Run this application inside a Docker container
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 testsThere are some unit tests in src/__tests__/unit to test specific
functionalities of the app.
To launch them run:
npm run test:unitAcceptance tests are in src/__tests__/acceptance to test the application end-to-end.
To launch them run:
npm run test:acceptanceThe project has 🛕nyc integrated lib to see the test coverage of the application. To see the coverage run:
npm run coverageThe report is generated in /coverage/index.html, open it in your browser.
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
- 🦄 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.
Please check out LoopBack 4 documentation to understand how you can continue to add features to this application.
-@2x.png)