This project is a lightweight Spring Boot microservice built as a Backend Engineer homework assignment.
It demonstrates core backend engineering skills including REST API design, relational data modeling, event logging, data visualization, and containerization.
- Java 11
- Spring Boot 2.7.18
- Spring Web, Spring Data JPA
- MySQL 8
- Hibernate / JPA
- XChart (data visualization)
- Springdoc OpenAPI (Swagger)
- Docker & Docker Compose
- CRUD REST API for Employee
- One-to-Many relationship: Employee → Events
- Automatic event logging on each CRUD operation
- Graph endpoint that visualizes events over time
- Global error handling & validation
- Health check endpoint
- Fully dockerized (App + MySQL)
| Field | Type |
|---|---|
| id | Long |
| name | String |
| role | String |
| createdAt | Timestamp |
| Field | Type |
|---|---|
| id | Long |
| employee | Many-to-One |
| type | GET / POST / PUT / DELETE |
| timestamp | Timestamp |
Relationship Employee 1 ──── * Event
Each CRUD operation on Employee automatically creates a corresponding Event.
| Method | Endpoint | Description |
|---|---|---|
| POST | /employee |
Create employee |
| GET | /employee/{id} |
Get employee by id |
| GET | /employees |
List all employees |
| PUT | /employee/{id} |
Update employee |
| DELETE | /employee/{id} |
Delete employee |
| Method | Endpoint | Description |
|---|---|---|
| POST | /events/graph |
Returns graph metadata (JSON) |
| POST | /events/graph/image |
Streams PNG graph |
Request example
{ "empIds": [1,2,3], "from": "01-12-2025 00:00", "to": "31-12-2025 23:59", "bucket": "DAY" } The PNG graph visualizes event counts per employee within the given time range.
🧪 Validation & Error Handling @Valid request validation
Consistent error responses
Proper HTTP status codes
Example Error Response { "status": 400, "message": "name must not be blank" } Error Mapping Scenario Status Validation error 400 Malformed JSON / enum 400 Resource not found 404 Unexpected error 500
🩺 Health Check GET /actuator/health Response:
{ "status": "UP" }
📊 Swagger / OpenAPI Swagger UI is available at:
http://localhost:8080/swagger-ui/index.html All endpoints, request/response models, and validations are documented.
🐳 Running with Docker Compose 1️⃣ Build & Start docker compose up --build
This starts:
Spring Boot application MySQL 8 database
2️⃣ Stop & Clean docker compose down -v
🔍 Sample cURL Commands Create Employee
curl -u user:user
-H "Content-Type: application/json"
-d '{"name":"Merve","role":"Backend Engineer"}'
http://localhost:8080/employee
Get Employee
curl -u user:user http://localhost:8080/employee/1 Graph Image
curl -u user:user
-H "Content-Type: application/json"
-d '{"empIds":[1],"from":"01-12-2025 00:00","to":"31-12-2025 23:59","bucket":"DAY"}'
http://localhost:8080/events/graph/image
--output graph.png
Update Employee
curl -i -u user:user
-H "Content-Type: application/json"
-d '{"name":"Merve D.","role":"Senior Backend Engineer"}'
-X PUT http://localhost:8080/employee/1
🗄 Database Schema (MySQL) Tables:
employees events
Foreign key: events.employee_id → employees.id (ON DELETE CASCADE) Indexes ensure efficient graph queries by employee and time.
📦 Project Structure css Copy code src/main/java ├── employee │ ├── EmployeeController │ ├── EmployeeService │ ├── EmployeeRepository │ └── dto ├── event │ ├── Event │ ├── EventService │ └── graph └── common ├── GlobalExceptionHandler ├── ApiError └── NotFoundException
🎯 Design Decisions & Assumptions Event logging is part of the core business logic GET operations also produce events (explicit requirement) Graph endpoint prioritizes clarity over heavy analytics JPA lifecycle callbacks are used for timestamps Docker Compose preferred over Kubernetes for simplicity
✅ Evaluation Criteria Coverage ✔ Clean REST API design ✔ Proper JPA & MySQL usage ✔ One-to-Many mapping ✔ Event logging correctness ✔ Graph filtering by employee & time ✔ Validation & error handling ✔ Swagger documentation ✔ Containerized setup
👤 Author Merve Döker Senior Java Backend Engineer
This project was created as a focused technical exercise to demonstrate backend engineering fundamentals without unnecessary complexity.