# StockHub Ltd — Stock Management System (SMS)

National Practical Exam 2026 — Full stack web application for StockHub Ltd, Kigali City, Rwanda.

## Project structure

```
Davina_Student_National_Practical_Exam_2026/
├── database/
│   └── schema.sql          # MySQL database SMS
├── backend-project/        # Node.js + Express API
└── frontend-project/       # React + Tailwind UI
```

**Rename the folder** `Davina_Student_National_Practical_Exam_2026` to `YourFirstName_YourLastName_National_Practical_Exam_2026` before submission.

## Database design (ERD summary)

| Entity | Primary Key | Relationships |
|--------|-------------|---------------|
| **Product** | productCode | 1 → many StockTransaction |
| **Warehouse** | warehouseCode | 1 → many StockTransaction |
| **StockTransaction** | transactionId | FK → Product, FK → Warehouse |
| **users** | id | Authentication |

Cardinalities: One Product has many Transactions; one Warehouse has many Transactions.

## Requirements checklist

| Requirement | Implementation |
|-------------|----------------|
| Insert on Product, Warehouse, Transactions | POST endpoints + forms |
| CRUD only on Transactions | GET/PUT/DELETE on `/api/transactions` |
| User account (username/password) | `users` table + login/register |
| Axios integration | `src/api/axios.js` |
| Reports (daily/weekly/monthly) | `/api/reports/stock-movement/:period` |
| Menu: Product, Warehouse, Transactions, Reports, Logout | `Layout.jsx` |
| Tailwind CSS | Configured in frontend |
| Responsive UI | Mobile nav + responsive grids |

## Setup

### 1. MySQL

1. Start MySQL (XAMPP, WAMP, or standalone).
2. Run the schema:

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

### 2. Backend

```bash
cd backend-project
copy .env.example .env
npm install
npm start
```

Edit `.env` with your MySQL password. API runs at **http://localhost:5000**

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

### 3. Frontend

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

Open **http://localhost:3000**

## API endpoints

| Method | Endpoint | Description |
|--------|----------|-------------|
| POST | `/api/auth/login` | Login |
| POST | `/api/auth/register` | Register user |
| GET/POST | `/api/products` | List / insert products |
| GET/POST | `/api/warehouses` | List / insert warehouses |
| GET/POST/PUT/DELETE | `/api/transactions` | Full CRUD transactions |
| GET | `/api/reports/available-stock` | Current stock report |
| GET | `/api/reports/stock-movement/:period` | daily \| weekly \| monthly |

All routes except auth require header: `Authorization: Bearer <token>`

## Tech stack

- **Frontend:** React 18, Vite, React Router, Tailwind CSS, Axios
- **Backend:** Node.js, Express.js, mysql2, bcryptjs, JWT
- **Database:** MySQL (database name: `SMS`)
