Restaurants API serves restaurants information.
- Admins can add, edit and delete restaurants.
- Users can add reviews to the restaurants and save them as favourite.
Clone the project and install dependencies
git clone https://github.com/teresaromero/restaurants-api.git && cd restaurants-api && yarn installThe project uses a SQLite Database, a Prisma ORM is use for integration with the server. To run locally make sure you follow this steps:
- Set up the DATABASE_URL environment variable to point to the SQLite file:
export DATABASE_URL=file:./db/dev.db- Set the required environment variables at a
.envfile, 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)
- 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:generateOnce 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:deployOnce you have the database setup, you can inspect it by using Prisma Studio
yarn prisma:studioprisma will use the DATABASE_URL on the .env file defined for all the commands
- Run the server
yarn devData models can be consulted at Prisma schema here
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.
- 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
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