Feature Specification: HR Analytics & Reporting
1. Overview & Vision
The Analytics module surfaces actionable HR insights from data that already exists across the HRM module. It eliminates the need to export to spreadsheets for basic questions like headcount trends, leave utilization, or attendance patterns.
2. Personas & Stakeholders
| Persona | Goal |
|---|---|
| HR Manager | Answer "how many people joined this quarter?" without exporting data. |
| Department Head | Understand leave and attendance patterns in their team. |
| Executive | Track headcount and payroll cost trends for strategic planning. |
3. User Stories
- As HR, I want to see a monthly headcount chart for the past 12 months split by status.
- As a department head, I want to see which of my employees used the most leave days this year.
- As HR, I want to see the average on-time rate by department for the past 30 days.
4. Functional Requirements (FR)
- REQ-AN-001: Headcount panel — headcount by status over time (line chart, monthly, last 12 months).
- REQ-AN-002: Headcount by department (bar chart).
- REQ-AN-003: New hires vs. terminations per month (grouped bar chart).
- REQ-AN-004: Leave utilization — days taken by type per department (stacked bar).
- REQ-AN-005: Top 10 employees by leave days used.
- REQ-AN-006: Department leave rate — average days per employee.
- REQ-AN-007: Attendance panel — average on-time rate by department.
- REQ-AN-008: Late / absent trends over past 30 days.
- REQ-AN-009: Date range selector controlling all panels simultaneously.
5. Non-Functional Requirements (NFR)
- Performance: All charts load within 2 seconds for organizations up to 1000 employees.
- Access: Gated behind
analytics:readpermission (HR Admin / Manager role).
6. Business Logic & Rules
- Date Range: Default to last 12 months; user can select custom range.
- Real Data Only: No hardcoded mocks — all charts pull from live DB aggregates.
- Department Scoping: Department heads see only their department's data; HR sees org-wide.
7. User Interface (UI/UX)
- Layout: Three panels — Headcount, Leave Utilization, Attendance.
- Charts: Built with
recharts(no new dependency — already used by dashboard). - Mobile: Charts scroll horizontally on small screens; simplified view option.
- Date Picker: Single range selector at the top controls all panels.
8. Information Architecture
/analyticsroute in HRM, accessible to HR Admin and Managers.- Links from the HRM Dashboard summary cards.
9. Data Model & Persistence
- No new tables — aggregates computed from
employees,leave_requests,attendance_records. - API endpoints perform GROUP BY queries with date windowing.
10. API & Service Layer
GET /analytics/headcount?from=&to=— monthly counts by statusGET /analytics/leave?from=&to=— leave utilization aggregatesGET /analytics/attendance?from=&to=— attendance rate aggregates
11. Integration Patterns
- Payroll: Total payroll cost per department available as an optional panel (if payroll module is enabled).
12. Security & Permissions
- RBAC:
analytics:readrequired. Department heads receive department-scoped responses. - No PII in charts: Aggregated data only; individual records not exposed through analytics API.
13. Error Handling & Resilience
- Empty data range returns zero-value chart (not an error) with a friendly message.
- Slow queries time out at 10 seconds with a user-facing retry option.
14. Performance & Scalability
- Heavy aggregations run asynchronously and are cached for 1 hour.
- Incremental cache invalidation on new employee, leave, or attendance records.
15. Globalization & i18n
- Chart axis labels and tooltips support EN/VI.
- Date formatting respects the org's locale setting.
16. Accessibility (a11y)
- All charts have accessible data tables as an alternative view.
- Color choices are WCAG contrast-safe and colorblind-friendly.
17. Observability & Analytics
- Query duration tracked per endpoint for performance regression detection.
18. Testing & Quality
- Unit tests for aggregate query correctness with known seed data.
- Visual regression tests for chart rendering.
19. Constraints & Assumptions
- Requires at least 1 month of historical data for meaningful trends.
- Attendance analytics require the Attendance module to be active.
20. Future Enhancements
- Predictive attrition scoring.
- Payroll cost analytics with budget vs. actual comparison.
- Export charts to PNG / PDF.