# Inventory Management System

A full-stack inventory management application built with **React**, **Tailwind CSS**, **Node.js**, **Express**, and **MySQL**.

## Features

- **Authentication** — Register & login with JWT tokens
- **Strong Password Policy** — Uppercase, lowercase, number, special character (8+ chars)
- **Product Management** — CRUD with SKU, pricing, supplier, location
- **Categories** — Organize products by category
- **Stock Movements** — Stock in, stock out, and quantity adjustments with audit trail
- **Dashboard** — Overview stats, low stock alerts, recent movements
- **Reports** — Inventory, low stock, and movement reports
- **Export** — Download reports as CSV or PDF
- **Role-Based Access** — Admin, Manager, Staff roles

## Project Structure

```
Lms/
├── backend/
│   ├── src/
│   │   ├── config/       # Database config & initialization
│   │   ├── controllers/  # Route handlers
│   │   ├── middleware/   # JWT auth & authorization
│   │   ├── routes/       # API routes
│   │   └── utils/        # Password validation
│   └── package.json
├── frontend/
│   ├── src/
│   │   ├── components/   # Reusable UI components
│   │   ├── context/      # Auth context
│   │   ├── pages/        # Page components
│   │   ├── services/     # API client
│   │   └── utils/        # Helpers
│   └── package.json
└── README.md
```

## Prerequisites

- [Node.js](https://nodejs.org/) v18+
- [MySQL](https://www.mysql.com/) v8+

## Setup

### 1. Database

Create a MySQL database and configure credentials:

```bash
cd backend
copy .env.example .env
```

Edit `.env` with your MySQL credentials:

```env
PORT=5000
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=your_password
DB_NAME=inventory_db
JWT_SECRET=your_super_secret_jwt_key_change_in_production
JWT_EXPIRES_IN=24h
```

Initialize the database tables:

```bash
npm install
npm run init-db
```

### 2. Backend

```bash
cd backend
npm install
npm run dev
```

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

### 3. Frontend

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

App runs at `http://localhost:3000`

## API Endpoints

| Method | Endpoint | Description |
|--------|----------|-------------|
| POST | `/api/auth/register` | Register new user |
| POST | `/api/auth/login` | Login |
| GET | `/api/auth/profile` | Get user profile |
| GET | `/api/products` | List products |
| POST | `/api/products` | Create product |
| POST | `/api/products/:id/stock` | Adjust stock |
| GET | `/api/categories` | List categories |
| GET | `/api/stock` | Stock movements |
| GET | `/api/reports/dashboard` | Dashboard stats |
| GET | `/api/reports/inventory` | Inventory report |
| GET | `/api/reports/inventory/pdf` | Export PDF |
| GET | `/api/reports/export/csv` | Export CSV |

## Password Requirements

- Minimum 8 characters
- At least one uppercase letter (A-Z)
- At least one lowercase letter (a-z)
- At least one number (0-9)
- At least one special character (@$!%*?&# etc.)

## User Roles

| Role | Permissions |
|------|-------------|
| **Admin** | Full access including delete |
| **Manager** | Create/edit products, categories, export reports |
| **Staff** | View inventory, adjust stock |

## Tech Stack

- **Frontend:** React 18, Vite, Tailwind CSS, React Router, Axios, Lucide Icons
- **Backend:** Node.js, Express, MySQL2, JWT, bcryptjs, PDFKit
- **Database:** MySQL
