Skip to main content

Backend Overview

BonardaHR's backend is a Spring Boot 3 REST API backed by PostgreSQL 15 and managed with Flyway migrations. It follows a package-by-feature (domain-driven) layout, uses JWT-based stateless authentication, and integrates optionally with Microsoft Azure AD, SharePoint, and Outlook via the Microsoft Graph API.


Tech Stack​

LayerTechnology
LanguageJava 21
FrameworkSpring Boot 3
DatabasePostgreSQL 15+
Schema MigrationsFlyway
AuthAzure AD OAuth2 + JWT
Microsoft IntegrationsMicrosoft Graph API
Build ToolMaven (via mvnw wrapper)
ContainerisationDocker + Docker Compose

Project Structure​

backend/
ā”œā”€ā”€ src/main/java/com/turntabl/backend/
│ ā”œā”€ā”€ config/ # Spring Security, CORS, JWT, async config
│ ā”œā”€ā”€ exception/ # GlobalExceptionHandler & custom exceptions
│ └── domain/ # Business Domain Modules (package-by-feature)
│ ā”œā”€ā”€ admin/ # RBAC management & custom role admin
│ ā”œā”€ā”€ common/ # Shared base entities & utilities
│ ā”œā”€ā”€ dashboard/ # Dashboard aggregation metrics
│ ā”œā”€ā”€ document/ # Document folders & SharePoint integration
│ ā”œā”€ā”€ employee/ # Profile management, dynamic fields, CSV import
│ ā”œā”€ā”€ esign/ # E-signature documents & signing requests
│ ā”œā”€ā”€ event/ # Company events & regional holidays
│ ā”œā”€ā”€ feedback/ # Employee surveys, performance & 1-on-1s
│ ā”œā”€ā”€ notification/ # In-app notifications & email dispatcher
│ ā”œā”€ā”€ onboarding/ # Onboarding templates, wizards & checklist tracking
│ ā”œā”€ā”€ organization/ # Departments, offices, teams & org chart tree
│ ā”œā”€ā”€ reports/ # HR metrics & Bradford Factor absenteeism engine
│ ā”œā”€ā”€ timeoff/ # Leave policies, balances, accruals & approvals
│ ā”œā”€ā”€ timesheet/ # Clock in/out & weekly timesheet submissions
│ └── workflow/ # Automated HR workflow engine & oversight
ā”œā”€ā”€ src/main/resources/
│ ā”œā”€ā”€ application.yml # Central configuration
│ └── db/migration/ # Flyway SQL migrations (V1–V19+)
ā”œā”€ā”€ Dockerfile # Multi-stage production build
ā”œā”€ā”€ docker-compose.dev.yml # Local PostgreSQL + pgAdmin
└── pom.xml

Quick Start​

1. Start PostgreSQL​

docker-compose -f docker-compose.dev.yml up -d

This spins up a local PostgreSQL container on port 5432 and a pgAdmin UI.

2. Configure the backend​

cp .env.example .env
# Edit .env with your DB credentials and JWT secret

3. Run the backend​

./mvnw spring-boot:run
# Server starts at http://localhost:8081

The backend runs with spring.profiles.active=dev by default, which automatically seeds 10 sample employees, leave types, balances, and time-off requests via DevDataSeeder.

4. Run the frontend​

cd ../frontend
npm install
npm run dev
# Starts at http://localhost:5173

Dev Login​

In dev mode, the login page shows a dropdown of pre-seeded employees. Select one and click login — no password required. Each employee has a different role:

EmployeeRoleCapabilities
Amara Osei (CEO)ADMINFull access to everything
Esi Adjei (HR Manager)HR_MANAGERManage all employees and time off
Kofi Boateng (Head of Engineering)MANAGERApprove team requests, view team
Yaw Asante (Software Engineer 3)EMPLOYEEView own profile, request time off
info

No Azure AD credentials are required in dev mode. See Microsoft Integration for production SSO setup.


Key Architecture Patterns​

Dual-Identifier Pattern​

Every entity has:

  • An internal BIGSERIAL id — used for foreign keys, joins, and JWT subject claims. Never exposed via the API.
  • A UUID public_id — the only identifier returned to clients.

The mapping boundary is the service layer. See ADR-012 for rationale.

Configurable Employee Sections​

Employee profiles combine fixed columns (name, email, hire date) with dynamic JSONB-backed sections (payroll, emergency contacts, personal interests). Section field definitions live in employee_sections + section_fields; values in employee_field_values. See ADR-001.

Time Off Workflow​

Requests follow a lifecycle: PENDING → APPROVED / REJECTED / CANCELLED. Balance counters (pending, used) are denormalized for O(1) reads and kept in sync across create, review, and cancel operations. Reviews use pessimistic locking to prevent double-approval races. See ADR-013.

Hierarchical Reporting​

Self-referencing reports_to_id with circular reference prevention. The buildHierarchy method in EmployeeServiceImpl fetches the full employee list and builds the org tree in-memory — O(n) per level, acceptable for typical structures (3–5 levels deep).

Bradford Factor Analytics​

HR metrics dashboard includes the Bradford Factor (S² Ɨ D) for measuring absenteeism impact. Risk thresholds (LOW / MEDIUM / HIGH / CRITICAL) are admin-configurable. See ADR-026 for details.

Roles & Permissions Admin​

Admins can create/edit/delete custom roles and assign permissions from the /admin page. The five default roles (ADMIN, IT_MANAGER, HR_MANAGER, MANAGER, EMPLOYEE) are protected from deletion.

Admin API endpoints:

EndpointPermissionDescription
GET /api/v1/admin/rolesROLE_READList all roles with permissions
POST /api/v1/admin/rolesROLE_CREATECreate a new role
PUT /api/v1/admin/roles/{id}ROLE_UPDATEUpdate role name/description/permissions
DELETE /api/v1/admin/roles/{id}ROLE_DELETEDelete a custom role
GET /api/v1/admin/permissionsROLE_READList all permissions
GET /api/v1/admin/employees/{id}/rolesROLE_READGet an employee's roles
PUT /api/v1/admin/employees/{id}/rolesROLE_ASSIGNSet an employee's roles

Microsoft Integrations​

All Microsoft integrations are optional — the app works fully in dev mode without any Azure credentials.

IntegrationPurposeDev Mode
Azure AD SSO"Sign in with Microsoft" buttonDev login dropdown (no SSO button)
SharePointDocument browsing, upload, previewMock service returns realistic fake data
Calendar SyncSync approved time-off to OutlookEvents logged to console

Development Commands​

Backend​

./mvnw spring-boot:run # Run with dev profile
./mvnw compile -q # Quick compile check
./mvnw test # Run all tests
./mvnw clean package # Production build (JAR)

Database Migrations​

Schema changes are managed with Flyway and run automatically on startup.

src/main/resources/db/migration/
ā”œā”€ā”€ V1__create_employee_tables.sql # Core schema: employees, roles, permissions, sections, audit
ā”œā”€ā”€ V2__create_time_off_tables.sql # Time off types, balances, requests, unlimited leave
ā”œā”€ā”€ V3__create_timesheet_tables.sql # Weekly timesheets with approval workflow
ā”œā”€ā”€ V4__create_departments_and_positions.sql # Departments and positions tables
ā”œā”€ā”€ V5__create_document_tables.sql # Document management with signatures
ā”œā”€ā”€ V6__create_company_events.sql # Company-wide events
ā”œā”€ā”€ V7__create_sites.sql # Site/location management
ā”œā”€ā”€ V11__add_reports_feature.sql # Bradford Factor flag, REPORT_READ permission
ā”œā”€ā”€ V12__add_reports_indexes.sql # Performance indexes for reports
└── V13__add_bradford_settings.sql # Configurable Bradford thresholds
caution

Never modify an existing migration. Always create a new V{next}__description.sql file.


Further Reading​

DocumentDescription
ArchitecturePackage layout, security, request flow diagram
Domain ModulesDetailed breakdown of each domain package
Database SchemaFull table reference, ERD, and migration history
HR WorkflowsTime-off, timesheet, document signing, and lifecycle workflows
ADRsAll 26 architectural decision records
Microsoft IntegrationAzure AD SSO, SharePoint, and Outlook Calendar setup
Database ReviewSchema review findings and recommendations