Skip to content

learnershakil/blackbox-frontend

Repository files navigation

Electronics Store Frontend

A modern, production-grade e-commerce frontend built with React 19, TypeScript, and Tailwind CSS v4. This application provides a complete shopping experience with admin management capabilities.

πŸš€ Features

Customer Features

  • Product Catalog: Browse products with advanced filtering, search, and sorting
  • Product Details: Comprehensive product pages with image galleries and reviews
  • Shopping Cart: Persistent cart with quantity management and real-time updates
  • Wishlist: Save products for later with easy management
  • User Authentication: Secure login/signup with JWT token management
  • User Account: Profile management, order history, and address book
  • Checkout Flow: Multi-step checkout with payment integration
  • Responsive Design: Mobile-first design with excellent UX

Admin Features

  • Dashboard: Analytics overview with charts and key metrics
  • Product Management: Complete CRUD operations for products and categories
  • Order Management: Process orders, update status, track shipments
  • User Management: Manage customer accounts and permissions
  • Coupon System: Create and manage promotional codes
  • Banner Management: Control homepage banners and promotional content

Technical Features

  • TypeScript: Full type safety throughout the application
  • React 19: Latest React features with concurrent rendering
  • Tailwind CSS v4: Modern styling with custom design system
  • React Query: Efficient server state management with caching
  • Zustand: Lightweight client state management
  • Error Handling: Comprehensive error boundaries and user feedback
  • Performance: Lazy loading, code splitting, and optimization
  • Testing: Unit and integration tests with Vitest
  • Accessibility: WCAG compliant with proper ARIA attributes

πŸ› οΈ Tech Stack

  • Frontend: React 19, TypeScript, Vite
  • Styling: Tailwind CSS v4, Lucide React Icons
  • State Management: Zustand, React Query
  • Forms: React Hook Form, Zod validation
  • Routing: React Router v7
  • Testing: Vitest, Testing Library, jsdom
  • Build: Vite with TypeScript compilation
  • Linting: ESLint with TypeScript support

πŸ“¦ Installation

Prerequisites

  • Node.js 18+
  • pnpm (recommended) or npm

Setup

# Clone the repository
git clone <repository-url>
cd frontend

# Install dependencies
pnpm install

# Copy environment variables
cp .env.example .env.local

# Configure environment variables
# Edit .env.local with your API endpoints and keys

# Start development server
pnpm dev

Environment Variables

Create a .env.local file with:

VITE_API_BASE_URL=http://localhost:3000/api
VITE_APP_NAME=Electronics Store
VITE_APP_VERSION=1.0.0
VITE_STRIPE_PUBLISHABLE_KEY=pk_test_xxxxx
VITE_GOOGLE_ANALYTICS_ID=G-XXXXXXXXXX

πŸƒβ€β™‚οΈ Development

Available Scripts

# Development
pnpm dev              # Start development server
pnpm build           # Build for production
pnpm preview         # Preview production build

# Testing
pnpm test            # Run tests in watch mode
pnpm test:run        # Run tests once
pnpm test:ui         # Run tests with UI
pnpm test:coverage   # Run tests with coverage

# Code Quality
pnpm lint            # Run ESLint
pnpm typecheck       # Run TypeScript checks
pnpm format          # Format code with Prettier

# Utilities
pnpm clean           # Clean build artifacts

Project Structure

src/
β”œβ”€β”€ components/          # Reusable UI components
β”‚   β”œβ”€β”€ ui/             # Base UI components
β”‚   β”œβ”€β”€ forms/          # Form components
β”‚   β”œβ”€β”€ layout/         # Layout components
β”‚   β”œβ”€β”€ charts/         # Chart components
β”‚   β”œβ”€β”€ error/          # Error handling components
β”‚   └── performance/    # Performance components
β”œβ”€β”€ pages/              # Page components
β”œβ”€β”€ hooks/              # Custom React hooks
β”œβ”€β”€ stores/             # Zustand stores
β”œβ”€β”€ services/           # API services
β”œβ”€β”€ types/              # TypeScript type definitions
β”œβ”€β”€ utils/              # Utility functions
β”œβ”€β”€ constants/          # Application constants
└── test/               # Testing utilities

πŸ§ͺ Testing

The project includes comprehensive testing setup:

Test Types

  • Unit Tests: Individual components and functions
  • Integration Tests: Component interactions and user flows
  • Accessibility Tests: ARIA attributes and screen reader support

Running Tests

# Run all tests
pnpm test

# Run tests with UI dashboard
pnpm test:ui

# Run tests with coverage report
pnpm test:coverage

# Run specific test file
pnpm test ProductCard.test.tsx

Test Coverage

  • Components: Unit tests for all UI components
  • Pages: Integration tests for major user flows
  • Hooks: Custom hook testing with proper mocking
  • Utils: Utility function testing with edge cases

πŸš€ Deployment

Build for Production

# Build the application
pnpm build

# Preview the build
pnpm preview

Deployment Options

  1. Vercel (Recommended)

    # Install Vercel CLI
    npm i -g vercel
    
    # Deploy
    vercel --prod
  2. Netlify

    # Build and deploy
    pnpm build
    netlify deploy --prod --dir=dist
  3. Docker

    # Build Docker image
    docker build -t electronics-store .
    
    # Run container
    docker run -p 80:80 electronics-store

See DEPLOYMENT.md for detailed deployment instructions.

πŸ“Š Performance

Optimization Features

  • Code Splitting: Route-based and component-based splitting
  • Lazy Loading: Images and components loaded on demand
  • Bundle Analysis: Built-in bundle size monitoring
  • Caching: Aggressive caching for static assets
  • Tree Shaking: Unused code elimination

Performance Metrics

  • Lighthouse Score: 95+ across all categories
  • First Contentful Paint: < 1.5s
  • Largest Contentful Paint: < 2.5s
  • Cumulative Layout Shift: < 0.1

πŸ”’ Security

Security Features

  • Content Security Policy: Prevents XSS attacks
  • Input Validation: Zod schemas for all forms
  • Authentication: Secure JWT token handling
  • HTTPS: Enforced in production
  • Environment Variables: Secure configuration management

β™Ώ Accessibility

  • WCAG 2.1 AA: Compliant accessibility standards
  • Keyboard Navigation: Full keyboard support
  • Screen Reader: Proper ARIA labels and descriptions
  • Color Contrast: Meets accessibility contrast ratios
  • Focus Management: Logical focus order and visible focus indicators

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/new-feature
  3. Make your changes and add tests
  4. Run tests: pnpm test:run
  5. Run linting: pnpm lint
  6. Commit your changes: git commit -m 'Add new feature'
  7. Push to the branch: git push origin feature/new-feature
  8. Submit a pull request

Development Guidelines

  • Follow TypeScript best practices
  • Write tests for new features
  • Maintain accessibility standards
  • Use conventional commit messages
  • Keep components small and focused

πŸ“ API Integration

The frontend integrates with a REST API providing:

  • Product management endpoints
  • User authentication and management
  • Order processing and tracking
  • Payment integration
  • Analytics and reporting

See api-req-response.md for complete API documentation.

πŸ› Troubleshooting

Common Issues

  1. Build Failures

    # Clear cache and reinstall
    pnpm clean
    rm -rf node_modules
    pnpm install
  2. Type Errors

    # Run type checking
    pnpm typecheck
  3. Test Failures

    # Update snapshots if needed
    pnpm test -- --update-snapshots
  4. Performance Issues

    # Analyze bundle size
    pnpm build:analyze

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support

For support and questions:

🎯 Roadmap

  • PWA support with offline functionality
  • Advanced analytics dashboard
  • Multi-language support (i18n)
  • Dark mode theme
  • Advanced search with AI recommendations
  • Real-time notifications
  • Voice search integration
  • Mobile app with React Native

Built with ❀️ using modern web technologies for optimal performance and user experience.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages