https://github.com/hareem-gohar/recipe-management-api
Recipe Management API built with Node.js, Express, and MongoDB, allowing users to manage recipes, blogs, leave comments, rate dishes, and add favorites. It features secure authentication, role-based access, and an admin dashboard for recipe and blog management.
https://github.com/hareem-gohar/recipe-management-api
bycryptjs dotenv expressjs jest jwt-token mongo-memory-server mongodb moongose nodejs supertest
Last synced: 2 months ago
JSON representation
Recipe Management API built with Node.js, Express, and MongoDB, allowing users to manage recipes, blogs, leave comments, rate dishes, and add favorites. It features secure authentication, role-based access, and an admin dashboard for recipe and blog management.
- Host: GitHub
- URL: https://github.com/hareem-gohar/recipe-management-api
- Owner: Hareem-Gohar
- Created: 2025-01-18T12:42:58.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-18T12:50:09.000Z (over 1 year ago)
- Last Synced: 2025-03-14T06:29:27.524Z (over 1 year ago)
- Topics: bycryptjs, dotenv, expressjs, jest, jwt-token, mongo-memory-server, mongodb, moongose, nodejs, supertest
- Language: JavaScript
- Homepage:
- Size: 72.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.html
Awesome Lists containing this project
README
Backend Application
/* From extension vscode.github */
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
.vscode-dark img[src$=\#gh-light-mode-only],
.vscode-light img[src$=\#gh-dark-mode-only],
.vscode-high-contrast:not(.vscode-high-contrast-light) img[src$=\#gh-light-mode-only],
.vscode-high-contrast-light img[src$=\#gh-dark-mode-only] {
display: none;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe WPC', 'Segoe UI', system-ui, 'Ubuntu', 'Droid Sans', sans-serif;
font-size: 14px;
line-height: 1.6;
}
.task-list-item {
list-style-type: none;
}
.task-list-item-checkbox {
margin-left: -20px;
vertical-align: middle;
pointer-events: none;
}
:root {
--color-note: #0969da;
--color-tip: #1a7f37;
--color-warning: #9a6700;
--color-severe: #bc4c00;
--color-caution: #d1242f;
--color-important: #8250df;
}
@media (prefers-color-scheme: dark) {
:root {
--color-note: #2f81f7;
--color-tip: #3fb950;
--color-warning: #d29922;
--color-severe: #db6d28;
--color-caution: #f85149;
--color-important: #a371f7;
}
}
.markdown-alert {
padding: 0.5rem 1rem;
margin-bottom: 16px;
color: inherit;
border-left: .25em solid #888;
}
.markdown-alert>:first-child {
margin-top: 0
}
.markdown-alert>:last-child {
margin-bottom: 0
}
.markdown-alert .markdown-alert-title {
display: flex;
font-weight: 500;
align-items: center;
line-height: 1
}
.markdown-alert .markdown-alert-title .octicon {
margin-right: 0.5rem;
display: inline-block;
overflow: visible !important;
vertical-align: text-bottom;
fill: currentColor;
}
.markdown-alert.markdown-alert-note {
border-left-color: var(--color-note);
}
.markdown-alert.markdown-alert-note .markdown-alert-title {
color: var(--color-note);
}
.markdown-alert.markdown-alert-important {
border-left-color: var(--color-important);
}
.markdown-alert.markdown-alert-important .markdown-alert-title {
color: var(--color-important);
}
.markdown-alert.markdown-alert-warning {
border-left-color: var(--color-warning);
}
.markdown-alert.markdown-alert-warning .markdown-alert-title {
color: var(--color-warning);
}
.markdown-alert.markdown-alert-tip {
border-left-color: var(--color-tip);
}
.markdown-alert.markdown-alert-tip .markdown-alert-title {
color: var(--color-tip);
}
.markdown-alert.markdown-alert-caution {
border-left-color: var(--color-caution);
}
.markdown-alert.markdown-alert-caution .markdown-alert-title {
color: var(--color-caution);
}
Here's an improved version of your README.md with a Table of Contents (TOC), better structure, and enhanced readability:
# Backend Application
This is the backend application for managing recipes, users, comments, favorites, ratings, and blogs. The application is built using **Node.js**, **Express**, and **MongoDB**. It includes authentication and authorization features, making it secure and scalable.
## Table of Contents
- [Features](#features)
- [Tech Stack](#tech-stack)
- [Project Structure](#project-structure)
- [Getting Started](#getting-started)
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Running the Server](#running-the-server)
- [Running Tests](#running-tests)
- [API Endpoints](#api-endpoints)
- [Public Endpoints](#public-endpoints)
- [Protected Endpoints](#protected-endpoints)
- [Admin Endpoints](#admin-endpoints)
- [Middleware](#middleware)
- [Testing with MongoMemoryServer](#testing-with-mongodb-memory-server)
- [License](#license)
- [Author](#author)
- [Contributions](#contributions)
- [Contact](#contact)
## Features
- **Recipe Management**: Add, update, delete, and fetch recipes.
- **User Management**: Handle user registration, authentication, and roles (user/admin).
- **Comments System**: Enable users to comment on recipes.
- **Favorites**: Allow users to mark recipes as favorites.
- **Ratings**: Enable users to rate recipes.
- **Blogs**: Manage blog posts related to recipes.
- **Secure Routes**:
- Protected routes for authenticated users.
- Admin-specific routes for managing sensitive resources.
## Tech Stack
- **Backend Framework**: Node.js with Express
- **Database**: MongoDB (with `mongoose` for schema modeling)
- **Authentication**: JSON Web Tokens (JWT)
- **Environment Variables**: `dotenv`
- **Testing**: Jest and Supertest
- **In-Memory Database for Testing**: MongoMemoryServer
## Project Structure
backend/
├── src/
│ ├── controllers/ # Functions for handling routes
│ │ └── urlController.js
│ ├── models/ # Mongoose models
│ │ └── urlModel.js
│ ├── routes/ # Route definitions
│ │ └── urlRoutes.js
│ ├── utils/ # Utility functions
│ │ └── validateUrl.js
│ ├── config/ # Configuration files
│ │ └── db.js
│ ├── app.js # Express app setup
│ └── server.js # Entry point
├── Middleware/ # Authentication middleware
│ ├── AuthMiddleware.js
│ ├── AdminAuthMiddleware.js
├── Routes/ # Application routes
│ ├── RecipeRoutes.js
│ ├── userRoutes.js
│ ├── CommentRoutes.js
│ ├── FavoriteRoutes.js
│ ├── RatingRoutes.js
│ └── BlogRoutes.js
├── .env # Environment variables
├── package.json # Project dependencies
├── jest.setup.js # Jest configuration
└── README.md # Documentation
## Getting Started
### Prerequisites
- Node.js (v16+)
- MongoDB (local or cloud instance)
- `npm` (or `yarn`)
### Installation
1. Clone the repository:
```bash
git clone https://github.com/your-repo/backend.git
cd backend
-
Install dependencies:
npm install
-
Create a .env file in the root directory and configure the following variables:
PORT=8000
MONGO_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret
-
Start the server in development mode:
npm start
Running the Server
For production:
npm run start:prod
Running Tests
-
Run unit tests using Jest:
npm test
API Endpoints
Public Endpoints
Method
Endpoint
Description
GET
/api/recipes
Fetch all recipes
POST
/api/users/register
Register a new user
Protected Endpoints
Method
Endpoint
Description
POST
/api/favorites
Add a recipe to favorites
GET
/api/comments/:recipeId
Fetch comments for a recipe
Admin Endpoints
Method
Endpoint
Description
DELETE
/api/recipes/:id
Delete a recipe
POST
/api/blogs
Create a new blog post
Middleware
-
AuthMiddleware: Protects routes by verifying the JWT token. -
AdminAuthMiddleware: Ensures only admin users access certain routes.
Testing with MongoMemoryServer
This project uses MongoMemoryServer to spin up an in-memory MongoDB instance for testing purposes. MongoMemoryServer allows you to test the functionality of your routes without requiring a real MongoDB instance.
Running Tests
-
Install Jest and Supertest:
npm install --save-dev jest supertest -
Run tests:
npm test
License
This project is licensed under the MIT License. See the LICENSE file for details.
Author
-
Hareem Gohar
An experienced frontend and backend developer passionate about scalable and efficient web applications.
Contributions
Contributions are welcome! Feel free to open issues or submit pull requests to enhance this project.
Contact
For any queries or support, contact me at [your-email@example.com].
### Improvements:
- Added a **Table of Contents** to allow easy navigation.
- Enhanced readability by breaking up large chunks of text into smaller, digestible sections.
- Improved formatting for the API endpoints section with a clean, responsive table structure.
- Included a **Testing** section with clearer instructions.
- Cleaned up some of the descriptions and formatted them to enhance clarity.
This structure should give your repo a polished, professional feel. You can add your personal contact and any other relevant details.