# Stock Management System (SMS)
## StockHub Ltd — National Practical Exam 2026

Web-based stock management application for StockHub Ltd, Kigali City, Rwanda.

---

## Project Structure

```
FirstName_LastName_National_Practical_Exam_2026/
├── ERD.md                 # Entity Relationship Diagram documentation
├── database.sql           # MySQL database schema (SMS)
├── backend-project/       # Node.js + Express API
└── frontend-project/      # React.js + Tailwind CSS UI
```

> **Important:** Rename the folder `FirstName_LastName_National_Practical_Exam_2026` to your real name format, e.g. `Jean_Pierre_National_Practical_Exam_2026`.

---

## Requirements

- **Node.js** v18+ ([https://nodejs.org](https://nodejs.org))
- **MySQL** 8.0+ (XAMPP, WAMP, or standalone MySQL)
- **npm** (comes with Node.js)

---

## Step 1: ERD (Hand-drawn + Digital)

1. Draw the ERD on plain paper using pencil (see `ERD.md` for entities, keys, and cardinalities).
2. Recreate it digitally using **draw.io**, **Lucidchart**, or **Edraw Max**.
3. Include PK, FK, relationship lines, and cardinalities (1:M).

### Key Relationships
| Entity A | Entity B | Cardinality |
|----------|----------|-------------|
| Product | StockTransaction | 1 : M |
| Warehouse | StockTransaction | 1 : M |

---

## Step 2: Create MySQL Database

This project uses **MySQL only** (not MongoDB). The backend connects via the `mysql2` package.

### Option A — Using Node.js (recommended)

1. Start MySQL server (XAMPP, WAMP, or MySQL Workbench).
2. Set your MySQL credentials in `backend-project/.env`:

```
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=your_mysql_password
DB_NAME=SMS
```

3. Create the database and tables:

```bash
cd backend-project
npm run setup-db
```

### Option B — Using MySQL Workbench / phpMyAdmin

1. Open MySQL Workbench or phpMyAdmin.
2. Import or run the file `database.sql` from the project root.
3. Update `backend-project/.env` with your MySQL password.

---

## Step 3: Start Backend

```bash
cd backend-project
npm install
npm start
```

Backend runs at **http://localhost:5000**

Default login: **admin** / **admin123** (created automatically on first start)

---

## Step 4: Start Frontend

Open a new terminal:

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

Frontend runs at **http://localhost:3000**

---

## Application Features

| Page | Operations |
|------|-----------|
| **Product** | Insert + View list |
| **Warehouse** | Insert + View list |
| **Transactions** | Create, Read, Update, Delete (full CRUD) |
| **Reports** | Daily, Weekly, Monthly (available stock, stock IN, stock OUT) |
| **Logout** | Clears session |

- Responsive design (mobile & desktop)
- User authentication (register / login)
- Axios integration with JWT token
- Tailwind CSS styling

---

## API Endpoints

| Method | Endpoint | Description |
|--------|----------|-------------|
| POST | `/api/auth/register` | Register user |
| POST | `/api/auth/login` | Login |
| GET | `/api/products` | List products |
| POST | `/api/products` | Add product |
| GET | `/api/warehouses` | List warehouses |
| POST | `/api/warehouses` | Add warehouse |
| GET | `/api/transactions` | List transactions |
| POST | `/api/transactions` | Add transaction |
| PUT | `/api/transactions/:id` | Update transaction |
| DELETE | `/api/transactions/:id` | Delete transaction |
| GET | `/api/reports/:period` | Report (daily/weekly/monthly) |

---

## Technologies Used

- **Frontend:** React.js, Vite, Tailwind CSS, Axios, React Router
- **Backend:** Node.js, Express.js, MySQL2, bcryptjs, JWT
- **Database:** MySQL (SMS)

---

## Author

Replace with your full name before submission.
