{"id":15190464,"url":"https://github.com/mrx-arafat/e-commmerce-backend","last_synced_at":"2026-03-04T02:01:58.313Z","repository":{"id":240863490,"uuid":"803629981","full_name":"mrx-arafat/e-commmerce-backend","owner":"mrx-arafat","description":"E-commerce Backend ","archived":false,"fork":false,"pushed_at":"2024-05-22T10:19:56.000Z","size":2452,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-28T04:53:49.040Z","etag":null,"topics":["expressjs","mongoosejs","nodejs","typescript"],"latest_commit_sha":null,"homepage":"https://e-commmerce-backend.vercel.app/","language":"TypeScript","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/mrx-arafat.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":"2024-05-21T05:10:02.000Z","updated_at":"2024-05-22T10:19:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"724a3750-7bd0-47a4-b6e5-ef8c71a3e9d5","html_url":"https://github.com/mrx-arafat/e-commmerce-backend","commit_stats":null,"previous_names":["mrx-arafat/e-commmerce-backend"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mrx-arafat/e-commmerce-backend","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrx-arafat%2Fe-commmerce-backend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrx-arafat%2Fe-commmerce-backend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrx-arafat%2Fe-commmerce-backend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrx-arafat%2Fe-commmerce-backend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrx-arafat","download_url":"https://codeload.github.com/mrx-arafat/e-commmerce-backend/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrx-arafat%2Fe-commmerce-backend/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30069220,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T01:03:42.280Z","status":"online","status_checked_at":"2026-03-04T02:00:07.464Z","response_time":59,"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":["expressjs","mongoosejs","nodejs","typescript"],"created_at":"2024-09-27T20:23:30.373Z","updated_at":"2026-03-04T02:01:58.296Z","avatar_url":"https://github.com/mrx-arafat.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# E-Commerce Backend\n\nThis is an E-Commerce backend application developed using Express and TypeScript, integrated with MongoDB using Mongoose for effective data management. The application ensures data integrity through validation using Joi.\n\n## Features\n\n- Create, Retrieve, Update, Delete Products\n- Create and Retrieve Orders\n- Inventory management with quantity updates on order creation\n- Data validation with Joi\n\n## Prerequisites\n\nMake sure you have the following installed on your system:\n\n- Node.js\n- npm\n- MongoDB\n\n## Project Setup\n\n### 1. Clone the repository\n\n```bash\ngit clone https://github.com/mrx-arafat/e-commerce-backend.git\ncd e-commerce-backend\n```\n\n### 2. Install dependencies\n\n```bash\nnpm install\n```\n\n### 3. Environment Variables\n\nCreate a `.env` file in the root directory of the project and add the following environment variables:\n\n```env\nPORT=5000\nDATABASE_URL=mongodb://localhost:27017/arafatDB\n```\n\n### 4. Build the Project\n\nTo compile the TypeScript code, run:\n\n```bash\nnpm run build\n```\n\n### 5. Seed the Database\n\nTo populate the database with sample data, run the feeder script:\n\n```bash\nnpx ts-node src/feeder.ts\n```\n\n### 6. Start the Server\n\n```bash\nnpm run start\n```\n\nThis will start the server on the port specified in the `.env` file (default is 5000).\n\n## API Endpoints\n\n### Product Management\n\n#### Create a New Product\n\n- **Endpoint**: `/api/products`\n- **Method**: POST\n- **Request Body**:\n\n```json\n{\n  \"name\": \"iPhone 13\",\n  \"description\": \"A sleek and powerful smartphone with cutting-edge features.\",\n  \"price\": 999,\n  \"category\": \"Electronics\",\n  \"tags\": [\"smartphone\", \"Apple\", \"iOS\"],\n  \"variants\": [\n    {\n      \"type\": \"Color\",\n      \"value\": \"Midnight Blue\"\n    },\n    {\n      \"type\": \"Storage Capacity\",\n      \"value\": \"256GB\"\n    }\n  ],\n  \"inventory\": {\n    \"quantity\": 50,\n    \"inStock\": true\n  }\n}\n```\n\n- **Sample Response**:\n\n![1716372461729](image/readme/1716372461729.png)\n\n#### Retrieve All Products\n\n- **Endpoint**: `/api/products`\n- **Method**: GET\n- **Sample Response**:\n\n![1716362594143](image/readme/1716362594143.png)\n\n#### Retrieve a Specific Product by ID\n\n- **Endpoint**: `/api/products/:productId`\n- **Method**: GET\n- `http://localhost:5000/api/products/664ca42bf0658ebbeba51b3a`\n- **Sample Response**:\n\n![1716362705841](image/readme/1716362705841.png)\n\n#### Update Product Information\n\n- **Endpoint**: `/api/products/:productId`\n- **Method**: PUT\n- **Sample Request Body**:\n\n**Sample Response**:\n\n![1716362790939](image/readme/1716362790939.png)\n\n#### Delete a Product\n\n- **Endpoint**: `/api/products/:productId`\n- **Method**: DELETE\n- **Sample Response**:\n\n![1716366826371](image/readme/1716366826371.png)\n\n#### Search a Product\n\n- **Endpoint**: `/api/products/search?searchTerm=iphone`\n- `http://localhost:5000/api/products/search?searchTerm=iphone`\n- **Method**: GET\n- **Sample Response**:\n\n![1716366578829](image/readme/1716366578829.png)\n\n### Order Management\n\n#### Create a New Order\n\n- **Endpoint**: `/api/orders`\n- **Method**: POST\n- **Request Body**:\n\n![1716371991645](image/readme/1716371991645.png)\n\n- **Sample Response**:\n\n#### Retrieve All Orders\n\n- **Endpoint**: `/api/orders`\n- **Method**: GET\n- **Sample Response**:\n\n#### Retrieve Orders by User Email\n\n- **Endpoint**: `/api/orders?email=level2@programming-hero.com`\n- **Method**: GET\n- **Sample Response**:\n\n![1716367248639](image/readme/1716367248639.png)\n\n### Bonus Section Done: Inventory Update\n\nWhen creating a new order via the `/api/orders` endpoint, the system will:\n\n1. Check the available quantity in inventory.\n2. Return an error response if the ordered quantity exceeds the available quantity.\n3. Update the inventory quantity and `inStock` status based on the ordered quantity.\n4. If the inventory quantity reaches zero, set `inStock` to false; otherwise, keep it as true.\n\n### Error Handling\n\n- **Insufficient Quantity Error**:\n\n```json\n{\n  \"success\": false,\n  \"message\": \"Insufficient quantity available in inventory\"\n}\n```\n\n- **Not Found Error**:\n\n```json\n{\n  \"success\": false,\n  \"message\": \"Order not found\"\n}\n```\n\n- **Not Found Route**:\n\n```json\n{\n  \"success\": false,\n  \"message\": \"Route not found\"\n}\n```\n\n### Validation with Joi\n\nJoi is used to validate incoming data for product and order creation and updating operations.\n\n## Developer\n\n[mrx-arafat](https://github.com/mrx-arafat)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrx-arafat%2Fe-commmerce-backend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrx-arafat%2Fe-commmerce-backend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrx-arafat%2Fe-commmerce-backend/lists"}