# DAB Enterprise LTD — Human Resource Management System (HRMS)

Web-based HRMS for **DAB Enterprise LTD** (Kigali City, Rwanda) — building tools and construction materials. Built with the **MERN stack**: MongoDB, Express.js, React.js, Node.js.

**TSS National Integrated Assessment 2025-2026**

---

## Features

- Employee, Department, and Position CRUD
- JWT authentication with **protected API routes**
- **Input sanitization** (XSS strip, `express-mongo-sanitize`, Helmet, rate limiting)
- **Server-side** validation (`express-validator`) and **client-side** form validation
- **Reset password** by employee email (no Nodemailer — password reset instantly with temporary password shown on screen)
- Dashboard with workforce statistics
- Modern UI with **Tailwind CSS v4** and React 18

---

## Folder structure

```
dab-enterprise-hrms/
├── README.md
├── .gitignore
│
├── backend/
│   ├── package.json
│   ├── .env.example
│   ├── .env
│   └── src/
│       ├── server.js
│       ├── config/
│       │   └── db.js
│       ├── models/
│       │   ├── Department.js
│       │   ├── Position.js
│       │   ├── Employee.js
│       │   └── User.js
│       ├── middleware/
│       │   ├── auth.js
│       │   ├── validate.js
│       │   └── errorHandler.js
│       ├── validators/
│       │   ├── authValidator.js
│       │   ├── employeeValidator.js
│       │   ├── departmentValidator.js
│       │   └── positionValidator.js
│       ├── controllers/
│       │   ├── authController.js
│       │   ├── employeeController.js
│       │   ├── departmentController.js
│       │   └── positionController.js
│       ├── routes/
│       │   ├── authRoutes.js
│       │   ├── employeeRoutes.js
│       │   ├── departmentRoutes.js
│       │   └── positionRoutes.js
│       └── utils/
│           └── seed.js
│
└── frontend/
    ├── package.json
    ├── vite.config.js
    ├── index.html
    ├── public/
    │   └── favicon.svg
    └── src/
        ├── main.jsx
        ├── App.jsx
        ├── index.css
        ├── api/
        │   └── axios.js
        ├── context/
        │   └── AuthContext.jsx
        ├── utils/
        │   └── validation.js
        ├── components/
        │   ├── ProtectedRoute.jsx
        │   ├── layout/
        │   │   ├── Sidebar.jsx
        │   │   └── DashboardLayout.jsx
        │   └── ui/
        │       ├── Button.jsx
        │       ├── Input.jsx
        │       ├── Select.jsx
        │       └── Modal.jsx
        └── pages/
            ├── Login.jsx
            ├── ResetPassword.jsx
            ├── Dashboard.jsx
            ├── Employees.jsx
            ├── Departments.jsx
            └── Positions.jsx
```

---

## Entity Relationship Diagram (ERD)

### Entities and attributes

| Entity | Attributes |
|--------|------------|
| **Employee** | EmpFirstName, EmpLastName, EmpEmail, EmpTelephone, EmpGender, EmpAddress, EmpDateOfBirth, EmpHireDate, EmpStatus |
| **Department** | DepartName |
| **Position** | PosName, RequiredQualification |
| **User** | UserName, Password |

### Relationships

1. **Department — Employee** (1 : N)  
   One department has many employees; each employee belongs to exactly one department.

2. **Position — Employee** (1 : N)  
   One position can be held by many employees; each employee has exactly one position.

3. **Employee — User** (1 : 1)  
   A user is also an employee; each user account links to one employee record.

### ERD diagram (Mermaid)

```mermaid
erDiagram
    DEPARTMENT ||--o{ EMPLOYEE : "has many"
    POSITION ||--o{ EMPLOYEE : "has many"
    EMPLOYEE ||--|| USER : "is also"

    DEPARTMENT {
        ObjectId _id PK
        string departName
        datetime createdAt
        datetime updatedAt
    }

    POSITION {
        ObjectId _id PK
        string posName
        string requiredQualification
        datetime createdAt
        datetime updatedAt
    }

    EMPLOYEE {
        ObjectId _id PK
        string empFirstName
        string empLastName
        string empEmail UK
        string empTelephone
        string empGender
        string empAddress
        date empDateOfBirth
        date empHireDate
        string empStatus
        ObjectId department FK
        ObjectId position FK
        datetime createdAt
        datetime updatedAt
    }

    USER {
        ObjectId _id PK
        string userName UK
        string password
        ObjectId employee FK UK
        datetime createdAt
        datetime updatedAt
    }
```

### ASCII ERD

```
┌─────────────────┐         ┌─────────────────┐
│   DEPARTMENT    │         │    POSITION     │
├─────────────────┤         ├─────────────────┤
│ PK _id          │         │ PK _id          │
│    departName   │         │    posName      │
└────────┬────────┘         │    requiredQual │
         │ 1                └────────┬────────┘
         │                           │ 1
         │ N                         │ N
         ▼                           ▼
┌─────────────────────────────────────────────┐
│                  EMPLOYEE                    │
├─────────────────────────────────────────────┤
│ PK _id                                       │
│    empFirstName, empLastName, empEmail        │
│    empTelephone, empGender, empAddress        │
│    empDateOfBirth, empHireDate, empStatus     │
│ FK department, FK position                    │
└────────────────────┬────────────────────────┘
                     │ 1
                     │ 1
                     ▼
              ┌─────────────┐
              │    USER     │
              ├─────────────┤
              │ PK _id      │
              │    userName │
              │    password │
              │ FK employee │
              └─────────────┘
```

---

## Prerequisites

- [Node.js](https://nodejs.org/) 18+
- [MongoDB](https://www.mongodb.com/) running locally (or MongoDB Atlas URI in `.env`)

---

## Installation and run

### 1. Backend

```bash
cd backend
npm install
cp .env.example .env
npm run seed
npm run dev
```

API: `http://localhost:5000`

### 2. Frontend

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

App: `http://localhost:5173`

---

## Default login (after seed)

| Field | Value |
|-------|--------|
| Username | `admin` |
| Password | `Admin@123` |

**Reset password test email:** `jean.uwimana@dabenterprise.rw`  
Default temporary password after reset: `Reset@12345` (configurable in `backend/.env`)

---

## API endpoints

| Method | Endpoint | Auth | Description |
|--------|----------|------|-------------|
| POST | `/api/auth/login` | No | Login |
| POST | `/api/auth/register` | No | Register user for employee |
| POST | `/api/auth/reset-password` | No | Reset by employee email |
| GET | `/api/auth/me` | Yes | Current user |
| GET/POST | `/api/employees` | Yes | List / create employees |
| GET/PUT/DELETE | `/api/employees/:id` | Yes | Employee by ID |
| GET | `/api/employees/stats` | Yes | Dashboard stats |
| GET/POST | `/api/departments` | Yes | Departments |
| GET/PUT/DELETE | `/api/departments/:id` | Yes | Department by ID |
| GET/POST | `/api/positions` | Yes | Positions |
| GET/PUT/DELETE | `/api/positions/:id` | Yes | Position by ID |

---

## Security

- JWT bearer tokens on protected routes
- `bcryptjs` password hashing
- `helmet`, CORS, rate limiting
- `express-mongo-sanitize` + custom HTML tag stripping
- `express-validator` on all mutating endpoints
- React protected routes via `ProtectedRoute` + axios 401 interceptor

---

## Tech stack

| Layer | Technology |
|-------|------------|
| Database | MongoDB + Mongoose |
| API | Node.js, Express.js |
| Frontend | React 18, Vite, React Router 7 |
| Styling | Tailwind CSS v4 (`@tailwindcss/vite`) |
| Auth | JSON Web Tokens |

---

## License

Educational project — DAB Enterprise LTD HRMS assessment.


This diagram treats your entire DAB Enterprise HRMS as a single central process, showing exactly how information flows between the core system and your two main external actors (Employee and HR Admin).

Level 0 Context Diagram
                        [ EMPLOYEE / STAFF ]
                           /            \
    Login Credentials     /              \    Auth Token, Profile Details,
    Password Reset Data  /                \   Status Toast Alerts
                        v                  \
               +----------------------------------+
               |                                  |
               |             PROCESS 0            |
               |                                  |
               |       DAB Enterprise HRMS        |
               |                                  |
               +----------------------------------+
                        ^                  /
    Employee Profiles,  \                  /  Workforce Directory,
    Dept & Position Config\                /   System Audits & Logs
                           \              v
                         [ HR MANAGER / ADMIN ]
Key Data Elements in this Diagram
The Core Process (0): Represents your entire Node.js/Express backend, MERN stack logic, and MongoDB databases bundled into one single boundary line.

Employee Flows: * Inflow: Sends data into the system to verify identity (login) or request credential updates (resetPassword).

Outflow: Receives profile details back from the server (getMe) and interactive UI alerts via your frontend state.

HR Admin Flows:

Inflow: Sends structured operational data to build the organization (employeeRoutes, departmentRoutes, positionRoutes).

Outflow: Receives data streams from the server to populate administrative dashboards and data tables.