- Overview
- Project Setup
- Environment Variables
- Architecure
- Testing
- Technologies Used
- QnAs
- Contributing
- License
- Future Improvements
This project involves creating a Node.js backend server for menu management, divided into three main parts:
- Category
- Subcategory: A category can have multiple subcategories.
- Items: A subcategory can have multiple items.
The API is designed to manage these entities efficiently, with functionalities to create, retrieve, update, and search within the system. This API can be tested using Postman.
-
Deployed Link: Menu Management API on Render
-
Swagger Documentation: API Documentation
-
Postman Collections: Postman Collections.
-
Loom Video: API Overview Video
-
To know more about the endpoints: API-Endpoints.md
NOTE:
The API is deployed on Render, sometimes it takes a coldstart of 50-60 seconds, if there is inactivity of few hours. So please be patient with the deployed API.
- Pre-requisites
- Node.js: 20 LTS, click here if not installed
- Docker with docker-compose, click here if not installed
- Postman or cURL, click here if not installed
-
Clone the Repository
git clone https://github.com/deepanshu-rawat6/menu-management-api.git cd menu-management-api
-
Install Dependencies
npm install
-
Set Up Database
-
As said in the assignment, to any assignment, so I have choosen
MongoDB
, along withPrisma
as anORM
. -
Configuring Prisma to connect to your database.
npx prisma init
-
After design/modifying the schema, run the following command to update the
Prisma/Client
:npx prisma generate
- Run the application
-
We have two method of running the application, locally either by
Node.js
orDocker
: -
In order to run with Docker, we use the
docker-compose.dev.yml
, with the command:
docker-compose -f docker-compose.dev.yml up
- Otherwise, you can simply run, with the help of Node.js with the command:
npm run dev
- In case, to just test the API, we can use the deployed link: Menu Management API on Render
You need to create a .env
file in the root directory to store your environment variables. Here's an example of what it might include:
DATABASE_URL= <DATABASE_URL>
PORT= <PORT_NUMBER>
DB_USER= <DB_USER>
DB_PASSWORD= <DB_PASSWORD>
To test the API endpoints, you can use Postman or cURL or any other API testing tool.
-
Postman Collection: Use the Postman Collection provided in the repository to import all the requests and environment variables.
-
Swagger Documentation: The Swagger UI provides a user-friendly interface to test and explore all available API endpoints.
- Node.js
- Express.js
- MongoDB (NoSQL Database)
- Prisma (ORM)
- TypeScript
- Swagger (API Documentation)
- Zod (Validation)
- Pino (Logging)
MongoDB: Found a NoSQL DB to be better for this use case, and out of those Mongo was the best. Also, it was supported by prisma so another plus point.
- zod
- For schema validation by:
- Validator middleware
- Custom schema for validation
- swagger-docs
- API Documentation in YAML format
- Types of requests(params, query parameters and path parameters) along with advanced logging and error handling
- Logging using pino, pino-pretty logger
- Error handling using extensive try catch in controllers
Generating Swagger configurations and thoroughly testing the API endpoints were the most challenging parts.
Instead of a monolithic architecture, I would have opted for a microservices-based architecture, incorporating user authentication and authorization to secure protected routes.
If you'd like to contribute to this project, please follow these steps:
- Fork the repository.
- Create a new branch (git checkout -b feature/YourFeature).
- Commit your changes (git commit -m 'Add some feature').
- Push to the branch (git push origin feature/YourFeature).
- Open a Pull Request.
This project is licensed under the MIT License. See the LICENSE file for details.
Given more time, here are some improvements that could be made:
-
Microservices Architecture: Splitting the project into smaller services for scalability and maintainability.
-
Authentication & Authorization: Adding user authentication and role-based access control to protect certain routes.
-
Performance Optimization: Implementing caching strategies and optimizing database queries for better performance.
-
Automated Testing: Adding unit and integration tests to ensure code quality and reliability.