How nolifer-jpg/monochrome-backend works
This is a single-service Spring Boot REST backend for task/habit tracking. It’s a classic layered monolith (not microservices) exposing JSON APIs to a future frontend (React/Next.js) and persisting data via Spring Data JPA into H2 (in-memory).
• External clients (browser/frontend, curl/Postman)
• HTTP REST API surface (controllers + endpoints)
• Layer boundaries (controller → service → repository → database)
• DTO mapping and validation
• Global exception handling and how errors become HTTP responses
• Runtime container (Spring Boot app) and build/run (Maven)
From the tree + README, you have these concrete modules/components:
Application entrypoint
• MonochromeApplication.java
Bootstraps Spring context (component scanning, auto-config).
REST API layer
• controller/HealthController.java (health endpoint)
• controller/TaskController.java (tasks endpoints)
Business logic layer
• service/TaskService.java (service interface)
• service/TaskServiceImpl.java (implementation)
Data access layer
• repository/TaskRepository.java (Spring Data JPA repository)
Domain model (persistence)
• domain/Task.java (JPA entity)
API contracts (boundary objects)
• dto/CreateTaskRequest.java (POST input)
• dto/TaskResponse.java (output payload)
Error handling
• exception/GlobalExceptionHandler.java (maps exceptions/validation to responses)
• exception/TaskNotFoundException.java
Config/runtime dependencies
• src/main/resources/application.properties (H2/JPA/Spring config)
• pom.xml, mvnw*, .mvn/** (build tooling)
• Tests: MonochromeApplicationTests.java
TaskController
• deserializes JSON into CreateTaskRequest
• triggers validation (Bean Validation / Spring validation if present)
• calls TaskService
TaskServiceImpl
• applies business rules (e.g., default completed=false, timestamps, etc.)
• constructs/updates Task entity
• calls TaskRepository
Read path (get all tasks)
Client → GET /tasks → Controller → Service → Repository → DB → Service maps list to TaskResponse[] → Controller returns 200 OK.
Command path (complete/delete)
Client → PATCH /tasks/{id}/complete or DELETE /tasks/{id}
• Repository may do findById
• If missing, service throws TaskNotFoundException
• Controller does not catch; GlobalExceptionHandler converts to 404 NOT_FOUND
• On success returns 204 No Content
Error paths (important to show explicitly)
• Validation error (e.g., blank description):
Client → Controller (validation fails) → GlobalExceptionHandler → 400 VALIDATION_ERROR with field details
• Not found:
Service throws TaskNotFoundException → GlobalExceptionHandler → 404 NOT_FOUND
Architectural patterns/design principles to highlight
• Layered architecture with strict direction:
• Controller (HTTP) depends on Service
• Service depends on Repository
• Repository depends on JPA/DB
• DTO boundary:
• Entities (Task) do not go directly over the wire
• CreateTaskRequest/TaskResponse are the API contract
• Centralized exception translation:
• Domain/service exceptions translated into proper HTTP semantics in one place
• Stateless REST:
• No auth/session currently
• In-memory DB for dev (H2), data resets on restart
How the backend sits in its world.
• Person: “Frontend Developer / End User”
• System: “MonoChrome Backend (Spring Boot)”
• External: “Future Frontend (React/Next.js)”
• Data store: “H2 In-Memory DB”
• Protocol: HTTP/JSON
Internal components *as they exist in packages*.
• Controllers
• Repository
• Domain entity
• DTOs
• GlobalExceptionHandler
This matches the file tree and avoids inventing components.
• TaskController, HealthController
• TaskService + TaskServiceImpl
• TaskRepository
• Task entity
• DTOs
• Exception handler + exceptions
On TaskController, list:
• POST /tasks
• GET /tasks
• PATCH /tasks/{id}/complete
• DELETE /tasks/{id}
On HealthController, list:
• GET /health (or whatever is implemented)
Transformations explicitly (DTO ↔ Entity)
• CreateTaskRequest → (mapping) → Task
• Task → (mapping) → TaskResponse
From TaskServiceImpl:
• throws TaskNotFoundException → handled by GlobalExceptionHandler → HTTP 404 payload
From controller/validation:
• MethodArgumentNotValidException (or similar) → GlobalExceptionHandler → HTTP 400 payload
Runtime boundary
Inside it: controllers/services/repositories/handler.
Outside: Client(s) and H2 DB.
“Don’t overthink it” but be very detailed (how to decompose further)
Because this repo is small, the best way to increase fidelity is to separate concerns inside each layer:
• “Request deserialization”
• “Validation”
• “HTTP status codes (201/200/204)”
• “Business rules”
• “Entity lifecycle (createdAt, completed default)”
• “NotFound guard”
• “DTO mapping”
• “Spring Data JPA (CrudRepository/JpaRepository)”
• “findById/save/findAll/deleteById”
• application.properties configures H2 + JPA
• In Build/Run lane (optional but useful):
• Maven Wrapper → Spring Boot plugin → produces runnable app