This is the frontend for an e-commerce application developed using NodeJS and React.
- Fully responsive design for mobile and desktop.
- Dynamic product rendering with pagination.
- Seamless cart synchronization with the backend.
- Download the latest version of Node.js from the official website.
- Install Node.js using the installer for your operating system.
- Verify the installation by running:
node -v npm -v
- Navigate to the frontend project directory.
- Install the required dependencies:
npm install
- If you haven't done so, be sure to download the backend files and follow installation steps for this project.
- Navigate to the backend directory.
- Run the Flask server:
python app.py
- The backend will be available at
http://127.0.0.1:8080.
- Navigate to the frontend directory.
- Start the development server:
npm start
- The frontend will be available at
http://127.0.0.1:3000.
The frontend of this project is built using Next.js, a React-based framework, to provide server-side rendering and optimized performance. Below is a breakdown of the key components and their responsibilities:
The Header.js component serves as the navigation bar for the application. It includes the following functionalities:
- A search bar that allows users to search for products.
- Upon submitting a search query, it redirects to the
/productspage and opens a modal displaying the searched product with an "Add to Cart" button.
- Upon submitting a search query, it redirects to the
- A login button that triggers the login modal (
Logincomponent) and fetches the user's cart from the database upon successful login. - Navigation links to access key sections of the website.
- This component is rendered on the
/productsroute and displays a grid of products. - It fetches data from our database to populate product information dynamically.
- Implements pagination to limit the display to nine products per page for better performance and usability.
- Used as the homepage, this component highlights featured or popular products.
- Like
ProductList, it fetches product data from the Fake Store API. - It focuses on providing a visually engaging layout for user engagement.
- Displays the user's shopping cart with the following functionalities:
- Adjusting product quantities.
- Removing items from the cart.
- Initiating the checkout process.
- It uses context from
CartContext.jsfor cart state management.
- Handles user authentication through a modal.
- Includes fields for entering user credentials and a submit button to log in.
- Upon successful login, it fetches the user's cart data and updates the application state.
The CartContext provides global state for managing the shopping cart. It includes:
- Functions to add, update, and remove items from the cart.
- Functions to save the cart to the database and fetch it upon login.
- A checkout function to initiate the purchase process.
- Backend Routes:
/checkout: Completes the purchase.- Other cart and user-related operations that synchronize the frontend with the database.
The app uses the following key routes:
/: Displays theProductGridas the homepage./products: Renders theProductListto browse all available products./admin: Accesses the admin panel for product management (for authorized users).
- Next.js: For efficient routing, SSR (Server-Side Rendering), and improved page performance.
- React Context API: For state management.
- CSS Modules/Tailwind: For styling components.
- Fetch API: For API requests.