Skip to content

A Laravel 12 application for uploading and processing CSV files with background job processing, real-time status updates, and idempotent product data management

Notifications You must be signed in to change notification settings

shahswiene/YoPrint_Laravel_Coding_Project

Repository files navigation

YoPrint Laravel CSV Upload System

A Laravel 12 application for uploading and processing CSV files with background job processing, real-time status updates, and idempotent product data management.

Features

  • CSV File Upload - Drag-and-drop or click to upload CSV files (up to 50MB)
  • Background Processing - Redis/Database queue with worker processes CSV files asynchronously
  • Real-time Status Updates - Auto-refreshing UI with color-coded status badges
  • Idempotent Uploads - UPSERT products by UNIQUE_KEY (no duplicates)
  • UTF-8 Cleaning - Automatic cleaning of non-UTF-8 characters
  • API Transformers - Fractal transformers for clean JSON responses
  • Comprehensive Tests - PHPUnit feature and unit tests

Tech Stack

  • Backend: Laravel 12 (PHP 8.2)
  • Database: SQLite
  • Queue: Redis (via Predis) or Database driver
  • Frontend: TailwindCSS, Vanilla JavaScript
  • Testing: PHPUnit

Installation

Prerequisites

  • PHP 8.2+
  • Composer
  • Docker (for Redis)
  • Git

Setup Steps

  1. Clone the repository

    git clone https://github.com/shahswiene/YoPrint_Laravel_Coding_Project.git
    cd YoPrint_Laravel_Coding_Project
  2. Install dependencies

    composer install
  3. Configure environment

    cp .env.example .env
    php artisan key:generate
  4. Update .env file

    DB_CONNECTION=sqlite
    QUEUE_CONNECTION=redis
    REDIS_CLIENT=predis
    REDIS_HOST=127.0.0.1
    REDIS_PORT=6379
  5. Run migrations

    php artisan migrate
  6. Start Redis (Docker)

    docker run -d --name redis -p 6379:6379 redis:alpine
  7. Start Laravel server

    php artisan serve
  8. Start queue worker (in separate terminal)

    php artisan queue:work redis --tries=3 --timeout=300
  9. Open browser

    http://127.0.0.1:8000
    

Running Tests

Run all tests:

php artisan test

Run specific test suite:

# Feature tests
php artisan test --testsuite=Feature

# Unit tests
php artisan test --testsuite=Unit

Run with coverage:

php artisan test --coverage

CSV Format

The application expects CSV files with the following columns:

Column Description
UNIQUE_KEY Unique identifier for product
PRODUCT_TITLE Product name
PRODUCT_DESCRIPTION Product description
STYLE# Style number
SANMAR_MAINFRAME_COLOR Color code
SIZE Product size
COLOR_NAME Color display name
PIECE_PRICE Product price

Example CSV

UNIQUE_KEY,PRODUCT_TITLE,PRODUCT_DESCRIPTION,STYLE#,SANMAR_MAINFRAME_COLOR,SIZE,COLOR_NAME,PIECE_PRICE
TEST001,Sample Product,A great product,STY001,Blue,L,Navy Blue,25.99
TEST002,Another Product,Another description,STY002,Red,M,Crimson,19.99

API Endpoints

Upload Status

GET /api/uploads/status

Returns JSON with Fractal transformer:

{
  "data": [
    {
      "id": 1,
      "filename": "test.csv",
      "status": "completed",
      "progress": {
        "total": 100,
        "processed": 100,
        "percentage": 100
      },
      "uploaded_at": "2025-10-28T14:00:00+00:00",
      "uploaded_at_human": "5 minutes ago",
      "error": null
    }
  ]
}

Testing

Test Coverage

  • UploadControllerTest (Feature)

    • Upload page display
    • File upload validation
    • File type validation
    • File size limits
    • Idempotent uploads
    • Queue job dispatch
    • API status endpoint
  • ProcessCsvUploadJobTest (Unit)

    • CSV parsing and product creation
    • UPSERT by UNIQUE_KEY
    • UTF-8 character cleaning
    • Empty CSV handling
    • Error handling and failed status

Running Specific Tests

# Run upload controller tests
php artisan test --filter=UploadControllerTest

# Run CSV job tests
php artisan test --filter=ProcessCsvUploadJobTest

Project Structure

app/
├── Http/Controllers/
│   └── UploadController.php       # Upload handling & API
├── Jobs/
│   └── ProcessCsvUpload.php       # Background CSV processing
├── Models/
│   ├── Product.php                # Product model
│   └── Upload.php                 # Upload tracking model
└── Transformers/
    └── UploadTransformer.php      # API response transformer

tests/
├── Feature/
│   └── UploadControllerTest.php   # Feature tests
└── Unit/
    └── ProcessCsvUploadJobTest.php # Unit tests

License

The Laravel framework is open-sourced software licensed under the MIT license.

About

A Laravel 12 application for uploading and processing CSV files with background job processing, real-time status updates, and idempotent product data management

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages