A modern e-commerce platform built with Next.js, TypeScript, and Tailwind CSS, featuring real product images, optimized performance, and powerful search functionality.
We've implemented a comprehensive search system that allows users to find products quickly and efficiently across the entire catalog.
- Global Search Bar: Accessible from navbar on all pages
- Real-time Search: Instant results as you type (debounced for performance)
- Smart Suggestions: Auto-complete suggestions based on product names, categories, and tags
- Recent Searches: Persistent search history with localStorage
- Search Highlighting: Visual highlighting of search terms in results
- Multi-field Search: Searches across product names, descriptions, categories, colors, and tags
Search Store (Zustand):
// lib/stores/search-store.ts
- Global search state management
- Recent searches persistence
- Search results caching
- Loading states and error handling
Search API Functions:
// lib/api/products.ts
- searchProducts(): Full-text search across product data
- getSearchSuggestions(): Auto-complete suggestions
- Relevance-based sorting (exact matches first)
- Performance optimized with debouncing
Advanced Search Component:
// components/search/search-component.tsx
- Dropdown with suggestions and recent searches
- Real-time results preview
- Keyboard navigation (Escape, Ctrl+K)
- Click-outside handling
- Mobile-responsive design
Smart Search Algorithm:
- ✅ Product name matching (exact and partial)
- ✅ Description text search
- ✅ Category matching
- ✅ Color matching
- ✅ Tag-based search
- ✅ Relevance scoring (exact matches prioritized)
- ✅ Case-insensitive search
- ✅ Special character handling
User Experience:
- ✅ Instant Search: Results appear as you type (300ms debounce)
- ✅ Search Suggestions: Auto-complete with recent searches
- ✅ Loading States: Visual feedback during search
- ✅ No Results Handling: Helpful messages and alternatives
- ✅ Search Persistence: Recent searches saved to localStorage
- ✅ URL Integration: Search terms reflected in URL for bookmarking
Search UI Components:
- ✅ Navbar Integration: Seamlessly integrated search bar
- ✅ Mobile Search: Optimized mobile search experience
- ✅ Search Results Page: Dedicated page with filtering
- ✅ Quick Results Preview: Preview results in dropdown
- ✅ Search Query Display: Clear indication of current search
Search Hook:
// hooks/use-search.ts
const {
query,
searchResults,
suggestions,
isSearching,
search,
clear
} = useSearch({
debounceMs: 300,
enableSuggestions: true,
persistToLocalStorage: true
})
Search Utilities:
// lib/utils.ts
- normalizeSearchQuery(): Clean and normalize search terms
- highlightSearchTerm(): Highlight matches in results
- debounce(): Performance optimization for search input
- areQueriesSimilar(): Prevent duplicate recent searches
- Debounced Input: 300ms delay to reduce API calls
- Query Caching: TanStack Query caching for repeated searches
- Stale-while-revalidate: 30s stale time for search results
- Efficient Filtering: Client-side filtering for better performance
- Lazy Loading: Search suggestions loaded only when needed
Basic Search:
// Search for "jacket"
searchProducts("jacket") // Returns leather jacket, denim jacket, etc.
Category Search:
// Search for "shoes"
searchProducts("shoes") // Returns all shoe products
Tag-based Search:
// Search for "casual"
searchProducts("casual") // Returns products tagged as casual
Color Search:
// Search for "black"
searchProducts("black") // Returns all black products
- Search Speed: < 300ms average response time
- Accuracy: Relevance-based scoring ensures best matches first
- Coverage: Searches across 5+ product fields
- UX: Instant feedback with loading states
- Persistence: Recent searches saved locally
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Search Bar │───▶│ Search Store │───▶│ Search API │
│ (Navbar/Page) │ │ (Zustand) │ │ (Products) │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│ │ │
▼ ▼ ▼
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Search UI │ │ Recent Searches │ │ Search Results │
│ (Suggestions) │ │ (localStorage) │ │ (Filtered) │
└─────────────────┘ └──────────────────┘ └─────────────────┘
- Responsive Design: Optimized for mobile screens
- Touch-friendly: Large touch targets and smooth interactions
- Mobile Sheet: Full-screen search on mobile devices
- Keyboard Handling: Proper mobile keyboard support
We've completely replaced placeholder images with high-quality, real product images from Unsplash. Here's what was implemented:
- 12 new products with real clothing images
- Multiple images per product for better product showcasing
- Diverse categories: T-Shirts, Jeans, Blazers, Dresses, Jackets, Sweaters, Shoes, Accessories, Hoodies, Shirts, Athletic wear
- Realistic pricing and detailed descriptions
- Next.js Image Optimization: Configured for external Unsplash images
- Responsive sizing: Optimized for different screen sizes
- Lazy loading: Images load as needed to improve performance
- Error handling: Fallback to placeholder if images fail to load
- Loading states: Smooth transitions with loading animations
ProductCard Component:
- ✅ Loading state indicators
- ✅ Error handling with fallbacks
- ✅ Optimized image sizing
- ✅ Better hover effects
- ✅ Stock status indicators
ProductDetails Component:
- ✅ Image gallery with thumbnail navigation
- ✅ Smooth image transitions
- ✅ Multiple image viewing
- ✅ Enhanced loading states
- ✅ Stock quantity management
Hero Section & Categories:
- ✅ High-quality hero background
- ✅ Category showcase with real fashion images
- ✅ Optimized for different viewports
Next.js Configuration:
// next.config.js
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'images.unsplash.com',
pathname: '/**',
}
],
unoptimized: false, // Enable optimization
}
Utility Functions:
getSafeImageUrl()
- Safe image URL handlinggetOptimizedImageUrl()
- Unsplash URL optimizationformatPrice()
- Consistent price formattingcalculateDiscountPercentage()
- Sale calculations
- Source: High-resolution images from Unsplash
- Optimization: Automatic format conversion (WebP when supported)
- Sizing: Responsive with proper aspect ratios
- Quality: 80% quality for optimal balance of size/quality
- Faster Loading: Optimized images with Next.js Image component
- Better UX: Loading states and smooth transitions
- Mobile Optimized: Responsive images for all devices
- SEO Friendly: Proper alt text and semantic markup
- Error Resilient: Graceful fallbacks if images fail
- Professional Look: Real product photography
- Consistent Styling: Uniform image treatment across components
- Modern Design: Updated hover effects and transitions
- Accessibility: Proper alt text and loading indicators
- TypeScript: Full type safety for image handling
- Error Boundaries: Graceful error handling
- Loading States: User-friendly loading indicators
- Responsive Design: Mobile-first approach
- Performance Monitoring: Optimized Core Web Vitals
# Install dependencies
npm install
# Run development server
npm run dev
# Build for production
npm run build
├── components/
│ ├── products/ # Product-related components
│ ├── search/ # Search components
│ ├── home/ # Homepage components
│ └── ui/ # Reusable UI components
├── lib/
│ ├── api/ # API functions (including search)
│ ├── stores/ # State management (including search store)
│ ├── types.ts # TypeScript definitions
│ └── utils.ts # Utility functions
├── hooks/
│ └── use-search.ts # Search hook
└── app/ # Next.js app directory
- 🔍 Global Search: Advanced search with suggestions and real-time results
- 🖼️ Real Product Images: Professional clothing photography
- 📱 Responsive Design: Mobile-first approach
- ⚡ Performance Optimized: Next.js Image optimization and search debouncing
- 🔒 Type Safe: Full TypeScript implementation
- 🎨 Modern UI: Tailwind CSS + Shadcn/ui components
- 🛒 Shopping Cart: Zustand state management
- 🔧 Product Filtering: Advanced filtering options
- 💾 Search Persistence: Recent searches saved locally
- ⌨️ Keyboard Shortcuts: Ctrl+K to focus search, Escape to close
Category | Technology |
---|---|
Framework | Next.js 14 (App Router, RSC) |
Language | TypeScript 5 |
UI & Styling | Tailwind CSS, Radix UI primitives via shadcn/ui, tailwind-merge, tailwindcss-animate |
State Management | Zustand |
Data Fetching | TanStack React Query (+ Devtools) |
Validation | Zod |
Auth & DB | Firebase v10 (easily swappable for Supabase) |
Charts & Visuals | Recharts |
Carousel | Embla Carousel |
Icons | Lucide-react |
Misc | clsx, cva, immer, date-fns, use-sync-external-store |
All dependencies are pinned to their latest stable versions as listed in
package.json
.
Built with ❤️ using Next.js, TypeScript, and modern web technologies.