Home & Introduction
Relevant source files
The following files were used as context for generating this wiki page:
- README.md
- Part1/API/src/main/resources/api-spec.yaml
- Part1/API/src/main/java/com/example/api/security/SecurityConfig.java
- Part1/API/src/main/java/com/example/api/model/Employee.java
- Part1/API/src/main/java/com/example/api/model/Department.java
- Part1/API/src/main/java/com/example/api/model/Assignment.java
- Part1/API/src/main/java/com/example/api/controller/EmployeeController.java
The SafeDispatch HQ Administration API is a RESTful service designed for headquarters administrators to manage organizational resources, including employees, departments, and project assignments. The system provides a centralized interface for HR and Management roles to perform CRUD operations, process employee promotions, and manage departmental budgets.
The project is built using the Spring Boot framework, utilizing Spring Security for Role-Based Access Control (RBAC) and Spring Data JPA for persistence. All administrative actions are secured via HTTPS and require Basic Authentication.
Sources: api-spec.yaml:4-8, SecurityConfig.java:36-47, ApiApplication.java:1-15
System Architecture
The application follows a standard layered architecture, separating concerns between the presentation (Controllers), business logic (Services), and data access (Repositories) layers.
Logical Component Overview
The system is organized into several key components:
- API Controllers: Handle incoming HTTP requests and map them to service methods.
- Service Layer: Implements business logic, such as promotion eligibility checks and budget validation.
- Data Models: Entity classes representing the core business objects (Employee, Department, Assignment).
- Security: Configurations for authentication and authorization based on user roles (HR, MANAGER).
The diagram above illustrates the request flow from the client through the security layers to the database.
Sources: SecurityConfig.java:16-52, EmployeeController.java:15-20, EmployeeService.java:12-18, EmployeeRepository.java:14-15
Data Models and Relationships
The core of the system revolves around three primary entities: Employee, Department, and the associative Assignment entity that links them.
Entity Relationships
- Employee to Assignment: One-to-Many. An employee can have multiple department assignments.
- Department to Assignment: One-to-Many. A department can host multiple employee assignments.
- Assignment: Acts as a join table containing specific metadata like the employee's role within that department and their access level.
This ER diagram shows the relationship between employees and departments via the assignment entity.
Sources: Employee.java:12-30, Department.java:11-22, Assignment.java:7-22
Security and Role-Based Access Control
The API implements strict access control using Spring Security. Users are authenticated via Basic Auth, and authorization is determined by roles assigned to the user.
| Endpoint Pattern | Allowed Roles | HTTP Methods |
|---|---|---|
/api/** | MANAGER, HR | GET |
/api/** | HR | POST, PUT, DELETE |
Authentication Flow
On startup, a DataLoader initializes default users:
- hr: Username "hr", Password "hr123", Role "HR".
- manager: Username "manager", Password "manager123", Role "MANAGER".
Sources: SecurityConfig.java:41-44, DataLoader.java:14-30, api-spec.yaml:15-23
Core API Features
Employee Management
The system allows for comprehensive employee lifecycle management. A notable feature is the Promotion Logic, which applies a 10% salary increase and updates the employee's rank to "Senior".
- Eligibility: Employees must have a
startDateat least 6 months in the past. - Validation: If an employee is ineligible, a
400 Bad Requestis returned.
Sources: EmployeeController.java:82-100, EmployeeService.java:51-71, api-spec.yaml:188-210
Department and Budgeting
Departments are created with a mandatory name, budget, and location. The system enforces that the budget must always be a positive integer.
- Validation:
IllegalArgumentExceptionis thrown if the budget is zero or negative.
Sources: Department.java:20-22, DepartmentController.java:32-38, DepartmentService.java:26-31
Conclusion
The SafeDispatch HQ Administration API provides a structured and secure environment for organizational management. By leveraging Spring Boot's ecosystem, it ensures data integrity through JPA relationships and enforces operational security via role-based permissions, specifically restricting sensitive write operations to HR personnel.
Sources: README.md:1-10, api-spec.yaml:4-10