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ā
| Layer | Technology |
|---|---|
| Language | Java 21 |
| Framework | Spring Boot 3 |
| Database | PostgreSQL 15+ |
| Schema Migrations | Flyway |
| Auth | Azure AD OAuth2 + JWT |
| Microsoft Integrations | Microsoft Graph API |
| Build Tool | Maven (via mvnw wrapper) |
| Containerisation | Docker + 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:
| Employee | Role | Capabilities |
|---|---|---|
| Amara Osei (CEO) | ADMIN | Full access to everything |
| Esi Adjei (HR Manager) | HR_MANAGER | Manage all employees and time off |
| Kofi Boateng (Head of Engineering) | MANAGER | Approve team requests, view team |
| Yaw Asante (Software Engineer 3) | EMPLOYEE | View own profile, request time off |
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:
| Endpoint | Permission | Description |
|---|---|---|
GET /api/v1/admin/roles | ROLE_READ | List all roles with permissions |
POST /api/v1/admin/roles | ROLE_CREATE | Create a new role |
PUT /api/v1/admin/roles/{id} | ROLE_UPDATE | Update role name/description/permissions |
DELETE /api/v1/admin/roles/{id} | ROLE_DELETE | Delete a custom role |
GET /api/v1/admin/permissions | ROLE_READ | List all permissions |
GET /api/v1/admin/employees/{id}/roles | ROLE_READ | Get an employee's roles |
PUT /api/v1/admin/employees/{id}/roles | ROLE_ASSIGN | Set an employee's roles |
Microsoft Integrationsā
All Microsoft integrations are optional ā the app works fully in dev mode without any Azure credentials.
| Integration | Purpose | Dev Mode |
|---|---|---|
| Azure AD SSO | "Sign in with Microsoft" button | Dev login dropdown (no SSO button) |
| SharePoint | Document browsing, upload, preview | Mock service returns realistic fake data |
| Calendar Sync | Sync approved time-off to Outlook | Events 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
Never modify an existing migration. Always create a new V{next}__description.sql file.
Further Readingā
| Document | Description |
|---|---|
| Architecture | Package layout, security, request flow diagram |
| Domain Modules | Detailed breakdown of each domain package |
| Database Schema | Full table reference, ERD, and migration history |
| HR Workflows | Time-off, timesheet, document signing, and lifecycle workflows |
| ADRs | All 26 architectural decision records |
| Microsoft Integration | Azure AD SSO, SharePoint, and Outlook Calendar setup |
| Database Review | Schema review findings and recommendations |