A modern, full-stack e-commerce web application built with Node.js, Express, and React. This application demonstrates core e-commerce functionality including product catalog, shopping cart, and checkout process, all using free and open-source tools.
- Product Catalog: Browse products with images, descriptions, prices, and stock information
- Shopping Cart: Add, remove, and update product quantities in your cart
- Persistent Cart: Cart data is saved in localStorage and persists across sessions
- Checkout Process: Simple checkout form with order submission
- Order Management: Orders are stored in a JSON file with unique IDs
- Stock Management: Product stock is automatically updated when orders are placed
- Responsive Design: Clean, modern UI that works on all devices
- Node.js: JavaScript runtime
- Express: Web application framework
- CORS: Cross-origin resource sharing middleware
- UUID: Generate unique order IDs
- React: UI library
- React Router: Client-side routing
- Vite: Fast build tool and development server
- Context API: State management for shopping cart
- JSON Files: Simple file-based data storage (no database required)
AiEcommerce/
├── backend/
│ ├── data/
│ │ ├── products.json # Product catalog data
│ │ └── orders.json # Order history
│ ├── routes/
│ │ ├── products.js # Product API routes
│ │ └── orders.js # Order API routes
│ ├── server.js # Express server setup
│ └── package.json # Backend dependencies
├── frontend/
│ ├── public/ # Static assets
│ ├── src/
│ │ ├── components/ # Reusable React components
│ │ │ ├── Header.jsx
│ │ │ └── ProductCard.jsx
│ │ ├── pages/ # Page components
│ │ │ ├── Products.jsx
│ │ │ ├── Cart.jsx
│ │ │ └── Checkout.jsx
│ │ ├── context/ # React Context for state management
│ │ │ └── CartContext.jsx
│ │ ├── App.jsx # Main application component
│ │ ├── main.jsx # Application entry point
│ │ └── index.css # Global styles
│ ├── index.html # HTML template
│ ├── vite.config.js # Vite configuration
│ └── package.json # Frontend dependencies
└── README.md # This file
Before you begin, ensure you have the following installed:
- Node.js (version 14 or higher)
- npm (comes with Node.js)
To check if you have Node.js and npm installed:
node --version
npm --versionIf not installed, download from nodejs.org
git clone <repository-url>
cd AiEcommercecd backend
npm installcd ../frontend
npm installYou need to run both the backend and frontend servers. Open two terminal windows:
cd backend
npm startThe backend server will start on http://localhost:5000
For development with auto-restart on file changes:
npm run devcd frontend
npm run devThe frontend will start on http://localhost:3000
Open your browser and navigate to:
http://localhost:3000
GET /api/products- Get all productsGET /api/products/:id- Get a single product by IDGET /api/products/category/:category- Get products by category
POST /api/orders- Create a new orderGET /api/orders- Get all ordersGET /api/orders/:id- Get a single order by ID
POST /api/orders
Content-Type: application/json
{
"items": [
{
"productId": "1",
"quantity": 2
}
],
"customer": {
"name": "John Doe",
"email": "john@example.com",
"phone": "555-0123",
"address": "123 Main St, New York, NY 10001"
}
}-
Browse Products: The home page displays all available products with images, descriptions, prices, and stock levels.
-
Add to Cart: Click the "Add to Cart" button on any product to add it to your shopping cart. The cart count in the header updates automatically.
-
View Cart: Click the "Cart" button in the header to view your shopping cart. Here you can:
- Adjust quantities using + and - buttons
- Remove items
- See the order total
- Proceed to checkout
-
Checkout: Fill in the shipping information form and click "Place Order". The order will be submitted to the backend, and you'll receive a confirmation with your order ID.
-
Persistent Cart: Your cart is saved in the browser's localStorage, so it will persist even if you close the browser or refresh the page.
Products are stored in backend/data/products.json. You can edit this file to:
- Add new products
- Update product information
- Change prices or stock levels
Orders are stored in backend/data/orders.json. Each order includes:
- Unique order ID
- Customer information
- Order items with quantities and prices
- Order total
- Timestamp
- Order status
Edit backend/data/products.json:
{
"id": "9",
"name": "New Product",
"description": "Product description",
"price": 99.99,
"category": "Electronics",
"image": "https://example.com/image.jpg",
"stock": 50
}All styles are in frontend/src/index.css. You can customize:
- Colors
- Fonts
- Layout
- Spacing
If you deploy the backend to a different URL, update the Vite proxy configuration in frontend/vite.config.js:
proxy: {
'/api': {
target: 'http://your-backend-url',
changeOrigin: true
}
}cd frontend
npm run buildThis creates an optimized production build in the frontend/dist directory.
npm run previewIf port 5000 or 3000 is already in use:
Backend: Set a different port
PORT=5001 npm startFrontend: Edit frontend/vite.config.js and change the port number
If you encounter CORS errors, ensure the backend CORS middleware is properly configured in backend/server.js.
Clear your browser's localStorage and refresh:
- Open Developer Tools (F12)
- Go to Application/Storage tab
- Clear localStorage
- Refresh the page
Potential features to add:
- User authentication and login
- Product search and filtering
- Product categories navigation
- Product reviews and ratings
- Order history for users
- Admin panel for managing products
- Payment gateway integration
- Email notifications
- Database integration (MongoDB, PostgreSQL)
This application uses only free and open-source tools:
- ✅ Node.js - Free
- ✅ Express - Free
- ✅ React - Free
- ✅ Vite - Free
- ✅ All npm packages - Free
Total Cost: $0
To deploy for free, consider:
- Backend: Railway, Render, Fly.io (free tiers)
- Frontend: Netlify, Vercel, GitHub Pages (free tiers)
MIT License - Feel free to use this project for learning or commercial purposes.
For issues or questions, please check:
- This README for common solutions
- The code comments for implementation details
- The console for error messages
Contributions are welcome! Feel free to submit issues or pull requests.
Happy Shopping! 🛒