# SmartShop Ltd - Sales Management System

A web-based sales management system for SmartShop Ltd, an electronics retailer selling phones, laptops, televisions, and accessories.

## Tech Stack

- **Frontend:** React.js (Vite)
- **Backend:** Node.js + Express
- **Database:** MySQL

## Features

### Product Management
- Create, read, update, delete products
- Fields: product ID, name, category, quantity, price, created date

### Customer Management
- Register, update, delete, and search customers
- Fields: customer ID, full name, phone, email, address, registration date

### Sales Management
- Record sales with customer and product selection
- Automatic total calculation
- Stock deduction on sale

### Reports & Analytics
- **Daily Sales Report** - Filter by specific date
- **Monthly Sales Report** - Filter by date range
- **Product Stock Report** - Available and sold stock
- **Customer Purchase Report** - All purchases by customer

### Dashboard
- Total products, customers, sales, and revenue
- Recent sales and low stock alerts

## Prerequisites

- Node.js (v18+)
- MySQL Server

## Setup Instructions

### 1. Database Setup

Open MySQL and run the schema file:

```bash
mysql -u root -p < backend/database/schema.sql
```

Or import `backend/database/schema.sql` using MySQL Workbench.

### 2. Backend Setup

```bash
cd backend
npm install
```

Copy `.env.example` to `.env` and update your MySQL credentials:

```
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=your_password
DB_NAME=smartshop_db
```

Seed the database with default admin user and sample data:

```bash
node scripts/seed.js
```

Start the backend server:

```bash
npm run dev
```

The API runs at `http://localhost:5000`

### 3. Frontend Setup

```bash
cd frontend
npm install
npm run dev
```

The app runs at `http://localhost:3000`

## Default Login

- **Username:** admin
- **Password:** admin123

## API Endpoints

| Method | Endpoint | Description |
|--------|----------|-------------|
| POST | /api/auth/login | User login |
| GET | /api/dashboard/summary | Dashboard stats |
| GET/POST/PUT/DELETE | /api/products | Product CRUD |
| GET/POST/PUT/DELETE | /api/customers | Customer CRUD |
| GET/POST | /api/sales | Sales list & record |
| GET | /api/reports/daily?date=YYYY-MM-DD | Daily report |
| GET | /api/reports/monthly?startDate=&endDate= | Monthly report |
| GET | /api/reports/stock | Stock report |
| GET | /api/reports/customer-purchases?customerId= | Customer purchases |

## Project Structure

```
Ecommerce/
├── backend/
│   ├── config/db.js
│   ├── database/schema.sql
│   ├── middleware/auth.js
│   ├── routes/
│   ├── scripts/seed.js
│   └── server.js
├── frontend/
│   └── src/
│       ├── components/
│       ├── context/
│       ├── pages/
│       └── services/
└── README.md
```
