Production-ready HR/Employee Management System built with Laravel 10 (API) and React 18 (Vite).
Backend:
- Laravel 10 (API-only)
- MySQL
- Laravel Sanctum (Token-based authentication)
- Spatie Laravel Permission (Role & Permission management)
Frontend:
- React 18
- Vite
- React Router
- TanStack Query
- Zustand (State management)
- Axios
- ✅ Token-based authentication with Laravel Sanctum
- ✅ Role-based access control (Admin, HR Manager, Employee)
- ✅ RESTful API with resource controllers
- ✅ Clean architecture: Service + Repository pattern
- ✅ FormRequest validation
- ✅ API Resources for consistent JSON responses
- ✅ Employee management
- ✅ Department management
- ✅ Attendance tracking
- ✅ Leave management
hr-management-system/
├── backend/ # Laravel API
│ ├── app/
│ │ ├── Http/
│ │ │ ├── Controllers/API/
│ │ │ ├── Requests/
│ │ │ └── Resources/
│ │ ├── Models/
│ │ ├── Repositories/
│ │ └── Services/
│ ├── database/
│ │ ├── migrations/
│ │ └── seeders/
│ └── routes/api.php
├── frontend/ # React App
│ ├── src/
│ │ ├── components/
│ │ ├── lib/
│ │ ├── pages/
│ │ ├── store/
│ │ └── routes.jsx
│ └── package.json
└── API_DOCUMENTATION.md # Complete API docs
- PHP 8.2+
- Composer
- Node.js 20.19+ or 22+
- MySQL 8.0+
cd backend
# Install dependencies
composer install
# Configure database in .env
# DB_DATABASE=hr_management
# DB_USERNAME=root
# DB_PASSWORD=
# Run migrations and seed data
php artisan migrate --force
php artisan db:seed --force
# Start server
php artisan serveBackend will run at: http://127.0.0.1:8000
cd frontend
# Install dependencies
npm install
# Start development server
npm run devFrontend will run at: http://localhost:5173
Admin Account:
- Email:
admin@example.com - Password:
password - Role: Admin (full access)
POST /api/login- LoginPOST /api/register- Register new userGET /api/me- Get current userPOST /api/logout- Logout
/api/departments- Department CRUD/api/employees- Employee CRUD/api/attendances- Attendance CRUD/api/leaves- Leave CRUD
See API_DOCUMENTATION.md for complete API documentation with request/response examples.
# Login
curl -X POST http://127.0.0.1:8000/api/login \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"email":"admin@example.com","password":"password"}'
# Get current user (use token from login response)
curl -X GET http://127.0.0.1:8000/api/me \
-H "Authorization: Bearer YOUR_TOKEN_HERE"Run the automated test script:
./test-api.shThis will test all authentication endpoints and verify token functionality.
- Full system access
- All CRUD operations on all resources
- Create, update, view departments
- Create, update, view employees
- Create, update, view attendance
- Create, update, view leaves
- No delete permissions
- Self-service operations (customize based on requirements)
Repository Pattern:
Controller → Service → Repository → Model
Request Flow:
- Request validated by FormRequest
- Controller calls Service method
- Service contains business logic
- Repository handles database operations
- Resource transforms model to JSON response
State Management:
- Zustand for auth state
- TanStack Query for server state
- React Router for navigation
- Create migration:
php artisan make:migration create_table_name - Create model:
php artisan make:model ModelName - Create repository:
app/Repositories/ModelRepository.php - Create service:
app/Services/ModelService.php - Create controller:
php artisan make:controller API/ModelController - Create FormRequest:
php artisan make:request StoreModelRequest - Create Resource:
php artisan make:resource ModelResource - Add routes to
routes/api.php
# Backend tests
cd backend
php artisan test
# Frontend tests
cd frontend
npm test- Token-based authentication via Laravel Sanctum
- Password hashing with bcrypt
- Rate limiting: 60 requests/minute per user/IP
- CORS configured for localhost development
- FormRequest validation on all inputs
- SQL injection prevention via Eloquent ORM
- Set
APP_ENV=productionin.env - Set
APP_DEBUG=false - Generate app key:
php artisan key:generate - Cache config:
php artisan config:cache - Cache routes:
php artisan route:cache - Optimize autoloader:
composer install --optimize-autoloader --no-dev
npm run buildDeploy the dist/ folder to your web server.
This project is open-source and available under the MIT License.
For API documentation, see API_DOCUMENTATION.md
For issues or questions, please open an issue on GitHub.