A full-stack e-commerce application built with Node.js, Express, TypeScript (backend) and React, TypeScript (frontend).
- Authentication: JWT-based user authentication with signup/login
- Products: CRUD operations, search, filtering, pagination, featured products
- Shopping Cart: Add/remove items, update quantities, cart management
- Orders: Order creation, history, status tracking, cancellation
- Database: In-memory storage with repository pattern (easily extensible to real databases)
- Testing: Comprehensive unit tests with Jest
- Type Safety: Full TypeScript implementation
- Modern React: Hooks, Context API, functional components
- Routing: React Router with protected routes
- Styling: Styled Components with responsive design
- State Management: Custom hooks for auth and cart management
- Testing: React Testing Library with component tests
- Type Safety: Full TypeScript implementation
sample-e-com/
├── server/ # Backend API
│ ├── src/
│ │ ├── controllers/ # Request handlers
│ │ ├── services/ # Business logic
│ │ ├── repositories/ # Data access layer
│ │ ├── models/ # Data models and types
│ │ ├── middleware/ # Auth and other middleware
│ │ ├── routes/ # API route definitions
│ │ └── __tests__/ # Backend tests
│ └── package.json
├── client/ # Frontend React app
│ ├── src/
│ │ ├── components/ # Reusable UI components
│ │ ├── pages/ # Page components
│ │ ├── hooks/ # Custom React hooks
│ │ ├── services/ # API client
│ │ ├── types/ # TypeScript type definitions
│ │ ├── styles/ # Global styles
│ │ └── __tests__/ # Frontend tests
│ └── package.json
└── README.md
- Node.js (v18 or higher)
- npm or yarn
- Clone the repository
git clone <repository-url>
cd sample-e-com
- Install dependencies
# Install root dependencies
npm install
# Install server dependencies
cd server
npm install
# Install client dependencies
cd ../client
npm install
cd ..
- Set up environment variables
Create a .env
file in the server
directory:
PORT=5000
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
NODE_ENV=development
CLIENT_URL=http://localhost:3000
Create a .env
file in the client
directory:
REACT_APP_API_URL=http://localhost:5000/api
npm run dev
npm run server
npm run client
npm run build
npm start
npm test
npm run test:server
npm run test:client
npm run test:coverage
POST /api/auth/signup
- User registrationPOST /api/auth/login
- User loginGET /api/auth/profile
- Get user profile (protected)
GET /api/products
- Get products with pagination, search, filteringGET /api/products/:id
- Get product by IDGET /api/products/featured
- Get featured productsGET /api/products/categories
- Get product categories
GET /api/cart
- Get user's cartPOST /api/cart
- Add item to cartPUT /api/cart/:itemId
- Update cart item quantityDELETE /api/cart/:itemId
- Remove item from cartDELETE /api/cart
- Clear entire cart
POST /api/orders
- Create new orderGET /api/orders
- Get user's ordersGET /api/orders/:id
- Get order by IDPUT /api/orders/:id/cancel
- Cancel order
- Browse Products: View featured products on homepage, browse all products with search/filter
- Authentication: Sign up or log in to access cart and orders
- Shopping: Add products to cart, adjust quantities
- Checkout: Enter shipping address, select payment method
- Order Management: View order history, track status, cancel pending orders
- Responsive Design: Mobile-first approach with breakpoints
- Error Handling: Comprehensive error handling on both client and server
- Loading States: Loading indicators throughout the application
- Form Validation: Client-side and server-side validation
- Protected Routes: Authentication required for cart, checkout, orders
- Pagination: Efficient loading of large product lists
- Search & Filter: Real-time product search and category filtering
- Runtime: Node.js
- Framework: Express.js
- Language: TypeScript
- Authentication: JWT (jsonwebtoken)
- Testing: Jest, Supertest
- Validation: Manual validation (easily extensible to libraries like Joi)
- CORS: Enabled for cross-origin requests
- Library: React 18
- Language: TypeScript
- Routing: React Router v6
- Styling: Styled Components
- HTTP Client: Axios
- Testing: React Testing Library, Jest
- Build Tool: Create React App
- TypeScript: Strict mode enabled
- ESLint: Configured for both server and client
- Prettier: Code formatting (can be added)
- Naming: Consistent camelCase for variables, PascalCase for components
- Unit Tests: Individual functions and components
- Integration Tests: API endpoints and user flows
- Coverage: Aim for >80% test coverage
- Mocking: API calls mocked in frontend tests
- Environment Variables: Separate configs for dev/prod
- Build Process: Optimized production builds
- CORS: Configured for production domains
- Error Handling: Production-safe error messages
- Logging: Console logging (extensible to proper logging services)
- Install database driver (e.g.,
pg
for PostgreSQL,mysql2
for MySQL) - Update repository classes to use database queries instead of in-memory storage
- Add database connection configuration
- Implement migrations for schema management
- Payment Integration: Stripe, PayPal, etc.
- Email Notifications: Order confirmations, shipping updates
- Admin Panel: Product management, order management
- Reviews & Ratings: Product reviews and ratings
- Inventory Management: Stock tracking, low stock alerts
- Wishlist: Save products for later
- Discounts & Coupons: Promotional codes and discounts
- Caching: Redis for session and data caching
- CDN: For static assets and images
- Database Indexing: Optimize query performance
- Code Splitting: Lazy load React components
- Image Optimization: Compress and resize product images
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For questions or issues, please open an issue on the GitHub repository.