# Sales Record Management System (SRMS)

A full-stack application built with the MERN stack for managing sales, customers, and products with per-user data isolation.

## Features
- **User Authentication**: Secure login and registration using JWT.
- **Data Isolation**: Each user can only view, create, and manage their own sales, customers, and products.
- **Dashboard & Reporting**: View daily, weekly, and monthly sales reports.

## Entity Relationship Diagram (ERD)

```mermaid
erDiagram
    USER ||--o{ PRODUCT : "creates"
    USER ||--o{ CUSTOMER : "registers"
    USER ||--o{ SALE : "records"
    
    USER {
        ObjectId _id PK
        String username
        String password "hashed"
    }
    
    PRODUCT {
        ObjectId _id PK
        String productCode
        String productName
        Number quantitySold
        Number unitPrice
        ObjectId user FK
    }
    
    CUSTOMER {
        ObjectId _id PK
        String customerNumber
        String firstName
        String lastName
        String telephone
        String address
        ObjectId user FK
    }
    
    SALE {
        ObjectId _id PK
        String invoiceNumber
        String salesDate
        String paymentMethod
        Number totalAmountPaid
        String customerNumber
        String productCode
        ObjectId user FK
    }
```

## Setup & Running Locally

### Prerequisites
- Node.js (v14+ recommended)
- MongoDB instance (local or Atlas)

### 1. Backend Setup
1. Open a terminal and navigate to the backend directory:
   ```bash
   cd srms-backend
   ```
2. Install dependencies:
   ```bash
   npm install
   ```
3. Ensure your `.env` file is set up correctly in the `srms-backend` folder. It should look like this:
   ```env
   PORT=5000
   MONGO_URI=your_mongodb_connection_string
   JWT_SECRET=your_jwt_secret_key
   ```
4. Start the backend server:
   ```bash
   npm run dev
   ```
   *The backend runs on http://localhost:5000 by default.*

### 2. Frontend Setup
1. Open a new terminal and navigate to the frontend directory:
   ```bash
   cd srms-frontend
   ```
2. Install dependencies:
   ```bash
   npm install
   ```
3. Start the frontend development server:
   ```bash
   npm run dev
   ```
   *The frontend runs on http://localhost:5173 by default.*

## Usage Flow
1. **Register**: Create a new account. You will be redirected to the login page upon success.
2. **Login**: Enter your credentials to access the system.
3. **Manage Data**: Add products, register customers, and record sales. Your data is isolated and protected from other users.
