{"id":50840100,"url":"https://github.com/vimalyad/e-commerce-backend","last_synced_at":"2026-06-14T06:06:44.206Z","repository":{"id":333633072,"uuid":"1137426210","full_name":"vimalyad/e-commerce-backend","owner":"vimalyad","description":"A Spring Boot-based REST API for an e-commerce platform with cart management, order processing, and payment handling capabilities.","archived":false,"fork":false,"pushed_at":"2026-01-20T11:21:26.000Z","size":36,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-02-10T18:38:01.649Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","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/vimalyad.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-19T10:59:18.000Z","updated_at":"2026-01-20T11:24:12.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/vimalyad/e-commerce-backend","commit_stats":null,"previous_names":["yamisukehiro2907/e-commerce-backend","vimalyad/e-commerce-backend"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/vimalyad/e-commerce-backend","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimalyad%2Fe-commerce-backend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimalyad%2Fe-commerce-backend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimalyad%2Fe-commerce-backend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimalyad%2Fe-commerce-backend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vimalyad","download_url":"https://codeload.github.com/vimalyad/e-commerce-backend/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimalyad%2Fe-commerce-backend/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34310815,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-14T02:00:07.365Z","response_time":62,"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":[],"created_at":"2026-06-14T06:06:43.595Z","updated_at":"2026-06-14T06:06:44.198Z","avatar_url":"https://github.com/vimalyad.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# E-Commerce Backend API\n\nA Spring Boot-based REST API for an e-commerce platform with cart management, order processing, and payment handling capabilities.\n\n## Features\n\n- **User Management**: User registration and profile management\n- **Product Management**: Create and search products with inventory tracking\n- **Shopping Cart**: Add items to cart, view cart contents, and clear cart\n- **Order Management**: Create orders from cart, view order history, and cancel orders\n- **Payment Processing**: Mock payment service simulating external payment gateway webhooks\n\n## Technology Stack\n\n- **Java** with Spring Boot\n- **MongoDB** for data persistence\n- **Lombok** for reducing boilerplate code\n- **Spring Data MongoDB** for database operations\n- **Maven** for dependency management\n\n## Prerequisites\n\n- Java 17 or higher\n- MongoDB installed and running locally\n- Maven 3.6+\n\n## Getting Started\n\n### 1. Clone the repository\n\n```bash\ngit clone https://github.com/yamiSukehiro2907/e-commerce-backend\ncd backend-api\n```\n\n### 2. Configure MongoDB\n\nThe application is configured to connect to MongoDB at `mongodb://localhost/e-commerce-db`. Update `src/main/resources/application.properties` if your MongoDB configuration differs:\n\n```properties\nspring.mongodb.uri=mongodb://localhost/e-commerce-db\nserver.port=8085\n```\n\n### 3. Build the project\n\n```bash\nmvn clean install\n```\n\n### 4. Run the application\n\n```bash\nmvn spring-boot:run\n```\n\nThe API will start on `http://localhost:8085`\n\n## API Endpoints\n\n### User Management\n\n- **POST** `/api/user/register` - Register a new user\n\n### Product Management\n\n- **POST** `/api/products` - Create a new product\n- **GET** `/api/products` - Get all products\n- **GET** `/api/products/search?q={name}` - Search products by name\n\n### Cart Management\n\n- **POST** `/api/cart/add` - Add item to cart\n- **GET** `/api/cart/{userId}` - Get cart items for a user\n- **DELETE** `/api/cart/{userId}` - Clear user's cart\n\n### Order Management\n\n- **POST** `/api/orders/user/{userId}` - Create order from cart\n- **GET** `/api/orders/user/{userId}` - Get all orders for a user\n- **POST** `/api/orders/{orderId}/cancel` - Cancel an order\n\n### Payment Management\n\n- **GET** `/api/payments` - Get all payments\n- **POST** `/api/payments/create` - Create a payment for an order\n- **POST** `/api/payments/pay/{paymentId}` - Process payment (triggers mock webhook)\n\n## Payment Mock Service\n\nInstead of integrating with an actual payment gateway, this application uses a **Mock Payment Service** (`PaymentMockService`) that simulates webhook responses from a payment provider.\n\n### How it works:\n\n1. When a payment is created, it's set to `PENDING` status\n2. When `/api/payments/pay/{paymentId}` is called, the mock service simulates a successful payment\n3. The mock service returns a `WebHookResponse` with:\n    - Transaction ID (mock UUID)\n    - Status: `PAID`\n4. The order status is updated to `SHIPPED` upon successful payment\n\nThis approach allows for testing the complete payment flow without requiring actual payment gateway integration.\n\n## Data Models\n\n### User\n- username, email, role\n\n### Product\n- name, description, price, stock\n\n### CartItem\n- userId, productId, quantity\n\n### Order\n- userId, totalAmount, status, createdAt\n\n### OrderItem\n- orderId, productId, quantity, price\n\n### Payment\n- orderId, amount, status, transactionId, createdAt\n\n## Business Logic\n\n### Order Creation Flow\n1. Validates user and cart items\n2. Checks product availability\n3. Reduces product stock\n4. Creates order with `CREATED` status\n5. Clears user's cart\n6. Creates order items\n\n### Order Cancellation\n- Only orders with status other than `PAID` can be cancelled\n- Restores product stock\n- Updates order status to `CANCELLED`\n\n### Payment Processing\n1. Creates payment record with `PENDING` status\n2. Simulates payment gateway webhook via mock service\n3. Updates payment status to `PAID`\n4. Updates order status to `SHIPPED`\n\n## Error Handling\n\nThe API includes comprehensive error handling for:\n- User not found\n- Product not found\n- Insufficient stock\n- Empty cart\n- Invalid order states\n- Duplicate payments\n\n## Development Notes\n\n- Uses `MongoTemplate` for database operations instead of Spring Data repositories\n- Implements custom repository pattern for better control over queries\n- Uses Java Records for DTOs (immutable data transfer objects)\n- Transaction management with `@Transactional` for critical operations\n\n## Testing\n\nRun the test suite:\n\n```bash\nmvn test\n```\n\n## Contributors\n\nVimal Kumar Yadav","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvimalyad%2Fe-commerce-backend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvimalyad%2Fe-commerce-backend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvimalyad%2Fe-commerce-backend/lists"}