<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Vinh Tech Blog]]></title><description><![CDATA[Vinh Tech Blog]]></description><link>https://vinhcraft.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sat, 07 Nov 2026 11:27:32 GMT</lastBuildDate><atom:link href="https://vinhcraft.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How I Saved 40+ Hours Building a Production-Ready Laravel 11 E-Commerce REST API]]></title><description><![CDATA[A production-ready Laravel 11 backend setup with Service-Repository pattern, HMAC payment webhooks, and zero-bloat logic.]]></description><link>https://vinhcraft.hashnode.dev/how-i-saved-40-hours-building-a-production-ready-laravel-11-e-commerce-rest-api</link><guid isPermaLink="true">https://vinhcraft.hashnode.dev/how-i-saved-40-hours-building-a-production-ready-laravel-11-e-commerce-rest-api</guid><category><![CDATA[Laravel]]></category><category><![CDATA[PHP]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[architecture]]></category><category><![CDATA[Developer]]></category><category><![CDATA[backend]]></category><dc:creator><![CDATA[Vinh Ngô Quốc]]></dc:creator><pubDate>Mon, 02 Nov 2026 09:24:35 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6ae854fa35e526c2d8f06221/21b22f43-f8b1-4041-9d32-065482d74d88.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Starting a new client project or e-commerce web application often means repeating the same foundational setup: configuring authentication with access and refresh tokens, setting up rate limiting, building data repositories, integrating payment gateways, and wiring up realtime WebSockets.</p>
<p>Before writing a single line of domain logic, developers easily spend 30 to 40 hours just on boilerplate configuration.</p>
<p>To streamline this workflow, I engineered and tested a production-ready Laravel 11 Backend Starter Kit designed for e-commerce and composite inventory stores.</p>
<p>Below is an overview of the architectural decisions, security practices, and workflow designs implemented in this codebase.</p>
<p>Clean Architecture: Repository and Service Pattern</p>
<p>While Laravel permits business logic directly inside controllers, doing so in complex e-commerce applications quickly leads to unmaintainable code.</p>
<p>This project implements a strict separation of concerns:</p>
<p>HTTP Request -&gt; FormRequest (Validation) -&gt; Controller -&gt; Service Layer -&gt; Repository Layer -&gt; Eloquent Model</p>
<p>Controllers: Handle HTTP transport, invoke service methods, and return structured JSON responses.</p>
<p>Services (app/Services/): Contain business rules, composite inventory calculations, payment signatures, and job dispatching.</p>
<p>Repositories (app/Repositories/): Abstract database interactions through interfaces (ProductRepositoryInterface, OrderRepositoryInterface), registered via RepositoryServiceProvider.</p>
<p>This structure allows swapping storage engines and writing isolated unit tests with ease.</p>
<p>Authentication and Role-Based Access Control (RBAC)</p>
<p>Modern APIs serve both single-page applications (SPAs) and native mobile clients simultaneously.</p>
<p>Dual-Mode JWT Authentication:<br />The authentication middleware supports two delivery mechanisms:</p>
<p>Bearer Tokens (Authorization: Bearer ) for mobile clients and tools like Postman or Bruno.</p>
<p>HttpOnly Cookies for browser clients to prevent XSS-based token theft.</p>
<p>Role-Based Access Control:<br />The RBAC middleware restricts access based on user roles:</p>
<p>admin: Full control over employee management, inventory configurations, and user accounts.</p>
<p>employee: Access to order fulfillment, stock imports, and reports.</p>
<p>user: Standard customer capabilities.</p>
<p>Recipe-Based Dynamic Inventory Management</p>
<p>Traditional e-commerce platforms often track stock using a simple quantity column on the product table. However, composite stores craft finished goods from raw components.</p>
<p>Example: A Luxury Rose Bouquet (Size M) requires:</p>
<p>10x Red Roses</p>
<p>5x Baby's Breath</p>
<p>1x Packaging Material</p>
<p>The inventory service calculates real-time craftable stock by querying raw material shipments. When an order is created, raw material stock is deducted inside an atomic database transaction.</p>
<p>Automated Daily Stock Importer:<br />Through Laravel's scheduler (php artisan schedule:work), the console command import-receipt:auto-create processes configured daily stock arrivals at specified hours and broadcasts alerts to staff.</p>
<p>Payment Processing and Webhook Verification</p>
<p>Payment processing requires cryptographic verification to prevent spoofed transactions.</p>
<p>The starter kit provides end-to-end flows for payment gateways with signature validation:</p>
<p>Checkout Session: Generates signed checkout URLs using HMAC-SHA512.</p>
<p>Webhook / IPN Verification: Sorts incoming parameters, recomputes the expected signature, and uses hash_equals() to prevent timing attacks. Updates order status to PAID only upon valid signature verification and returns 400 Bad Request if the payload is forged or tampered with.</p>
<p>Realtime WebSockets with Pusher</p>
<p>The backend connects to Pusher Channels for immediate UI synchronization:</p>
<p>admin-orders channel: Triggers instant notifications when a customer completes an order.</p>
<p>admin-auto-imports channel: Alerts staff when the scheduled import command executes.</p>
<p>private-chat.{userId} channel: Facilitates private customer support conversations.</p>
<p>All event broadcasts and transactional emails are queued (php artisan queue:work) to ensure API response latency stays under 50ms.</p>
<p>Security Hardening and Quality Assurance</p>
<p>The codebase includes an automated test suite covering 19 end-to-end scenarios:</p>
<p>Rate Limiting: The login endpoint is protected with throttle:login (10 requests/minute). Repeated failures immediately trigger HTTP 429 Too Many Requests.</p>
<p>SQL Injection and XSS Protection: Prepared statements prevent SQL injection attacks, while custom middleware removes script tags from payloads and adds security headers (X-Content-Type-Options: nosniff, X-Frame-Options: DENY, X-XSS-Protection: 1; mode=block).</p>
<p>File Upload Validation: Provides Cloudinary integration with local disk fallback. File uploads are strictly validated for MIME types (PNG, JPG, WEBP, PDF) and size (under 2MB).</p>
<p>Getting the Starter Kit</p>
<p>This project is packaged as a ready-to-deploy boilerplate.</p>
<p>Included Components:</p>
<p>Full Laravel 11.x source code (PSR-4 compliant)</p>
<p>50+ Database Migrations and Seeders (pre-configured Admin and Demo users)</p>
<p>Ready-to-import Postman / Bruno Collection (postman_collection.json)</p>
<p>Interactive Swagger OpenAPI Documentation (/api/documentation)</p>
<p>Complete setup documentation in English and Vietnamese</p>
<p>Multi-container Docker Compose configuration (app, queue, schedule)</p>
<p>Product Link on Gumroad:<br /><a href="https://vinhcraft17.gumroad.com/l/laravel-ecommerce-starter-kit">https://vinhcraft17.gumroad.com/l/laravel-ecommerce-starter-kit</a></p>
<p>If you have questions regarding the architecture or implementation details, feel free to leave a comment below.</p>
]]></content:encoded></item></channel></rss>