Skip to content

romainjacquel/challenges

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Solution Summary

Completed Tasks

🔧 Backend Improvements

1. Refactored Blocking I/O

  • Replaced fs.readFileSync() with async fs.promises API in items.js
  • All file operations now non-blocking (readData/writeData functions)
  • Improved error handling with proper HTTP status codes

2. Server-Side Pagination & Search

  • Implemented paginated API responses with metadata:
    {
      "data": [...],
      "pagination": {
        "page": 1,
        "pageSize": 20,
        "totalItems": 100,
        "totalPages": 5,
        "hasNextPage": true,
        "hasPrevPage": false
      }
    }
  • Added search by name and category via ?q= query parameter
  • Configurable page size (10/20/50/100 items, max 100)
  • Backward compatible with legacy ?limit= parameter

3. Performance Optimization

  • stats.js already implements caching with fs.watch() for file changes
  • Stats recalculate only when data file is modified
  • Cache invalidation automatic and efficient

4. Testing

  • Comprehensive unit tests in items.spec.js
  • 100% route coverage: GET all/by ID, POST, search, pagination, error cases
  • 25+ test cases with proper data backup/restore
  • All tests passing ✅

💻 Frontend Improvements

1. Memory Leak Fix

2. Pagination & Search Implementation

  • Server-side pagination with client state management
  • Debounced search input (300ms delay)
  • Page size selector (10/20/50/100)
  • Jump to page input
  • Navigation buttons (Previous/Next) with disabled states
  • Real-time results count display

3. Performance Considerations

  • React-window NOT used: Encountered integration issues during implementation
  • Given the 1-hour time constraint and unfamiliarity with the library, opted for pragmatic solution
  • Alternative approach: Server-side pagination effectively limits rendered DOM nodes (max 100 items per page)
  • Smooth scrolling with custom scrollbar styling
  • Staggered fade-in animations (30ms delay per item)

4. UI/UX Enhancements

  • Modern design with Tailwind-inspired color palette
  • Skeleton loaders with shimmer animation
  • Comprehensive error states with retry functionality
  • Empty state with contextual messaging
  • Search clear button with icon
  • Fully responsive (mobile breakpoints: 768px, 480px)
  • Accessibility improvements:
    • ARIA labels and live regions
    • Semantic HTML (role attributes)
    • Screen reader-only labels
    • Keyboard navigation support

📦 Additional Improvements

Dataset

  • Created 100-item test dataset in items.json
  • 4 categories: Electronics (43), Office Supplies (42), Furniture (10), Appliances (5)
  • Price range: $4 - $2,499

UI Components

Trade-offs & Decisions

Why No react-window?

During implementation, I encountered compatibility issues with react-window v2.x. The library expected specific prop formats that caused runtime errors (Object.values(undefined)). Given:

  1. Time constraint: 1-hour assessment window
  2. Unfamiliarity: Never used react-window before
  3. Documentation time: Would require significant reading
  4. Pragmatic solution exists: Server-side pagination achieves the same goal

Decision: Implemented server-side pagination instead, which:

  • Limits network payload (only 10-100 items per request)
  • Reduces DOM nodes (same performance benefit as virtualization)
  • Provides better user experience with search/filter
  • Easier to maintain and debug

Performance Analysis

Server-side pagination vs. Virtualization:

  • Both limit rendered DOM nodes ✅
  • Server approach reduces network payload ✅
  • Virtualization better for static large datasets ❌ (not our use case)
  • Server approach scales better with database integration ✅

Testing

# Backend tests (all passing)
cd backend
npm test

# Test coverage: 100% routes, 25+ test cases
# ✓ GET /api/items (pagination, search, limit)
# ✓ GET /api/items/:id (valid, invalid, not found)
# ✓ POST /api/items (validation, edge cases)
# ✓ Error handling (malformed JSON, etc.)

Running the Application

# Terminal 1 - Backend (port 3001)
cd backend
npm install
npm start

# Terminal 2 - Frontend (port 3000)
cd frontend
npm install
npm start

Test URLs:

  • http://localhost:3000/ - Browse all items (paginated)
  • http://localhost:3000/?q=laptop - Search example
  • http://localhost:3000/items/1 - Item detail page

API Examples:

  • GET /api/items?page=1&pageSize=20 - Paginated
  • GET /api/items?q=electronics&page=1&pageSize=10 - Search + pagination
  • GET /api/stats - Stats with caching

Code Quality

  • ✅ Clean, idiomatic React/Node.js code
  • ✅ Proper error handling at all levels
  • ✅ Comprehensive comments where needed
  • ✅ Type validation (input sanitization)
  • ✅ Security considerations (abort controllers, input trimming)
  • ✅ Accessibility (ARIA, semantic HTML)
  • ✅ Responsive design (mobile-first approach)
  • ✅ Performance optimizations (debouncing, memoization)

Time Breakdown (approx. 1 hour)

  • Backend refactoring & pagination: 20 min
  • Frontend pagination & search: 20 min
  • UI/UX improvements & styling: 15 min
  • Testing & debugging: 5 min

Note: All objectives from the assessment were completed successfully, with the exception of react-window integration (replaced with equally effective server-side pagination approach due to time constraints and unfamiliarity with the library).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors