A clean, production-style CRUD REST API built with Spring Boot 4, Spring Data JPA, and MySQL, demonstrating layered architecture (Controller → Service → Repository) with support for both hard delete and soft delete.
This project is designed as a solid reference implementation of RESTful CRUD principles in Java — proper HTTP status codes, clean separation of concerns, and predictable API contracts.
- Features
- Tech Stack
- Project Architecture
- Getting Started
- Configuration
- API Reference
- Architecture & Implementation Document
- Future Improvements
- License
- ✅ Full CRUD operations for
Studentresources - ✅ Soft delete support (records are flagged, not physically removed)
- ✅ Hard delete support (permanent removal)
- ✅ Layered architecture — Controller / Service / Repository
- ✅ Spring Data JPA with derived query methods
- ✅ MySQL persistence with auto schema sync (
ddl-auto=update) - ✅ Meaningful HTTP status codes (
201,302,404,200)
| Layer | Technology |
|---|---|
| Language | Java 21 |
| Framework | Spring Boot 4.1.0 |
| Data Access | Spring Data JPA / Hibernate |
| Database | MySQL |
| Build Tool | Maven |
| API Style | REST (JSON) |
com.example.SpringBootCRUDOperation
│
├── Controller/
│ └── StudentController.java # REST endpoints — handles HTTP requests/responses
│
├── Service/
│ └── StudentService.java # Business logic layer
│
├── Repository/
│ └── StudentRepository.java # Spring Data JPA repository interface
│
├── Entity/
│ └── Student.java # JPA entity / database model
│
└── SpringBootCrudOperationApplication.java # Application entry point
The application follows a classic three-tier layered architecture:
- Controller Layer — Exposes REST endpoints and handles request/response mapping.
- Service Layer — Encapsulates business rules (e.g., defaulting
deleted = false, merging update fields). - Repository Layer — Handles persistence via Spring Data JPA, including custom derived queries filtered by
deletedstatus.
📄 For a deeper dive into design decisions, data flow diagrams, and implementation rationale, see the Architecture & Implementation Document section below.
- Java 21+
- Maven 3.9+
- MySQL 8+ running locally
git clone https://github.com/<your-username>/SpringBootCRUDOperation.git
cd SpringBootCRUDOperationCREATE DATABASE student_crud_db;See the Configuration section below.
mvn clean install
mvn spring-boot:runThe application will start on http://localhost:8080 by default.
Update src/main/resources/application.properties with your local MySQL credentials:
spring.application.name=SpringBootCRUDOperation
spring.datasource.url=jdbc:mysql://localhost:3306/student_crud_db
spring.datasource.username=root
spring.datasource.password=your_password
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
⚠️ Note: For production, avoidddl-auto=updateand never commit real credentials. Use environment variables or a secrets manager instead.
Base URL: /api/students
| Method | Endpoint | Description | Success Status |
|---|---|---|---|
| POST | /create |
Create a new student | 201 Created |
| GET | /get?id={id} |
Get a single student by ID | 302 Found |
| GET | /getAll |
Get all active students | 302 Found |
| PUT | /update?id={id} |
Update an existing student | 302 Found |
| DELETE | /delete?id={id} |
Permanently delete a student | 200 OK |
| PATCH | /delete-soft?id={id} |
Soft-delete (flag) a student | 200 OK |
Request
POST /api/students/create
Content-Type: application/json
{
"name": "John Doe",
"email": "[email protected]",
"age": 21,
"rollNo": 101,
"subject": "Computer Science"
}Response 201 Created
{
"id": 1,
"name": "John Doe",
"email": "[email protected]",
"age": 21,
"rollNo": 101,
"subject": "Computer Science",
"deleted": false
}Request
GET /api/students/getAllResponse 302 Found
[
{
"id": 1,
"name": "John Doe",
"email": "[email protected]",
"age": 21,
"rollNo": 101,
"subject": "Computer Science",
"deleted": false
}
]Request
PATCH /api/students/delete-soft?id=1Response 200 OK
Record Deleted successfully
Detailed PDFs covering system design, data flow, request lifecycle, and implementation decisions:
📎 Simple CRUD Operations (PDF)
📎 Soft Delete Implementation (PDF)
- Add DTOs to decouple API contracts from JPA entities
- Add global exception handling (
@ControllerAdvice) - Add request validation (
@Valid, Bean Validation) - Add pagination and sorting to
getAllendpoint - Add Swagger/OpenAPI documentation
- Add unit and integration tests
- Externalize sensitive configuration via environment variables
This project is open-source and available under the MIT License.
Built with ☕ and Spring Boot