A modern e-commerce product listing and detail page built with Next.js 15, TypeScript, and Tailwind CSS. This application demonstrates a complete product catalog with shopping cart functionality, responsive design, and comprehensive testing.
- πͺ Product Catalog: Responsive product grid with category filtering
- π± Product Details: Comprehensive product information with star ratings
- π Shopping Cart: Full cart functionality with add/remove/update operations
- π¨ Modern UI: Clean design using commerce-main theme principles
- π± Responsive: Mobile-first design with seamless tablet/desktop experience
- π Dark Mode: Automatic theme switching based on system preferences
- βΏ Accessibility: Proper ARIA labels and keyboard navigation
- π§ Type Safety: Full TypeScript implementation
- β Comprehensive Testing: 91 tests with 100% pass rate
| Technology | Version | Purpose |
|---|---|---|
| Next.js | 15.4.4 | React framework with App Router |
| TypeScript | ^5.0 | Type safety and development experience |
| Tailwind CSS | ^4.0 | Utility-first styling with plugins |
| Axios | ^1.11.0 | HTTP client for API requests |
| Jest | ^30.0.5 | Testing framework |
| React Testing Library | ^16.3.0 | Component testing utilities |
| Heroicons | ^2.2.0 | Consistent SVG icon system |
| React Hot Toast | ^2.5.2 | Toast notifications |
| Headless UI | ^2.2.6 | Accessible UI components |
- Node.js 22.0 or later
- npm
-
Clone the repository:
git clone <repository-url> cd next-js-ecommerce-product-listing
-
Install dependencies:
npm install
-
Environment Configuration:
# Copy example environment file cp .env.example .env # Edit .env with your configuration (optional - defaults provided)
-
Run health check and start development server:
npm run dev
The application will:
- β Perform API health check
- π Start on http://localhost:3000
- π Display startup status
# Start without health check
npm run dev:skip-check
# Run health check only
npm run health-check
# Build for production
npm run build
# Start production server
npm startβββ src/
β βββ app/ # Next.js 15 App Router
β β βββ product/[id]/ # Dynamic product detail pages
β β β βββ page.tsx # SSR product page with metadata
β β βββ products/ # Product listing page
β β βββ globals.css # Global styles with Tailwind
β β βββ layout.tsx # Root layout with providers
β β βββ page.tsx # Homepage with welcome + products
β βββ components/ # Reusable UI components
βββ scripts/
β βββ health-check.js # API health check script
βββ .env # Environment variables
βββ .env.example # Environment template
βββ jest.config.js # Jest configuration
The application uses environment variables for configuration:
# Store Configuration
NEXT_PUBLIC_STORE_NAME="E-Commerce"
# Server Configuration
PORT=3000
# API Configuration
NEXT_PUBLIC_API_URL=https://fakestoreapi.com/products- π API URL: Configurable product data endpoint
- πͺ Custom Port: Configurable server port (default: 3000)
- πͺ Store Name: Dynamic store branding
- β Health Check: Automatic API validation on startup
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run with coverage report
npm test -- --coverage
# Run specific test file
npm test ProductCard.test.tsx| Test Suite | Tests | Coverage |
|---|---|---|
| ProductsContext | 14 | Global state, API integration, category filtering |
| ProductDescription | 22 | Product display, ratings, add to cart functionality |
| Loading Component | 22 | UI states, accessibility, edge cases |
| ProductService | 9 | API calls, error handling, environment config |
| CartContext | 9 | Cart operations, calculations |
| Cart Component | 11 | Cart UI, quantity controls |
| ProductCard | 5 | Product display, interactions |
- π― User-Centric: Tests from user perspective using Testing Library
- π§ Comprehensive Mocking: API calls, contexts, timers, environment variables
- β‘ Performance: Fast test suite (< 2 seconds)
- π Async Testing: Proper handling of API calls and state updates
- βΏ Accessibility: Screen reader and keyboard navigation testing
- π± Responsive: Component testing across different viewports
- Welcome header with configurable store name
- Category filtering with visual indicators
- Product grid with responsive layout (1β2β3β4 columns)
- Loading states and error handling
- Redirect handling for direct product URL access
- Dedicated product catalog page
- Category-based filtering
- Product count display
- Consistent grid layout with homepage
- SSR with Metadata: SEO-optimized with dynamic titles
- Star Ratings: Visual rating display with filled/empty stars
- Add to Cart: Enhanced UX with loading states and success feedback
- Related Products: Category-based product suggestions
- Breadcrumb Navigation: Clear navigation hierarchy
- 404 Handling: Graceful handling of invalid product IDs
- Persistent State: Cart maintained across page navigation
- Quantity Management: Increase/decrease/remove operations
- Price Calculations: Accurate totals with currency formatting
- Cart Modal: Slideout cart with glass-morphism design
- Empty State: Clear messaging when cart is empty
- Toast Notifications: Success feedback for cart operations
Based on commerce-main theme principles:
- Colors: Neutral palette with blue accents
- Typography: System fonts with proper hierarchy
- Spacing: Consistent 8px grid system
- Components: Reusable button, card, and form styles
- Responsive: Mobile-first breakpoints (640px, 768px, 1024px)
- Accessibility: High contrast ratios and focus states
- β‘ Turbopack: Fast development builds with Next.js 15
- πΌ Image Optimization: Next.js automatic image optimization
- π¦ Code Splitting: Automatic route-based splitting
- π API Health Check: Startup validation prevents runtime failures
- β‘ Fast Refresh: Hot module replacement for instant updates
- π Bundle Optimization: Tree shaking and compression
Features:
- Environment-configurable API URL
- Automatic health check on startup
- Error handling with user-friendly messages
- Loading states during data fetching
- ProductsContext: Global product state with category filtering
- CartContext: Shopping cart operations with persistence
- React useReducer: Predictable state updates
- TypeScript: Full type safety for state and actions
- API Failures: Graceful degradation with error messages
- Invalid Routes: 404 pages with navigation options
- Network Issues: Retry mechanisms and user feedback
- Validation: Form validation and user input sanitization
- π Advanced Search: Full-text search with autocomplete
- π· Enhanced Filtering: Price ranges, ratings, availability
- β Reviews System: User reviews and rating submissions
- β€οΈ Wishlist: Save products for later
- π€ User Accounts: Registration, login, profile management
- π± Progressive Web App: Offline support and app-like experience
- π Notifications: Push notifications for deals and updates
- π Internationalization: Multi-language and currency support
- π€ Recommendations: AI-powered product suggestions
- π Analytics: User behavior tracking and insights
- π Advanced Cart: Save for later, bulk operations
- π³ Checkout Flow: Payment integration and order management
- β‘ Virtual Scrolling: Handle thousands of products
- π Caching: Redis/CDN for improved performance
- π Real-time Updates: WebSocket inventory updates
- π Monitoring: Error tracking and performance metrics
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
- β Tests Required: All new features must include tests
- π TypeScript: Maintain type safety throughout
- π¨ Design System: Follow established patterns and components
- βΏ Accessibility: Ensure WCAG 2.1 AA compliance
- π± Responsive: Test across device breakpoints
Built with β€οΈ using Next.js 15, TypeScript, and Tailwind CSS