Code Monkey home page Code Monkey logo

foleon-assignment's Introduction

Foleon Backend Challenge

Description

The main goal of this application is to

create a simple backend application for our front-end. The backend will be responsible for creating CRUD endpoints that allow us to create reusable elements and documents. Project can have multiple documents. Document is made of multiple elements (can have multiple elements of same type as well). Order of the elements in the document is important. One element can be used on multiple documents. Supported elements can be type of: button, image or text. Each entity (element/document/project) should have basic attributes like createdAt, name etc. When we are fetching document, combine all their elements (including their attributes) in proper order.

For the building of this application I used the following technologies:

Database Schema

Database Schema

  • Project table contains information about the project. It has a one-to-many relationship with the Document table. Also has a one-to-many relationship with the Element table that helps us to keep track of the elements that are used in multiple projects.
  • Document table contains the information about the document. It has a one-to-many relationship with the Element table. Also has a many-to-one relationship with the Project table.
  • Element table contains the information about the element. It has a many-to-one relationship with the Document table. Also has a many-to-one relationship with the Project table.
  • And finally, the element_to_document table contains the information about the elements that are used in the document. It's the pivot table in relation (many-to-many) between the Elem

By using this schema we can easily create a document by using the elements that are used in other documents or projects. Also, we can keep tracking the order of the elements in the document by using the order column in the element_to_document table.

About the Apis and Test cases, I have tried to keep everything simple and straight.

There is still a lot of work to do to make this application production ready. For example, we can add more tests, add more validations, add more error handling, add more logging, add more security, better api structure, add more documentation, add more features, etc. But I think this is enough for now.

Getting Started

Set up and run

To set up the API you need to open a terminal window and install the dependencies

npm install

You can find the server and database configuration in the env file. You have to change the database configuration and enter your credentials.

After that, you need to run migrations and seed the database.

npm run migration:run
npm run seed:run

Now you can start the API server:

npm run start

Quick run with Docker

If you are tired of installing all the dependencies, you can run the application with Docker. You need to have Docker installed on your machine. After that, you can run the following command:

cp env-example .env
docker compose up -d

Documenttion

Also you can find the swagger documentation in the following link: http://localhost:3000/api.

Test

For running the tests you need to run the following command: I have implemented the test cases just for document module which I believe is the most complicated module in this application.

npm run test

foleon-assignment's People

Contributors

amirkheirabadi73 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.