A production-grade workforce management system enforcing spatial geofencing for field operations using native MySQL spherical calculations and DB-level pessimistic concurrency control.
Features • Architecture • Database • API Spec • Installation • Testing
- Spatial Geofencing Engine: Enforces sub-100m geofence boundaries for mobile clock-ins using MySQL 8.0 native geodesic distance calculations (
ST_Distance_Sphere). - Race-Condition & Anti-Tampering Protection: Prevents duplicate active shifts across multiple devices using atomic transactions wrapped in database pessimistic locking (
SELECT ... FOR UPDATE). - Role-Based Access Control (RBAC): Strict segregation between System Administrators (Project & Worker CRUD) and Field Workers (Project view & Geofenced Clock-in/out).
- Real-Time Operational Dashboard: Real-time stats on active projects, total workers, current active shifts, and daily compliance percentages.
- Modern Responsive SPA: React 19 single-page app powered by Vite, Tailwind CSS, TanStack Query (v5), and the HTML5 Geolocation API with hardware fallback handling.
flowchart TD
subgraph Client["React 19 SPA (Vite + TanStack Query)"]
UI_Login["Login Screen (/login)"]
UI_Admin["Admin Dashboard (/admin/*)"]
UI_Worker["Worker Dashboard (/worker/*)"]
GPS["Browser Geolocation API"]
end
subgraph API["Laravel 13 REST API (/api/v1)"]
AuthCtrl["AuthController (Sanctum Tokens)"]
ProjCtrl["ProjectController (CRUD & Assignments)"]
AttCtrl["AttendanceController (Clock In / Out)"]
AdminCtrl["AdminController (Metrics)"]
RadiusSvc["AttendanceRadiusService (Pessimistic Locking)"]
end
subgraph DB["MySQL 8.0 Spatial Engine"]
ST_Dist["ST_Distance_Sphere(POINT(lng1, lat1), POINT(lng2, lat2))"]
Tables[("users | projects | project_user | attendances")]
end
UI_Login -->|"POST /auth/login"| AuthCtrl
UI_Worker -->|"GPS Coordinates"| GPS
GPS -->|"POST /attendance/clock-in"| AttCtrl
UI_Admin -->|"GET /admin/*"| AdminCtrl
AttCtrl --> RadiusSvc
RadiusSvc --> ST_Dist
ST_Dist --> Tables
| Table | Core Columns | Description & Constraints |
|---|---|---|
users |
id, name, email, role, phone, status |
Stores credentials and user profiles (admin/worker, active/inactive). |
projects |
id, name, latitude, longitude, geofence_radius_meters |
Stores site coordinates with high-precision decimals (10,8) and (11,8). |
project_user |
project_id, user_id, assigned_at |
Pivot table mapping worker site assignments. Unique index on [project_id, user_id]. |
attendances |
user_id, project_id, distance_meters, status, clock_in_at |
Attendance log (approved / rejected_outside_radius). |
All endpoints strictly return a unified JSON payload envelope:
{
"success": true,
"message": "Clocked in successfully. Distance from site center: 12.4m (Allowed: 100m).",
"data": {
"id": 102,
"user_id": 5,
"project_id": 1,
"clock_in_latitude": 31.235711,
"clock_in_longitude": 30.044420,
"distance_meters": 12.4,
"status": "approved",
"clock_in_at": "2026-11-04 02:00:00",
"clock_out_at": null
},
"errors": null
}{
"success": false,
"message": "Clock-in rejected. You are 245.8m away from the work site center (Allowed: 100m).",
"data": null,
"errors": {
"geofence": ["Worker location is outside the allowed radius."]
}
}- Backend Framework: Laravel 13 (PHP 8.3)
- Authentication: Laravel Sanctum (Bearer Tokens)
- Permissions & Roles: Spatie Laravel-Permission
- Database Engine: MySQL 8.0+ Spatial Calculations
- Frontend Framework: React 19 + Vite
- State Management & Data Fetching: TanStack Query (React Query v5)
- Styling: Tailwind CSS + Lucide Icons
- Testing & CI/CD: PHPUnit, Parallel Testing, GitHub Actions Service Containers
Make sure you have installed on your local environment:
- PHP 8.3 or higher
- Composer 2.x
- Node.js 20.x & NPM
- MySQL 8.0+
git clone https://github.com/Abdoxrs/WorkRadius.git
cd WorkRadius# Install PHP dependencies
composer install
# Environment configuration
cp .env.example .env
php artisan key:generate
# Configure database credentials in .env file
# DB_DATABASE=workradius
# DB_USERNAME=root
# DB_PASSWORD=
# Run database migrations and populate seed data
php artisan migrate --seed
# Start Laravel backend server
php artisan serve# Install Node modules
npm install
# Start Vite hot-reloading dev server
npm run dev
# Build production assets
npm run buildAutomated feature and unit test suite verifying spatial accuracy, security rules, and concurrency control.
php artisan testAuthTest: Login flow, invalid credential handling (401), account deactivation enforcement (403), Sanctum token revocation.AttendanceTest: Inside/outside geofence radius checks, unassigned worker access blocks, double-shift concurrency prevention (409 Conflict), clock-out calculations.ProjectTest: Admin site creation, worker site assignments, worker boundary restrictions (/my-projects).AdminTest: Worker CRUD operations, status toggling, dashboard KPI analytics payload.
Tests: 21 passed (83 assertions)
Duration: 7.73s
Result: 100% PASS
| Role | Password | Access Level | |
|---|---|---|---|
| Administrator | admin@workradius.com |
password |
Full system management & live logs |
| Field Worker | worker@workradius.com |
password |
Site view & GPS clock-in/out |
This project is open-source and available under the MIT License.