Skip to content

dani7115/trustfactory_assessment

Repository files navigation

E-Commerce Shopping Cart System

A full-featured e-commerce shopping cart application built with Laravel 12, Livewire 3, and Tailwind CSS. This project demonstrates modern Laravel development practices with real-time interactions, queue jobs, scheduled tasks, and comprehensive admin management.

πŸš€ Quick Start

Access Links

Customer Login: http://trustfactory_assessment.test/login
Admin Login: http://trustfactory_assessment.test/admin/login
Home Page: http://trustfactory_assessment.test

Login Credentials

Admin Account

  • Email: admin@test.com
  • Password: password
  • Access: Admin panel for managing products and orders

Customer Account

  • Email: customer@test.com
  • Password: password
  • Access: Full shopping experience (browse, cart, orders)

πŸ“‹ Features

Customer Features

Product Browsing

  • Browse products with images, descriptions, and pricing
  • Search products by name
  • Filter products by category
  • Real-time pagination without page refresh
  • Stock availability indicators
  • Product images with fallback placeholders

Shopping Cart

  • Add products to cart with stock validation
  • Update item quantities with real-time stock checks
  • Remove items from cart
  • View cart total and item subtotals
  • Automatic stock management (decrements on add, increments on remove)
  • Loading states on all cart actions

Order Management

  • View order history with pagination
  • Detailed order receipts in modal popup
  • Order status tracking
  • Customer information preservation

Dashboard

  • Overview statistics (Total Products, My Orders, Cart Items, Low Stock)
  • Recent orders list
  • Quick action links
  • Real-time data updates

Admin Features

Product Management

  • Create, edit, and delete products
  • Upload product images
  • Manage product details (name, description, price, stock)
  • Category assignment
  • View all products in table format
  • Low stock indicators

Order Management

  • View all customer orders
  • Filter orders by status (pending, processing, shipped, delivered)
  • Update order status with automatic email notifications
  • View detailed order information
  • Customer information display

Automated Notifications

  • Low stock email alerts (triggered when stock ≀ 10)
  • Order confirmation emails
  • Order status update emails
  • All emails sent via queue system

Scheduled Jobs

  • Daily sales report (runs every evening at 8:00 PM)
  • Email report with total orders, revenue, and product sales breakdown

πŸ—οΈ Architecture

Database Structure

Core Tables

  • users - Customer accounts
  • admins - Admin accounts (for future multi-admin support)
  • categories - Product categories
  • products - Product catalog with images and stock tracking
  • carts - User shopping carts
  • cart_items - Individual cart items
  • orders - Customer orders with status tracking
  • order_items - Order line items with product snapshots
  • customer_infos - Preserved customer information

Key Design Decisions

Data Persistence

  • Order Items: Store product name, SKU, and description to preserve order history even if products are deleted
  • Customer Info: Store customer details separately to maintain order records if user account is deleted
  • Product Images: Stored in storage/app/public/products with symbolic link to public access

Stock Management

  • Stock is decremented when items are added to cart
  • Stock is incremented when items are removed from cart
  • Stock validation occurs at checkout to prevent overselling
  • Low stock threshold: 10 units or less

Order Workflow

  1. Pending - Order created
  2. Processing - Order confirmed, stock deducted
  3. Shipped - Order shipped to customer
  4. Delivered - Order completed

Service Classes

OrderService

  • Handles order status updates
  • Manages status timestamps
  • Sends email notifications on status changes

ProductService

  • Manages product image uploads
  • Handles image deletion
  • Provides image update functionality

Queue System

Jobs

  • LowStockNotification - Sends email when product stock is low
  • DailySalesReport - Generates and emails daily sales summary

Queue Configuration

  • Default driver: database
  • Jobs are queued for background processing
  • Run queue worker: php artisan queue:work

Scheduled Tasks

Daily sales report runs automatically via Laravel scheduler:

  • Schedule: Every day at 8:00 PM
  • Location: routes/console.php
  • Command: Schedule::job(new DailySalesReport)->dailyAt('20:00')

πŸ”§ Technical Stack

  • Framework: Laravel 12
  • Frontend: Livewire 3, Tailwind CSS, Flux UI Components
  • Authentication: Laravel Fortify
  • Database: SQLite (default), supports MySQL/PostgreSQL
  • Queue: Database queue driver
  • File Storage: Local filesystem with public disk

πŸ“ Project Structure

app/
β”œβ”€β”€ Jobs/
β”‚   β”œβ”€β”€ LowStockNotification.php
β”‚   └── DailySalesReport.php
β”œβ”€β”€ Livewire/
β”‚   β”œβ”€β”€ Products.php (Customer product browsing)
β”‚   β”œβ”€β”€ Cart.php (Shopping cart management)
β”‚   β”œβ”€β”€ Orders.php (Customer order history)
β”‚   └── Admin/
β”‚       β”œβ”€β”€ Products.php (Admin product management)
β”‚       └── Orders.php (Admin order management)
β”œβ”€β”€ Models/
β”‚   β”œβ”€β”€ User.php
β”‚   β”œβ”€β”€ Admin.php
β”‚   β”œβ”€β”€ Product.php
β”‚   β”œβ”€β”€ Category.php
β”‚   β”œβ”€β”€ Cart.php
β”‚   β”œβ”€β”€ CartItem.php
β”‚   β”œβ”€β”€ Order.php
β”‚   β”œβ”€β”€ OrderItem.php
β”‚   └── CustomerInfo.php
β”œβ”€β”€ Notifications/
β”‚   β”œβ”€β”€ OrderConfirmation.php
β”‚   └── OrderStatusUpdate.php
└── Services/
    β”œβ”€β”€ OrderService.php
    └── ProductService.php

🎯 How It Works

Shopping Flow

  1. Browse Products

    • Customer visits products page
    • Searches or filters products
    • Views product details and stock availability
  2. Add to Cart

    • Customer clicks "Add to Cart"
    • System validates stock availability
    • Creates or updates cart item
    • Decrements product stock
    • Shows loading state during process
  3. Manage Cart

    • Customer can update quantities
    • System validates against available stock
    • Stock adjusts in real-time
    • Cart total updates automatically
  4. Checkout

    • System validates all items are still available
    • Creates order with customer information snapshot
    • Creates order items with product snapshots
    • Deducts stock from products
    • Checks for low stock and dispatches notifications
    • Sends order confirmation email
    • Clears cart
  5. Order Tracking

    • Customer views order history
    • Admin updates order status
    • Customer receives email notifications on status changes

Admin Workflow

  1. Product Management

    • Admin logs in and accesses "Manage Products"
    • Can create new products with images
    • Can edit existing products
    • Can delete products (order history preserved)
  2. Order Management

    • Admin views all orders
    • Filters by status if needed
    • Updates order status (processing β†’ shipped β†’ delivered)
    • System automatically sends email notifications

Background Processing

  1. Low Stock Notifications

    • Triggered when product stock drops to 10 or below
    • Job dispatched to queue
    • Email sent to admin@test.com
    • Includes product name and current stock level
  2. Daily Sales Report

    • Scheduled to run daily at 8:00 PM
    • Queries all orders from current day
    • Calculates total revenue, orders, and items sold
    • Groups by product for detailed breakdown
    • Emails comprehensive report to admin

πŸ” Security Features

  • Password hashing using bcrypt
  • CSRF protection on all forms
  • Authentication middleware on protected routes
  • Input validation on all user inputs
  • SQL injection protection via Eloquent ORM
  • XSS protection via Blade templating

🎨 UI/UX Features

  • Responsive design (mobile, tablet, desktop)
  • Dark mode support
  • Loading states on all interactive buttons
  • Real-time updates without page refresh
  • Modal dialogs for detailed views
  • Toast notifications for user feedback
  • Smooth transitions and animations

πŸ“Š Database Seeding

The seeder creates:

Run seeder:

php artisan db:seed

🚦 Setup Instructions

  1. Install Dependencies

    composer install
    npm install
  2. Environment Setup

    cp .env.example .env
    php artisan key:generate
  3. Database Setup

    php artisan migrate
    php artisan db:seed
    php artisan storage:link
  4. Start Development Server

    php artisan serve
    npm run dev
  5. Start Queue Worker (for background jobs)

    php artisan queue:work

πŸ“ Notes

  • All prices are stored as decimals with 2 decimal places
  • Stock quantities are integers
  • Product images are optional (placeholder shown if missing)
  • Order items preserve product information even if product is deleted
  • Customer information is preserved in orders even if user is deleted
  • Admin panel is accessible only to admin@test.com email
  • Queue must be running for email notifications to work
  • Scheduler must be running for daily sales reports

πŸŽ“ Learning Points

This project demonstrates:

  • Laravel best practices and conventions
  • Livewire component architecture
  • Queue and job processing
  • Scheduled tasks (cron jobs)
  • Service layer pattern
  • Database relationships and migrations
  • File upload handling
  • Email notifications
  • Real-time UI updates
  • Responsive design with Tailwind CSS
  • Authentication and authorization
  • Data persistence strategies

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages