{"id":27147869,"url":"https://github.com/manineedtosleep/sql-commerce","last_synced_at":"2025-10-29T07:04:46.248Z","repository":{"id":262676689,"uuid":"888010920","full_name":"ManINeedToSleep/SQL-Commerce","owner":"ManINeedToSleep","description":null,"archived":false,"fork":false,"pushed_at":"2024-11-21T17:12:49.000Z","size":3796,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-21T18:23:34.198Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ManINeedToSleep.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-13T16:55:48.000Z","updated_at":"2024-11-21T17:13:04.000Z","dependencies_parsed_at":"2024-11-13T17:54:18.241Z","dependency_job_id":null,"html_url":"https://github.com/ManINeedToSleep/SQL-Commerce","commit_stats":null,"previous_names":["manineedtosleep/sql-commerce"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ManINeedToSleep%2FSQL-Commerce","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ManINeedToSleep%2FSQL-Commerce/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ManINeedToSleep%2FSQL-Commerce/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ManINeedToSleep%2FSQL-Commerce/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ManINeedToSleep","download_url":"https://codeload.github.com/ManINeedToSleep/SQL-Commerce/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247838415,"owners_count":21004576,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-08T11:51:27.150Z","updated_at":"2025-10-29T07:04:41.203Z","avatar_url":"https://github.com/ManINeedToSleep.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# **E-Commerce Database Schema**\n\nThis project defines a basic database schema for an e-commerce store using MySQL. The schema is designed to track customers, products, orders, and order details. It includes tables for storing customer information, product inventory, and order data, as well as the relationships between them.\n\n---\n\n## **Schema Overview**\n\nThe schema contains the following tables:\n1. **Customers**: Stores customer information.\n2. **Products**: Stores product details and inventory.\n3. **Orders**: Tracks customer orders.\n4. **Order Details**: Stores the specifics of products within each order.\n\n---\n\n## **Tables**\n\n### **1. Customers Table**\nStores customer details such as name, contact information, and registration date.\n\n| Column              | Description                                      |\n|---------------------|--------------------------------------------------|\n| `customer_id`       | Unique identifier for each customer (auto-increment). |\n| `first_name`        | Customer's first name.                           |\n| `last_name`         | Customer's last name.                            |\n| `email`             | Customer's email address (unique).               |\n| `phone_number`      | Customer's phone number.                         |\n| `address`           | Customer's address.                              |\n| `city`              | City of residence.                               |\n| `state`             | State of residence.                              |\n| `zip_code`          | Customer's zip code.                             |\n| `registration_date` | Date and time the customer registered (defaults to current timestamp). |\n\n---\n\n### **2. Products Table**\nStores product details including pricing and stock quantity.\n\n| Column              | Description                                      |\n|---------------------|--------------------------------------------------|\n| `product_id`        | Unique identifier for each product (auto-increment). |\n| `name`              | Name of the product.                             |\n| `description`       | Detailed product description.                    |\n| `price`             | Price of the product (up to two decimal places). |\n| `stock_quantity`    | Quantity of the product in stock.                |\n| `date_added`        | Date the product was added to the inventory.     |\n\n---\n\n### **3. Orders Table**\nTracks orders placed by customers, including their status and total amount.\n\n| Column              | Description                                      |\n|---------------------|--------------------------------------------------|\n| `order_id`          | Unique identifier for each order (auto-increment). |\n| `customer_id`       | Links to the `customer_id` in the `customers` table (foreign key). |\n| `order_date`        | Date and time the order was placed.              |\n| `order_status`      | Current status of the order (`Pending`, `Shipped`, `Delivered`, `Cancelled`). |\n| `total_amount`      | Total price of the order.                        |\n\n---\n\n### **4. Order Details Table**\nStores the specifics of each product included in an order.\n\n| Column              | Description                                      |\n|---------------------|--------------------------------------------------|\n| `order_detail_id`   | Unique identifier for each order item (auto-increment). |\n| `order_id`          | Links to the `order_id` in the `orders` table (foreign key). |\n| `product_id`        | Links to the `product_id` in the `products` table (foreign key). |\n| `quantity`          | Quantity of the product ordered.                 |\n| `price`             | Price of the product at the time of the order.   |\n\n---\n\n## **Relationships**\n\n1. The **Orders** table is linked to the **Customers** table via the `customer_id` foreign key.  \n   - **Purpose:** Tracks which customer placed each order.\n\n2. The **Order Details** table links:\n   - **Orders** via the `order_id` foreign key.\n   - **Products** via the `product_id` foreign key.  \n   - **Purpose:** Tracks which products were included in each order and their respective quantities.\n\n---\n\n## **Sample Queries**\n\n### 1. **Get All Orders for a Specific Customer**\nFetch all orders placed by a customer with `customer_id = 1`:\n```sql\nSELECT order_id, order_date, total_amount, order_status\nFROM orders\nWHERE customer_id = 1;\n```\n\n---\n\n### 2. **Get All Details for a Specific Order**\nFetch product details for a specific order with `order_id = 1`:\n```sql\nSELECT \n    p.name AS product_name, \n    od.quantity, \n    od.price AS unit_price, \n    (od.quantity * od.price) AS total_price\nFROM \n    order_details od\nJOIN \n    products p ON od.product_id = p.product_id\nWHERE \n    od.order_id = 1;\n```\n\n---\n\n### 3. **Update Stock After an Order**\nReduce the stock of a product after an order is placed:\n```sql\nUPDATE products\nSET stock_quantity = stock_quantity - 1\nWHERE product_id = 1;\n```\n\n---\n\n## **Future Enhancements**\nThis schema can be extended to support additional features:\n- Add a **Categories** table for product categorization.\n- Include a **Reviews** table for customer feedback on products.\n- Implement discount or coupon functionality using a **Coupons** table.\n- Add shipment tracking with a **Shipments** table.\n\n---\n\n# **Installation Guide for E-Commerce Application**\n\nThis guide will walk you through the steps to set up your e-commerce database and application, from installing the required tools to cloning the GitHub repository and running the app.\n\n---\n\n## **1. Install Required Tools**\n\n### **a. Install SQL Server**\n1. **Download and Install SQL Server**:\n   - Go to the [SQL Server Downloads page]([https://www.microsoft.com/en-us/sql-server/sql-server-downloads](https://dev.mysql.com/downloads/installer/)).\n   - Choose **SQL Server Community Edition** (free for development).\n   - Run the installer and select **Full Installation**.\n\n---\n\n### **b. Install Node.js and npm**\n1. **Download and Install Node.js**:\n   - Go to the [Node.js Downloads page](https://nodejs.org/).\n   - Install the **LTS version** (which includes npm).\n\n2. **Verify Installation**:\n   - Open a terminal or command prompt and run:\n     ```bash\n     node -v\n     npm -v\n     ```\n     These commands should show the installed versions.\n\n---\n\n### **c. Install Git**\n1. **Download and Install Git** from [Git's official page](https://git-scm.com/downloads).\n2. Set up Git on your machine:\n   ```bash\n   git config --global user.name \"Your Name\"\n   git config --global user.email \"youremail@example.com\"\n   ```\n\n---\n\n## **2. Clone the GitHub Repository**\n1. **Clone the Repository**:\n   - Open your terminal or command prompt.\n   - Run the following command to clone the project repository to your local machine:\n     ```bash\n     git clone \u003crepository_url\u003e\n     cd \u003crepository_name\u003e\n     ```\n\n---\n\n## **3. Set Up the Application**\n1. **Install Dependencies**:\n   - In the project directory, run:\n     ```bash\n     npm install\n     ```\n\n2. **Configure the `.env` File**:\n   - Create a `.env` file in the root of the project with the following variables:\n     ```plaintext\n        DB_HOST=localhost\n        DB_PORT=3306\n        DB_NAME=database_name\n        DB_USER=root\n        DB_PASSWORD=database_password\n        PORT=3000\n     ```\n\n---\n\n## **4. Run the Application**\n1. **Start the Application**:\n   - Run the application in development mode:\n     ```bash\n     npm run dev\n     ```\n\n2. **Test the App**:\n   - Open your browser and go to `http://localhost:3000` to see the app in action.\n\n---\n\n## **5. Verify Everything Works**\n1. **Verify SQL Server Database**:\n   - In SSMS, run a query like:\n     ```sql\n     SELECT * FROM customers;\n     ```\n     to ensure your data is properly inserted.\n   \n2. **Verify Application**:\n   - Ensure the app is running correctly and connecting to your SQL Server database by checking the app's logs.\n\n---\n\nWith this setup, you now have the e-commerce application running with a local SQL Server database and the ability to manage everything via SSMS and the Node.js application.\n\n---\n\n### Reflection\n\n1. How do primary and foreign keys help maintain data integrity?\n   A : Primary keys are like the unique ID cards for each record, so there are no duplicates. Foreign keys connect tables and make sure the data matches up properly, like linking an order to a specific customer. It keeps everything tidy and consistent.\n\n2. What insights can be gained by joining multiple tables?\n   A : Joins let you mix and match data from different tables to see the bigger picture.\n\n3. How can aggregate functions summarize data?\n   A : Aggregate functions are the shortcuts for getting the big numbers, like total sales (SUM), average order size (AVG), or the number of customers (COUNT).\n\n4. What types of analyses are enabled by date functions?\n   A : With date functions, you can look at trends over time. Stuff like “When are we busiest?” and “What’s the monthly revenue?”.\n\n5. How might you extend this database for additional e-commerce features?\n   A : Maybe add a categories table to organize products better or a reviews table so customers can leave feedback.\n\n   ![NodeIMG](NodeIMG.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanineedtosleep%2Fsql-commerce","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmanineedtosleep%2Fsql-commerce","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanineedtosleep%2Fsql-commerce/lists"}