Skip to content

Take home assessment, develop of a restaurant api

License

Notifications You must be signed in to change notification settings

teresaromero/restaurants-api

Repository files navigation

Restaurants API

Build and Test

Restaurants API serves restaurants information.

  • Admins can add, edit and delete restaurants.
  • Users can add reviews to the restaurants and save them as favourite.

How to run the project

Clone the project and install dependencies

    git clone https://github.com/teresaromero/restaurants-api.git && cd restaurants-api && yarn install

The project uses a SQLite Database, a Prisma ORM is use for integration with the server. To run locally make sure you follow this steps:

  1. Set up the DATABASE_URL environment variable to point to the SQLite file:
    export DATABASE_URL=file:./db/dev.db
  1. Set the required environment variables at a .env file, for example:
export JWT_SECRET=yousecret
export JWT_EXPIRES_IN=secondstoexpire
export HASH_SALT=hashnumber

(you can use the same .env file for database and app environments)

  1. Generate Prisma Client & Migrations

Prisma ORM generates the client within node_modules with the provided schema. For the app to work the Client should be generated.

    yarn prisma:generate

Once the dependency for PrismaClient has been created, the database has to be initialized. Run migrations so the database schema is aligned with the prisma schema and the client.

    yarn prisma:migrate:deploy

Once you have the database setup, you can inspect it by using Prisma Studio

    yarn prisma:studio

prisma will use the DATABASE_URL on the .env file defined for all the commands

  1. Run the server
    yarn dev

Data models can be consulted at Prisma schema here

SwaggerUI and OpenAPI Spec

An OpenAPI spec is available here.

However, in development mode, there is a SwaggerUI available to test the API. Once the server is running you can access http://localhost:${PORT}/docs.

Roadmap, missing features

  • Implement routes for admin statistics of: number of users, reviews, restaurants.
  • Deployment flow
  • E2E automation with Bruno CLI in Github
  • Implement session management and refresh token for auth
  • Migrate to Postgres

Architecture diagram

Diagrams available at here

Improvements over current design:

  • Replace SQLite with Postgres: replication of data and more eficient queries
  • Use Redis Cache: distributed cache to support listing of restaurants and reviews initially
  • Add monitoring and logging to be able to know what is happening in the system, potential breaking points or issues or decide which request needs better performance
  • Implement a queue system to ingest the reviews creation (potentially the more loaded create flow)
  • Use Kubernetes for orchestration of the containers and scale horizontally using a load balancer

About

Take home assessment, develop of a restaurant api

Topics

Resources

License

Stars

Watchers

Forks

Languages