{"id":24769417,"url":"https://github.com/parthasarathy27/e-commerce-api-be","last_synced_at":"2026-05-14T21:05:28.402Z","repository":{"id":274474381,"uuid":"923020340","full_name":"parthasarathy27/E-commerce-API-BE","owner":"parthasarathy27","description":"The E-commerce API Backend is a robust and scalable backend system built using Node.js and MongoDB to support a multi-role e-commerce platform. The system is designed to handle various e-commerce operations such as product management, user authentication, and role-based access control.","archived":false,"fork":false,"pushed_at":"2025-01-29T03:54:52.000Z","size":50,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-29T15:20:59.946Z","etag":null,"topics":["api","backend","database","ecommerce","task"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/parthasarathy27.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-27T14:05:58.000Z","updated_at":"2025-01-29T03:54:56.000Z","dependencies_parsed_at":"2025-01-27T15:31:08.477Z","dependency_job_id":"9e940ab0-76ea-4960-9e71-07234f14d376","html_url":"https://github.com/parthasarathy27/E-commerce-API-BE","commit_stats":null,"previous_names":["parthasarathy27/e-commerce-api-be"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/parthasarathy27/E-commerce-API-BE","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parthasarathy27%2FE-commerce-API-BE","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parthasarathy27%2FE-commerce-API-BE/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parthasarathy27%2FE-commerce-API-BE/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parthasarathy27%2FE-commerce-API-BE/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/parthasarathy27","download_url":"https://codeload.github.com/parthasarathy27/E-commerce-API-BE/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parthasarathy27%2FE-commerce-API-BE/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33043274,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"online","status_checked_at":"2026-05-14T02:00:06.663Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","backend","database","ecommerce","task"],"created_at":"2025-01-29T02:53:41.837Z","updated_at":"2026-05-14T21:05:28.387Z","avatar_url":"https://github.com/parthasarathy27.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# E-commerce API Backend\n\nThis project is an API backend for an e-commerce website built using **Node.js** and **MongoDB**. It supports multiple user roles, each with specific permissions and functionalities. The roles include **Admin**, **Staff**, **Vendor**, and **Buyer**. The project allows users to register, view products, add products, and manage the product catalog based on their role in the system.\n\n## Project Overview\n\nThe API facilitates the following core functionalities:\n\n- **User Authentication \u0026 Role-Based Access**: Allows users to sign up, log in, and access system resources based on their assigned roles.\n- **CRUD Operations**: Supports creating, reading, updating, and deleting products. Different roles have different access to these operations.\n- **Product Management**: Admin, staff, and vendors can create and manage products, including product details, prices, and images.\n- **Product Search \u0026 Pagination**: Provides search functionality and pagination for better product listing management.\n\n## Roles and Permissions\n\n1. **Admin**: \n   - Can view all vendor, staff, and user details.\n   - Can create products and set the start and expiry dates for products.\n   - Can upload product images and define old/new prices and delivery options.\n   - Full access to all functionalities.\n\n2. **Staff**: \n   - Can view and add products for assigned vendors.\n   - Can set product details such as name, description, and prices.\n   \n3. **Vendor**: \n   - Can view and manage only their own products.\n   - Can set details for their own products.\n\n4. **Buyer (User)**: \n   - Can view all products.\n   - Can see vendor information, expiry time, and discount information for each product.\n\n## Database\n\n- The backend uses **MongoDB** to store information about users, vendors, staff, products, etc.\n- The database is designed with collections for users, products, and roles.\n\n### Key Collections:\n\n- **Users**: Stores user details (name, email, password, role).\n- **Products**: Stores product details (name, description, price, start date, expiry date, vendor ID, etc.).\n- **Roles**: Stores user roles and permissions.\n\n## Features\n\n- **User Authentication**: \n  - Buyers and vendors can sign up and log in.\n  - Admin and staff users can be created by the super-admin.\n  - Passwords are hashed before storing.\n\n- **Product Management**:\n  - Admin can add, edit, or delete products.\n  - Each product has a unique URL.\n  - Products have a start and expiry date (expiry is set 7 days after the start date).\n  - Free delivery and delivery amount are handled.\n\n- **Discount Calculation**:\n  - Discount percentage and amount are calculated on the fly, not stored in the database.\n  \n- **Search and Pagination**:\n  - Implemented a search feature to find products.\n  - Server-side pagination for product listing.\n\n## Getting Started\n\n### Prerequisites\n\n- **Node.js** installed on your machine.\n- **MongoDB** database (local or cloud).\n- **Postman** to test the API endpoints.\n\n### Setup\n\n1. **Clone the repository**:\n   ```bash\n   git clone https://github.com/parthasarathy27/E-commerce-API-BE.git\n   cd E-commerce-API-BE\n   ```\n\n2. **Install Dependencies**:\n   Install the required dependencies using npm:\n   ```bash\n   npm install\n   ```\n\n3. **MongoDB Configuration**:\n   - Make sure MongoDB is installed and running on your local machine or use a cloud MongoDB service like **MongoDB Atlas**.\n   - Configure the MongoDB connection in the `.env` file:\n     ```env\n     MONGO_URI=mongodb://localhost:27017/ecommerce_db\n     ```\n\n4. **Run the Application**:\n   Start the server by running:\n   ```bash\n   npm run dev\n   ```\n\n   The server should now be running on `http://localhost:3000`.\n\n### API Endpoints\n\n- **POST /auth/signup**: Register a new user (buyer/vendor).\n- **POST /auth/login**: Log in to the system and receive a JWT token.\n- **GET /products**: Get a list of all products (with pagination and search filters).\n- **GET /products/:id**: Get product details by ID.\n- **POST /products**: Admin/Staff/Vendor can create a new product.\n- **PUT /products/:id**: Update a product (Admin/Staff).\n- **DELETE /products/:id**: Delete a product (Admin/Staff).\n- **GET /users**: Get all users (Admin only).\n- **POST /users**: Create a new user (Admin only).\n\n### Example Postman Collection\n\nIncluded in the repository is a **Postman collection** to test the various API endpoints. You can import this collection into Postman for easier testing.\n\n## Security Considerations\n\n- Passwords are hashed using **bcrypt** before being stored in the database.\n- Authentication is handled via **JWT tokens**, which are required for accessing protected routes.\n- Role-based access control ensures that only authorized users can access certain endpoints.\n\n## Database Schema\n\nThe MongoDB database uses collections for **Users** and **Products**. Below is an overview of the database schema.\n\n### Users Collection\n\n```json\n{\n  \"_id\": ObjectId,\n  \"name\": \"John Doe\",\n  \"email\": \"john@example.com\",\n  \"password\": \"hashed_password\",\n  \"role\": \"buyer\", // Can be 'admin', 'staff', 'vendor', or 'buyer'\n  \"createdAt\": ISODate(\"2023-01-01T00:00:00Z\")\n}\n```\n\n### Products Collection\n\n```json\n{\n  \"_id\": ObjectId,\n  \"name\": \"Product Name\",\n  \"description\": \"Product description\",\n  \"price\": 100.00,\n  \"old_price\": 150.00,\n  \"start_date\": ISODate(\"2025-01-01T00:00:00Z\"),\n  \"expiry_date\": ISODate(\"2025-01-08T00:00:00Z\"),\n  \"delivery_amount\": 10.00,\n  \"free_delivery\": false,\n  \"vendor_id\": ObjectId(\"vendor_object_id\"),\n  \"image_url\": \"https://example.com/image.jpg\",\n  \"unique_url\": \"product-unique-url\"\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparthasarathy27%2Fe-commerce-api-be","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparthasarathy27%2Fe-commerce-api-be","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparthasarathy27%2Fe-commerce-api-be/lists"}