Skip to main content

Architecture Overview

The HRMS is a two-tier web application consisting of a Laravel API backend and a Next.js frontend, communicating over REST JSON APIs with cookie-based session authentication.

System Diagram

┌──────────────────────────────┐         ┌──────────────────────────────┐
│ HRMS Frontend │ │ HRMS Backend │
│ (hrms-web) │ HTTP │ (hrms-api) │
│ │◄───────►│ │
│ Next.js 16 (App Router) │ JSON │ Laravel 12 │
│ React 19 + TypeScript 5 │ │ PHP 8.2+ │
│ Tailwind CSS v4 │ │ PostgreSQL │
│ shadcn/ui Components │ │ Spatie RBAC │
│ │ │ Laravel Sanctum │
│ http://localhost:3000 │ │ http://localhost:8000 │
└──────────────────────────────┘ └──────────┬───────────────────┘

┌──────────▼───────────────────┐
│ PostgreSQL │
│ hrms-db │
└─────────────────────────────┘

Technology Stack

LayerTechnologyVersion
Backend FrameworkLaravel12.x
Backend LanguagePHP8.2+
DatabasePostgreSQL15+
AuthenticationLaravel Sanctum4.x
Authorization (RBAC)Spatie Laravel Permission6.x
API DocumentationScramble (Dedoc)0.13.x
Backend TestingPHPUnit11.x
Frontend FrameworkNext.js (App Router)16.x
Frontend UI LibraryReact19.x
Frontend LanguageTypeScript5.x
CSS FrameworkTailwind CSS4.x
UI Component Libraryshadcn/uiLatest

Key Architecture Decisions

DecisionChoiceRationale
API StyleRESTful JSON APISimple, well-understood, suitable for CRUD-heavy operations
AuthenticationCookie-based SPA via SanctumSecure, no token management on frontend, CSRF protection built in
RBACSpatie Laravel PermissionIndustry-standard role + permission model with middleware support
Frontend RenderingClient-side (CSR)SPA-style with cookie auth; no SSR needed for internal admin dashboard
Component Libraryshadcn/uiCopy-paste components, fully customizable, Tailwind-native
DatabasePostgreSQLProduction-grade, supports advanced queries, JSON columns
Separate repositorieshrms-api + hrms-webIndependent deployment, clear separation of concerns

Data Flow

Browser → Frontend (Next.js, port 3000)
↕ Cookie-based auth (Sanctum session cookie)
API Server (Laravel, port 8000)
↕ Eloquent ORM
PostgreSQL Database (hrms-db)
  1. The frontend is a client-side rendered SPA.
  2. All API calls use credentials: "include" to send session cookies automatically.
  3. The backend validates the session cookie on every request via Sanctum middleware.
  4. Authorization is enforced by Laravel Policies backed by Spatie permissions.
  5. The frontend reads the user's permissions from GET /api/me and conditionally renders UI elements.

Core Design Patterns

PatternWhere Used
Form Request validationAll mutation endpoints (47 FormRequest classes)
Policy authorizationAll controllers (7 policy classes)
API Resource transformersAll responses (25 resource classes)
Service layerWorkflow logic (KPI, Probation, Notifications)
Transaction + pessimistic lockingAll workflow mutations
Snapshot patternKPI evaluations and probation records preserve historical data
Polymorphic audit trailAll workflow actions logged to audit_events
Consistent response envelope{ data, message, meta? } across all endpoints