PromptBase
Upgrade
Close icon
General
Home
Marketplace
Create
Hire
Login
Chat
Sell
Explore

Prompt Details

Model
(claude-5-opus)
Token size
1,357
Example input
[What you want to build]: Build a REST API for an e-commerce application that allows customers to create orders, view their orders, and cancel an order before it is shipped. [Existing code / repository / files, if any]: Existing repository: ecommerce-api/ β”œβ”€β”€ src/ β”‚ β”œβ”€β”€ controllers/ β”‚ β”œβ”€β”€ routes/ β”‚ β”œβ”€β”€ models/ β”‚ └── app.js β”œβ”€β”€ tests/ β”œβ”€β”€ package.json └── README.md [Language / framework / database / APIs / deployment]: Language: JavaScript Runtime: Node.js Framework: Express.js Database: PostgreSQL ORM: Prisma Authentication: JWT Testing: Jest + Supertest [Features and functionality]: Create an order Add multiple products to an order Validate product availability Calculate the total order amount Return the created order Allow customers to view their own orders Allow cancellation only when order status is PENDING [Code / architecture / debugging / tests / full implementation]: Requirement analysis Confirmed / Assumed / Missing information Root-cause investigation Architecture impact Implementation plan Required file changes Corrected code Unit tests Integration tests Edge-case tests Security review Final validation report
Example output
πŸ”Ž PHASE 1 β€” REQUIREMENT UNDERSTANDING Goal Fix incorrect order-total calculations while preserving the existing e-commerce architecture. Users Authenticated customers Existing product-service users Core Features Create order Calculate line-item totals Calculate final order total Retrieve orders Cancel eligible orders Inputs Example request: { "items": [ { "productId": "prod_101", "quantity": 2 }, { "productId": "prod_205", "quantity": 1 } ] } Expected Output { "id": "order_123", "status": "PENDING", "total": 1300, "items": [ { "productId": "prod_101", "quantity": 2, "unitPrice": 500, "lineTotal": 1000 }, { "productId": "prod_205", "quantity": 1, "unitPrice": 300, "lineTotal": 300 } ] } Business Rules lineTotal = unitPrice Γ— quantity orderTotal = sum(all lineTotal values) Quantity must be greater than 0. Product must exist. Product must be available. Only authenticated users can create or access orders. PENDING orders can be cancelled. Shipped orders cannot be cancelled. CONFIRMED The application uses Node.js/Express. PostgreSQL and Prisma are used. JWT authentication exists. Product APIs already exist. Multiple products can belong to one order. The reported bug concerns quantity-based calculation. ASSUMED Product price is retrieved from the database during order creation. The order stores the price used at purchase time. Prices are represented in the smallest currency unit or a database numeric type. Existing order endpoints should remain backward compatible. MISSING Actual controller implementation Prisma schema Existing order model Actual failing stack trace Existing order tests Exact database price type Current order API response format Conclusion: The exact root cause cannot yet be confirmed without inspecting the implementation. --- πŸ—οΈ PHASE 2 β€” ARCHITECTURE A minimal architecture would be: HTTP Request ↓ Authentication Middleware ↓ Order Route ↓ Order Controller ↓ Order Service ↓ Product Repository / Prisma ↓ PostgreSQL Why this structure? Authentication remains separate from business logic. Order calculation belongs in the order service. Database access remains isolated. Existing product functionality does not need to be rewritten. --- 🧩 PHASE 3 β€” IMPLEMENTATION PLAN Milestone 1: Investigate Inspect order controller. Inspect order service. Inspect Prisma schema. Locate total calculation. Reproduce the reported failure. Expected Result Identify whether quantity is being ignored during line-total calculation. Milestone 2: Fix Calculation Task: Correct line-item calculation. Purpose: Ensure every product price is multiplied by its requested quantity. Expected logic: lineTotal = unitPrice Γ— quantity Milestone 3: Add Tests Test: One product, quantity 1 One product, quantity > 1 Multiple products Quantity 0 Negative quantity Missing product Unavailable product Decimal prices Very large quantity Milestone 4: Regression Validation Verify existing: Product APIs Authentication Order retrieval Order cancellation remain unaffected. --- πŸ’» PHASE 4 β€” CODE IMPLEMENTATION Suppose investigation discovers this existing logic: const total = items.reduce((sum, item) => { return sum + item.product.price; }, 0); Confirmed Root Cause The calculation adds only the product price: price instead of: price Γ— quantity For: β‚Ή500 Γ— 2 the current implementation contributes: β‚Ή500 instead of: β‚Ή1000 Corrected Logic const total = items.reduce((sum, item) => { return sum + item.product.price * item.quantity; }, 0); For: β‚Ή500 Γ— 2 β‚Ή300 Γ— 1 the calculation becomes: 500 Γ— 2 = 1000 300 Γ— 1 = 300 Total = 1300 Important: This code should only be applied after confirming that item.quantity is actually the intended quantity field in the existing codebase. --- πŸ› PHASE 5 β€” DEBUGGING TRACE SYMPTOM Order total is lower than expected when products have quantities greater than 1. ↓ FAILURE POINT Order-total calculation. ↓ ROOT CAUSE The implementation sums product prices but ignores item quantity. ↓ FIX Multiply each product's unit price by its quantity before adding it to the order total. ↓ REGRESSION RISK Potential risk if: Existing code already calculates line totals elsewhere. Prices use floating-point numbers. Quantity validation is missing. Database values are strings/Decimals rather than JavaScript numbers. These areas must be checked before finalizing the fix. --- πŸ§ͺ PHASE 6 β€” TESTING Test 1: Single Product Input { "items": [ { "productId": "prod_1", "quantity": 1 } ] } Product price: β‚Ή500 Expected Total = β‚Ή500 Pass Criteria API returns HTTP 201 and total 500. --- Test 2: Quantity Greater Than One Input { "items": [ { "productId": "prod_1", "quantity": 3 } ] } Product price: β‚Ή500 Expected 500 Γ— 3 = β‚Ή1500 Pass Criteria Returned total equals 1500. --- Test 3: Multiple Products Input { "items": [ { "productId": "prod_1", "quantity": 2 }, { "productId": "prod_2", "quantity": 1 } ] } Prices: prod_1 = β‚Ή500 prod_2 = β‚Ή300 Expected 500 Γ— 2 + 300 Γ— 1 = 1000 + 300 = β‚Ή1300 Pass Criteria Returned total equals 1300. --- Test 4: Zero Quantity Input { "items": [ { "productId": "prod_1", "quantity": 0 } ] } Expected HTTP 400 Bad Request Pass Criteria Order is not created. --- Test 5: Negative Quantity { "items": [ { "productId": "prod_1", "quantity": -5 } ] } Expected HTTP 400 Bad Request Pass Criteria Negative quantities are rejected. --- Test 6: Invalid Product { "items": [ { "productId": "does_not_exist", "quantity": 1 } ] } Expected HTTP 404 Not Found Pass Criteria No order is created. --- Test 7: Unauthenticated Request Send the order request without JWT. Expected HTTP 401 Unauthorized Pass Criteria Order creation is rejected. --- πŸ” SECURITY REVIEW Check that: Product prices are taken from the trusted database, not from client input. Client cannot submit: { "price": 1 } to purchase a β‚Ή500 product for β‚Ή1. Quantity is validated server-side. Users cannot access another customer's orders. JWT validation remains enforced. Database queries are parameterized through Prisma. No credentials are hardcoded. Critical security/business rule: The client should send: productId quantity but not be trusted for the final product price. --- πŸ” PHASE 7 β€” CODE REVIEW Correctness The calculation should multiply unit price by quantity. Maintainability Keep the calculation in the existing order-service/business-logic layer rather than duplicating it across controllers. Performance Avoid unnecessary product queries inside a loop if the existing architecture can retrieve all required products in one query. Error Handling Invalid quantities and unavailable products should fail before creating the order. Backward Compatibility Existing API contracts should remain unchanged unless the bug fix requires a documented response change. --- πŸ“‹ FINAL VALIDATION REPORT FINAL CHANGES Correct order line-total calculation. Validate quantity. Add regression tests. Ensure server-side product pricing. Preserve existing authentication and product APIs. KNOWN LIMITATIONS Actual files cannot be safely modified until the real repository/code is provided. Exact database Decimal/number handling needs verification. Existing API response structure needs confirmation. REMAINING RISKS Floating-point currency calculations. Concurrent inventory changes. Database transaction failures. Race conditions during stock validation. TEST RESULTS Not executed. No claim of passing tests can be made because the actual project has not been run. NEXT STEPS 1. Inspect the actual order controller/service. 2. Inspect the Prisma schema. 3. Reproduce the reported β‚Ή800 result. 4. Confirm the exact failure point. 5. Apply the smallest safe fix. 6. Run unit and integration tests. 7. Perform regression testing. 8. Review the final diff. 9. Only then determine whether the implementation is production-ready. 🎯 Expected transformation IDEA ↓ E-Commerce Order API ↓ REQUIREMENTS ↓ Multi-product ordering + quantity calculation ↓ ARCHITECTURE ↓ Route β†’ Controller β†’ Service β†’ Prisma β†’ PostgreSQL ↓ BUG ↓ Quantity ignored during total calculation ↓ FIX ↓ unitPrice Γ— quantity ↓ TEST ↓ Unit + Integration + Edge Cases ↓ VALIDATION ↓ Production readiness only after actual execution evidence
πŸŒ€ Claude

Vibe Coding Programming Assistant

Add to Cart
Instant accessInstant access
Usage rightsCommercial use
Money-back guaranteeMoney‑back
By purchasing this prompt, you agree to our terms of service
CLAUDE-5-OPUS
Tested icon
Guide icon
4 examples icon
Free credits icon
This prompt helps AI turn ideas into structured coding tasks, generate implementation plans, write and improve code, debug failures, and validate the final project without unnecessary complexity. πŸ’‘ Convert ideas into clear coding requirements πŸ—οΈ Design practical project architecture πŸ’» Generate implementation-ready code πŸ› Debug errors & improve existing code πŸ§ͺ Create tests & validation checks πŸ” Review code quality & maintainability πŸš€ Guide the project from idea to working build πŸš€ Turn you
...more
Updated 2 weeks ago
Report
Browse Marketplace