This project is an E-commerce back end that utilizes the latest technologies, providing an efficient and scalable solution for internet retail companies. Built with an Express.js API and connected to a MySQL database using Sequelize, this application facilitates product, category, and tag management through a RESTful API. This allows businesses to maintain their inventory in a database, offering endpoints for creating, reading, updating, and deleting (CRUD operations) data for categories, products, and tags.
- Demo Video
- Features
- Installation
- Usage
- Database Models
- Associations
- Structure
- Starter Code
- State Flow Diagram
- Contributing
- License
Open Demo video of Employee Tracker
-
View All Categories, Products, and Tags: Users can retrieve a comprehensive list of all categories, products, and tags stored in the database, each accessible through dedicated API GET routes. This feature ensures that the backend supports scalable read operations for e-commerce inventories.
-
Add New Categories, Products, and Tags: The backend allows for the insertion of new categories, products, and tags into the database via API POST routes. This functionality is crucial for expanding the e-commerce catalog and supporting a growing business.
-
Update Existing Categories, Products, and Tags: With API PUT routes, users can modify the details of existing categories, products, and tags. This feature facilitates dynamic inventory management, allowing changes to product details, categorizations, and tagging as needed.
-
Delete Categories, Products, and Tags: The API DELETE routes enable users to remove categories, products, and tags from the database. This capability is essential for keeping the database clean and up-to-date, ensuring that discontinued products or obsolete categories and tags are properly managed.
-
Structured Database Models with Associations: Utilizes Sequelize to define structured database models for Categories, Products, Tags, and ProductTags, with appropriate associations among them. This structure supports complex queries and relationships, such as finding all products within a category or all tags associated with a product.
-
Environment Variable Configuration: Incorporates the
dotenv
package to securely configure environment variables. This approach safeguards database credentials and other sensitive information, making the application more secure and easier to configure across different environments. -
Sequelize Sync on Server Start: Automatically syncs Sequelize models to the MySQL database upon server startup. This feature ensures that the database schema is up-to-date and ready for operations as soon as the server begins running.
- Ensure you have Node.js and MySQL installed on your machine.
- Clone the repository to your local machine:
git clone https://github.com/naturuplift/ECommerceBackEnd.git
- Navigate to the project directory and install dependencies:
cd ECommerceBackEnd
npm install
- Create a
.env
file in the root directory to store your MySQL username, password, and database name:
DB_NAME='ecommerce_db'
DB_USER='your_mysql_username'
DB_PASSWORD='your_mysql_password'
DB_HOST='your_host'
- Use the
schema.sql
file in thedb
folder to create your database using MySQL shell commands. - Seed the database:
npm run seed
- Start the server:
npm start
Once the server is running, you can use an API client like Insomnia to test the API routes.
- GET routes for categories, products, and tags display data in a formatted JSON.
- POST, PUT, and DELETE routes allow for creating, updating, and deleting data in the database.
Below are sample screenshots showcasing the application routes functionality.
GET All Categories:
GET Category (by Id):
GET All Products:
GET Product (by Id):
GET All Tags:
GET Tag (by Id):
POST CREATE Category:
PUT UPDATE Category (by Id):
DELETE DELETE Category (by Id):
POST CREATE Product:
PUT UPDATE Product (by Id):
DELETE DELETE Product (by Id):
POST CREATE Tag:
PUT UPDATE Tag (by Id):
DELETE DELETE Tag (by Id):
-
Category
id
(Integer, Primary Key, Auto Increment, Not Null)category_name
(String, Not Null)
-
Product
id
(Integer, Primary Key, Auto Increment, Not Null)product_name
(String, Not Null)price
(Decimal, Not Null, Validates Decimal)stock
(Integer, Not Null, Default Value 10, Validates Numeric)category_id
(Integer, References Category model's id)
-
Tag
id
(Integer, Primary Key, Auto Increment, Not Null)tag_name
(String)
-
ProductTag
id
(Integer, Primary Key, Auto Increment, Not Null)product_id
(Integer, References Product model's id)tag_id
(Integer, References Tag model's id)
- Product belongs to Category
- Category has many Product models
- Product belongs to many Tag models through ProductTag
- Tag belongs to many Product models
Your directory may have the following structure:
ECommerceBackEnd/
├── config/
│ └── connection.js
├── db/
│ ├── schema.sql
├── models/
│ ├── Category.js
│ ├── Product.js
│ ├── Tag.js
│ ├── ProductTag.js
│ └── index.js
├── routes/
│ ├── api/
│ │ ├── category-routes.js
│ │ ├── product-routes.js
│ │ ├── tag-routes.js
│ │ └── index.js
│ └── index.js
├── seeds/
│ ├── category-seeds.js
│ ├── product-seeds.js
│ ├── productTag-seeds.js
│ ├── tag-seeds.js
│ └── seed.js
├── .env
├── .gitignore
├── package.json
├── package-lock.json
├── server.js
└── README.md
To start with this project we used the following Starter Code
For a visual representation of the sequence of actions involved in the employee tracker, refer to the State Flow Diagram provided in the project documentation.
Feel free to reach out, contribute, or provide feedback to make the Password Generator Project even more robust and user-friendly!
Your contributions are welcome! Please feel free to submit issues and pull requests with improvements or suggestions.
This project is licensed under the MIT License. See the LICENSE file for details.