-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrocerease_v2_ultimate_documentation.txt
More file actions
231 lines (203 loc) · 12.3 KB
/
Copy pathgrocerease_v2_ultimate_documentation.txt
File metadata and controls
231 lines (203 loc) · 12.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
================================================================================
🏆 GROCEREASE V2 — ENTERPRISE E-COMMERCE ULTIMATE REPORT 🏆
================================================================================
Author: Antigravity AI Senior Architect
Target: Rabin Mishra | IT Engineer | NEC Regd: 97236
Project: GrocerEase v2
Tech Stack: Laravel 11, PHP 8.3, SQLite/PostgreSQL, S3/Cloudflare R2, Bootstrap 5
Date: May 18, 2026
================================================================================
--------------------------------------------------------------------------------
1. EXECUTIVE SUMMARY
--------------------------------------------------------------------------------
GrocerEase v2 is a modern, high-performance, secure, and production-ready rewrite
of the legacy GrocerEase e-commerce website. The legacy codebase relied on
vulnerable, unauthenticated procedural scripts, direct database query injections,
IP-based shopping carts, and local disk image persistence.
This v2 system transforms GrocerEase into an enterprise-grade platform. Built
on Laravel 11 and PHP 8.3, it introduces a clean Service-Repository pattern,
strict role-based access controls, automatic guest-to-customer cart merging,
atomic checkouts with double-spend protection, dual Nepalese payment gateways
(eSewa v2 and Khalti), custom GD image processing, fully decoupled S3-compatible
object storage (Cloudflare R2 / DigitalOcean Spaces), a widescreen fluid design,
and responsive UI layouts with advanced navigation controls.
--------------------------------------------------------------------------------
2. SYSTEM ARCHITECTURE & DESIGN PATTERNS
--------------------------------------------------------------------------------
GrocerEase v2 uses a highly decoupled Service-Repository pattern to separate
business validation, database operations, third-party payment gateways, and
image optimization from controller actions.
[Client Browser]
│ (HTTP Requests & WebSockets)
▼
[Controllers Layer] (Thin, Handles Requests & Responses)
│
├──────────────► [Eloquent Models] (Database Schema Mapping)
│
▼
[Services Layer] (Fat, Encapsulates All Business Logic)
│
├──────────────► [OrderService] (Atomic Transaction & Catalog Locks)
├──────────────► [CartService] (Session UUID Sync & Deduplication)
├──────────────► [PaymentService] (eSewa HMAC-SHA256 & Khalti REST Client)
├──────────────► [ProductService] (Advanced Search & Filter Pipelines)
│
▼
[Infrastructure Layer]
│
├──────────────► [Cloud Storage Disk] (Cloudflare R2 / S3 Decoupling)
├──────────────► [Database Engine] (PostgreSQL / SQLite)
└──────────────► [Nepali Gateways] (eSewa / Khalti APIs)
--------------------------------------------------------------------------------
3. STAGE-BY-STAGE COMPLETED ACCOMPLISHMENTS
--------------------------------------------------------------------------------
STAGE 3: ENTERPRISE AUTHENTICATION & ADMIN PROTECTION
* Legacy Flaw: The admin backend was accessible to any visitor simply by
navigating to "/admin_area", with zero authentication or validation.
* V2 Accomplishment: Integrated a robust, BCrypt-hashed role-based access
control (RBAC) guard.
* Security Gatekeeper: Built custom 'AdminMiddleware' which intercepts all
restricted routes.
* Friendly Visibility Guards: The "Admin Terminal" link is completely hidden
from guests and standard customers. If standard users attempt to access the
admin area directly, they are greeted by a descriptive 403 Forbidden page
instructing them exactly how to log out of their account and log in as admin.
Once logged in as an administrator, the green dropdown navbar dynamically
reveals the "Admin Dashboard" button.
STAGE 4: HIGH-PERFORMANCE PRODUCT CATALOG
* Legacy Flaw: Missing SEO URLs, raw direct query interpolations, and
calculating pagination manually in SQL.
* V2 Accomplishment: Engineered a dynamic, index-optimized search and multi-
filtering system inside 'ProductService'.
* Key Capabilities: Supports wildcard search, categories, brands, and minimum/
maximum price filtering. Generates SEO-friendly URLs using unique database
slug hooks.
STAGE 5: SESSION-CART ENGINE WITH AUTO-MERGING
* Legacy Flaw: The cart associated items strictly to the visitor's IP address.
Multiple users on the same Wi-Fi shared the same cart, and logging in on a
different device wiped all selected items.
* V2 Accomplishment: Designed a robust, dual-state 'CartService' engine.
* State Synchronization: Guests are tracked using a secure, session-stored UUID
('session("cart_id")'). Authenticated users are tracked directly via their
persistent 'user_id' in the database.
* Reconciler Mechanism: Upon login, the guest cart is automatically reconciled
and merged into the user's permanent cart, dynamically merging matching items,
deduplicating stock entries, and enforcing inventory boundaries.
STAGE 6: ATOMIC CHECKOUT & DOUBLE-SPEND MITIGATION
* Legacy Flaw: No database transactions. Parallel requests could buy products
simultaneously, driving inventory below zero and causing overselling.
* V2 Accomplishment: Engineered transactional checkout inside 'OrderService'.
* Concurrency Defense: Uses 'DB::transaction' with pessimistic locking
('sharedLock'/'lockForUpdate'). It snapshots live product catalog prices at
the millisecond of checkout and instantly rolls back the entire checkout if
any item stock drops below requested levels.
STAGE 7: DUAL NEPALESE PAYMENT GATEWAY INTEGRATIONS
* eSewa (v2 Payload Protocol): Implements eSewa's latest merchant API using
HMAC-SHA256 signature generation and Base64 request payloads. Automatically
renders a secure auto-POST payment redirect form.
* Khalti Sandbox Integration: Fully API-driven payment gateway. Requests
initiations dynamically from Khalti servers, redirects customers to their
secure transaction portal, and handles callback verification on return.
* Audit Trails: Transparently logs all payments, updating order states from
'pending' to 'completed' or 'failed' to ensure clean business accounting.
STAGE 8: ADMIN DASHBOARD & CUSTOM IMAGE OPTIMIZER
* Dashboard Analytics: Renders a real-time business statistics suite showing
Total Revenue (completed payments), Total Order Counts, Total Catalog Items,
Recent Orders, and alert flags for low-stock products (stock < 5).
* custom Image Uploader: Uses 'Intervention Image (v3)' to intercept product
photo uploads, dynamically resizing them down to an optimized '800x800px'
square (preserving aspect ratio) to maximize page load speeds.
STAGE 9: DECOUPLED CLOUD STORAGE & IMAGE MIGRATOR
* Cloud Storage Abstraction: Configured S3 Flysystem drivers. Replaced all
hardcoded storage calls with dynamic config-driven disk drivers.
* Cloud Ready: In local development, the system uses 'local' storage. For staging
and production deployment, changing a single line in '.env' ('FILESYSTEM_DISK=r2')
redirects all uploads and serves all assets directly from Cloudflare R2 or
DigitalOcean Spaces with ZERO code modifications.
* Console Migration Tool: Built and executed `php artisan grocerease:migrate-images`,
which scanned all 48 legacy catalog images, uploaded them to the new active
storage engine, and updated all database references without a single error.
STAGE 10: FLUID WIDESCREEN, SECTION SCROLLS & MOBILE RESPONSIVENESS
* Fluid Widescreen: Replaced narrow containers with widescreen fluid layouts
('.container-fluid px-lg-5 px-md-4 px-3'). The site now beautifully stretches
end-to-end on high-resolution widescreen monitors.
* Homepage Ordering: Rearranged visual sections to place Featured Products first
on the homepage, followed by Categories, and then Brands, keeping the layout
dynamic and modern.
* Smooth Scrolling: Integrated smooth section anchor points for Navbar buttons
('#categories-section', '#brands-section', '#contact-footer') with native
CSS `scroll-behavior: smooth`.
* Mobile Responsive Collapsible Navbar: Optimized the entire design for mobile
viewports, featuring a clean brand-green responsive hamburger menu.
--------------------------------------------------------------------------------
4. LOCAL SETUP & CHRONOLOGICAL EXECUTION GUIDE
--------------------------------------------------------------------------------
Follow these steps in exact chronological order to launch the application:
1. Initialize Environment Configuration:
$ cp .env.example .env
2. Install Project Dependencies:
$ composer install
3. Generate Secret Key:
$ php artisan key:generate
4. Run Database Migrations & Seeders:
$ php artisan migrate:fresh --seed
5. Migrate Legacy Product Images to Storage Engine:
$ php artisan grocerease:migrate-images
6. Expose Storage Disk to the Web Server:
$ php artisan storage:link
7. Launch Local Web Server:
$ php artisan serve
(Application will be hosted at: http://127.0.0.1:8000)
8. Execute the Automated Test Suite (100% Success Guard):
$ ./vendor/bin/phpunit
--------------------------------------------------------------------------------
5. OUT-OF-THE-BOX LOGIN CREDENTIALS
--------------------------------------------------------------------------------
| User Role | Username / Email | Password | Access Level |
| :-------------- | :-------------------- | :---------- | :-------------------- |
| Administrator | admin@grocerease.com | Admin@1234 | Full Admin Dashboard |
| Customer (Test) | test@grocerease.com | Test@1234 | Customer Storefront |
*Important Note: If you are logged into the storefront as the customer, you
must click "Logout" in the top-right menu before accessing the Admin Dashboard.
--------------------------------------------------------------------------------
6. DETAILED FOLDER & CODE DIRECTORY MAP
--------------------------------------------------------------------------------
Below is the directory map of the critical files modified in this rewrite:
grocerease-v2/
├── app/
│ ├── Http/
│ │ ├── Controllers/
│ │ │ ├── Admin/
│ │ │ │ ├── DashboardController.php # Real-time dashboard metrics
│ │ │ │ ├── ProductController.php # Product CRUD & image resize
│ │ │ │ ├── CategoryController.php # Category management
│ │ │ │ └── OrderController.php # AJAX order statuses
│ │ │ ├── HomeController.php # Rearranged home catalog bindings
│ │ │ └── PaymentController.php # Payment gateway orchestrators
│ │ └── Middleware/
│ │ └── AdminMiddleware.php # Custom Admin guard with error guide
│ └── Services/
│ ├── ProductService.php # High-performance catalog filter
│ ├── CartService.php # Guest session reconciler
│ ├── OrderService.php # Atomic checkouts & locks
│ └── PaymentService.php # HMAC signatures & APIs
│
├── config/
│ └── filesystems.php # Cloudflare R2 disk definitions
│
├── routes/
│ └── web.php # Prefix router & admin redirects
│
├── resources/
│ └── views/
│ ├── layouts/
│ │ └── app.blade.php # Fluid layout, green legible footer
│ ├── home.blade.php # Swapped visual sections order
│ └── products/
│ ├── index.blade.php # Fullscreen catalog view
│ └── show.blade.php # Fullscreen product details view
│
└── storage/logs/ # System execution logs directory
================================================================================
🎉 CONGRATULATIONS! THE SYSTEM IS DEPLOYMENT READY! 🎉
================================================================================