Production-ready REST API with AOP architecture, concurrency control, and scalable queue processing
A scalable Laravel REST API powering a full e-commerce platform with a clean Service Layer architecture, Aspect-Oriented Programming (AOP) for cross-cutting concerns, concurrency-safe processing, and a Redis queue system monitored via Horizon.
Business logic is isolated in dedicated services. Cross-cutting concerns are handled via a Decorator-based AOP simulation:
- Logging Aspect — activity and error logging
- Performance Aspect — execution time, memory, query count
- Tracing Aspect — full request lifecycle (start → end)
- Error Handling Aspect — centralized exception management
- Transaction Aspect — atomic DB operations
Services contain pure business logic only — no logging, no error handling, no transaction management mixed in.
| Mechanism | Purpose |
|---|---|
Cache::lock() |
Global checkout throttling |
DB::transaction() |
Atomic operations |
lockForUpdate() |
Row-level locking |
Prevents overselling and ensures consistency under concurrent requests.
Three dedicated log streams:
| Log Type | Purpose |
|---|---|
| Tracing | Request lifecycle (start → end) |
| Activity | Business events and failures |
| Performance | Execution time, memory, query count |
Enables before/after performance comparison and simplifies debugging of concurrency issues.
Redis-backed queues with Laravel Horizon for monitoring. Handles OTP email delivery via Gmail SMTP. Decouples heavy operations from the request cycle and improves response time.
Authentication — Registration, login, OTP email verification, Sanctum token-based auth
User Profile — View, update profile, change avatar
Product Browsing — Categories → Stores → Products, product details, search across products and stores
Favorites — Add/remove favorites, organized by category
Cart — Add/update/remove items, 50-item capacity limit, concurrency-safe updates
Orders — Place and cancel orders, view history, automatic stock updates on delivery and cancellation
| Layer | Technology |
|---|---|
| Backend | Laravel 11 |
| Language | PHP 8+ |
| Database | MySQL |
| Queues | Redis |
| Monitoring | Laravel Horizon |
| Auth | Sanctum |
| Gmail SMTP | |
| API Testing | Postman |
git clone https://github.com/karamlk/ecommerce-backend-api.git
cd ecommerce-backend-apicomposer installcp .env.example .env
php artisan key:generateEdit .env with your database and Gmail SMTP credentials:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database
DB_USERNAME=your_username
DB_PASSWORD=your_password
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=your_email@gmail.com
MAIL_PASSWORD=your_gmail_app_password
MAIL_ENCRYPTION=tlsphp artisan migratephp artisan db:seedsudo service redis-server start
php artisan serveBasic worker:
php artisan queue:workOr Laravel Horizon (recommended):
php artisan horizonHorizon dashboard: http://localhost:8000/horizon
Import the Postman collection included in the repository:
postman/Ecommerce-Backend-api.postman_collection.json
All protected endpoints require:
Authorization: Bearer {token}Product, store, and user images are not included in the repository. Seeded data references files under storage/product_photos/, storage/profile_photos/, and storage/store_photos/. Missing images fall back to a placeholder automatically.