Git Product home page Git Product logo

brains-challenge's Introduction

Coding Exercise Backend

Quick Start

  1. In order to populate and run the mongo database, you need Docker and docker-compose. Run
docker-compose up
  1. To make the API work, first install all dependencies (note that npm@7 was used to generate the package-lock)
npm ci 
  1. And finally you can run the express server
npm start
  1. Go to http://localhost:3000/graphql

Implementation Story

The API consists of express server, mongo database and graphql. In order to simplify the task a bit and to write everything from scratch, the libraries mongoose, graphql-compose, and graphql-compose-mongoose are used.

The mongo database is populated with the provided json file with no additional changes. That implies that a new favorite field is not set and when queried using grapghl the value can be true, false, and also null.

The source code is written in TypeScript. To simplify the development and avoid any explicit transpilation step, ts-node is used to run the project instead of node. Supposedly, ts-node is acceptable to run in production when there is the --transpile-only flag specified.

Things to Improve in the Project

Mongo DB currently contains a single collection with no additional indices. It makes sense to add indices to all the fields that are used to filter results.

The mongoose schema is generated by an on-line tool. It would require just slightly more effort to have a detailed schema with all nested fields. As of now, all the more complex nested fields (e.g. specific objects) are "just" JSON objects.

As this was a small task there wasn't much to cover by tests. There is a single utility function - covered (npm test). Other than that, we could test if DB queries query what are supposed to query, or possibly cover the task specification, i.e. that the API handles whatever is specified in the requirements.

For easier maintenance of the project, we could setup eslint rules or TypeScript type check in a pre-commit or pre-push hook. Or anywhere on the way before the code gets to the master/main branch. Currently, there is only prettier config for consistent code formatting.

Original Task Specification

This repository contains a coding exercise for new developers joining the backend development team.

Fork this repository and create your own exercise!

What we want you to build

We have provided you with Pokemon data in a json file. Your mission is to create a database and expose the database to an API. Basically, you need to:

  • Design the database to store information for the Pokemon data
  • Load the database with the data
  • Implement the API Interface with the following features:
    • Query pokemons with the options:
      • Pagination
      • Search by name
      • Filter by pokemon type
      • Filter by favorite
    • Query a pokemon by id
    • Query a pokemon by name
    • Query list of pokemon types
    • Mutation to mark/unmark pokemon as favorite
  • Test are important and if time allows it, we'd like to see some test coverage

Technology

Remember that our technology stack is:

  • Node.js (Typescript, Fastify)
  • GraphQL (Nexus)
  • PostgreSQL (Objection.js)

You can use the framework that you prefer, but please write the challenge in JS or TS. You can choose PostgreSQL / MongoDB like database, be free but take in consideration the best database to store the data.

brains-challenge's People

Contributors

matoushavlena avatar

Watchers

 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.