Code Monkey home page Code Monkey logo

treetracker-query-api's Introduction

Treetracker Query API

This API exposes a RESTful interface to query the treetracker data, capture, planter and organization and others.

One of query api's client is our web map app: https://github.com/Greenstand/treetracker-web-map-client/

Development toolkit

This repository was created from Greenstand's template for microservice projects. This means it comes with many development tools that we use for development and deployment. As a contributor to this repository, you should learn and use these tools. They are outlined below.

  • Conventional Commits
  • husky
  • prettier / lint
  • github actions
  • Jest
  • TypeScript

Getting Started

Project Setup

Open terminal and navigate to a folder to install this project:

git clone https://github.com/Greenstand/treetracker-repository-name.git

Install all necessary dependencies:

npm ci

Run the server with database settings:

DATABASE_URL=[...] npm run dev

Please join our slack channel to get help with setting up the database.

Workflow with Github

check out here

Development Specification

  • Every endpoint should have a e2e test to cover the main use cases.

  • For edge cases, we can use unit tests to test the edge cases, don't need to use e2e test to cover all cases, e2e just cover main workflow.

  • Class name should be capitalized.

  • Do not write SQL directly in router and model files, there is a function called delegateRepository can help to simplify some simple cases;

  • Please use loglevel to replace console.log, and always use appropriate log level to log.

Architecture of this project

This project use multiple layer structure to build the whole system. The architecture follows some principles of Domain Driven Design. And inspired by this article: https://medium.com/spotlight-on-javascript/domain-driven-design-for-javascript-developers-9fc3f681931a

We compose/build the model instance in a functional style, then execute the business.

  • Protocol layer

I think we can also call it the Application Layer, a term in the DDD, the entry of this project.

This microservice offers RESTFul API interface based on HTTP protocol. We use Express to handle all HTTP requests.

The Express-routers work like the controller role in MVC, they receive the requests and parameters from client, and translate it and dispatch tasks to appropriate business models. Then receive the result from them, translate to the 'view', the JSON response, to client.

  • Model layer

The business model, most of the business logic is here. We are considering put most of the business logic in the model layer. So it should be the thickest layer, including all the business logic, and build up the relationship between models(business).

  • Infrastructure layer

    • Repository layer

      Repository is responsible for communicating with the real database.

      All the SQL statements should be here.

    • Others

      For example, the Message Queue.

About the documentation/specification

We use OpenAPI 3.0 to document the API.

You can copy the yaml file and import to swagger-ui to see the API.

How to test

Unit test

To run the unit tests:

npm run test-unit

End to End test

All the end to end tests are located under folder __tests__/e2e, the test will run against the dev database.

To run the integration test:

Run tests:

npm run test-e2e

If errors:


DATABASE_URL is undefined

or

{ "code": 500,"message": "Unknown error (self signed certificate in certificate chain)" }

Follows those steps:

1- Go to the .env file, copy the DATABASE_URL with its value.

2- Add it with NODE_TLS_REJECT_UNAUTHORIZED='0' , npm run test-e2e, and run the tests.

For example:


DATABASE_URL=[the link provided] NODE_TLS_REJECT_UNAUTHORIZED='0' npm run test-e2e

. . . . . . .

treetracker-query-api's People

Contributors

dadiorchen avatar semantic-release-bot avatar quaidbartolomei avatar pierrelstan avatar gwynndp avatar mayankbucha avatar mohmn avatar dagmawig avatar aayushgauba avatar kpoke avatar jeremydthomas avatar kparikh9 avatar olhad avatar kothariroshni8 avatar waynelao avatar kunalznk avatar tranquanghuy0801 avatar ojafero avatar mohmin2 avatar ucrynet avatar weiyusun avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.