This repository contains a React application built with Vite, providing a fast and optimized development environment. The project focuses on creating a functional shopping cart for a modern web application.
This template provides a minimal setup to get a React application running quickly using Vite with Hot Module Replacement (HMR).
Before starting, ensure you have the following installed:
- Clone the repository:
git clone https://github.com/ramihdedeh/ShoppingCart.git
- Navigate to the frontend directory:
cd shoppingcart
npm install / npm buildnpm run dev http://localhost:5173To work with the backend, navigate to the backend directory:
cd backendBefore running the backend, you need to configure the database connection. Follow these steps:
- Open the configuration file:
backend/models/index.js- Add the following database configuration:
const sequelize = new Sequelize('shoppingcart', 'root', 'password', {
host: '127.0.0.1',
dialect: 'mysql',
});To build the backend, run the following command in the Express-backend directory:
npm buildTo start the Express backend server, follow these steps:
- Open a terminal and navigate to the
backenddirectory:cd backend
2.Run the following command to start the server:
node server.js3.Once the server is running, it will be accessible at:
http://localhost:5000If the database does not already exist, follow these steps to create it:
-
Open your MySQL terminal or a database client like MySQL Workbench.
-
Run the following SQL command to create the database:
CREATE DATABASE shoppingcart;
-
create the users table:
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL,
cart JSON DEFAULT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
role VARCHAR(50) DEFAULT 'user'
);
- create the product table:
CREATE TABLE products (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
description TEXT,
price DECIMAL(10, 2) NOT NULL,
image VARCHAR(255),
stock INT NOT NULL DEFAULT 0,
category VARCHAR(255),
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
- create cart table in mysql:
CREATE TABLE Cart (
id INT AUTO_INCREMENT PRIMARY KEY,
userId INT NOT NULL,
productId INT NOT NULL,
quantity INT NOT NULL,
createdAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updatedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (userId) REFERENCES Users(id) ON DELETE CASCADE,
FOREIGN KEY (productId) REFERENCES Products(id) ON DELETE CASCADE
);Fast Development: Built with Vite for an optimized development workflow. Live Reload and HMR: Changes to your code are reflected immediately in the browser. Modern Frontend: Built using React with support for JSX and functional components. CSS Modules: Style your components with scoped CSS for better maintainability.
This project leverages the following technologies:
React: Frontend library for building dynamic user interfaces.
Vite: Build tool for blazing-fast development and optimized builds.
Node.js: JavaScript runtime for managing dependencies and scripts.
Express: backend library for building backend.