A comprehensive Spring Boot scaffolding project designed for coding interviews. This project demonstrates common patterns, best practices, and architectural components typically used in enterprise Java applications.
- RESTful API with comprehensive CRUD operations
- JPA/Hibernate for data persistence
- H2 Database for easy setup and testing
- Validation with Bean Validation annotations
- Exception Handling with global exception handler
- DTOs and Mappers using MapStruct
- Unit Tests with JUnit 5 and Mockito
- Integration Tests with MockMvc
- Lombok for reducing boilerplate code
- Logging with SLF4J
src/
├── main/
│ ├── java/com/example/interviewscaffold/
│ │ ├── controller/ # REST Controllers
│ │ ├── dto/ # Data Transfer Objects
│ │ ├── entity/ # JPA Entities
│ │ ├── exception/ # Custom Exceptions & Global Handler
│ │ ├── mapper/ # MapStruct Mappers
│ │ ├── repository/ # JPA Repositories
│ │ ├── service/ # Business Logic Services
│ │ └── InterviewScaffoldApplication.java
│ └── resources/
│ └── application.yml # Application Configuration
└── test/
├── java/com/example/interviewscaffold/
│ ├── controller/ # Controller Tests
│ └── service/ # Service Tests
└── resources/
└── application-test.yml # Test Configuration
- Java 17
- Spring Boot 3.2.0
- Spring Data JPA
- H2 Database
- MapStruct (for object mapping)
- Lombok (for reducing boilerplate)
- JUnit 5 (for testing)
- Mockito (for mocking)
- Maven (for dependency management)
- Java 17 or higher
- Maven 3.6 or higher
-
Clone and navigate to the project:
cd /Users/shaileshpant/src/java-sb -
Build the project:
mvn clean install
-
Run the application:
mvn spring-boot:run
-
Access the application:
- Application: http://localhost:8080
- H2 Console: http://localhost:8080/h2-console
- JDBC URL:
jdbc:h2:mem:testdb - Username:
sa - Password:
password
- JDBC URL:
# Run all tests
mvn test
# Run specific test class
mvn test -Dtest=UserControllerTest
# Run with coverage
mvn test jacoco:reportGET /api/health- Application health statusGET /api/health/ready- Readiness check
POST /api/users- Create a new userGET /api/users- Get all usersGET /api/users/{id}- Get user by IDGET /api/users/search?name={name}- Search users by nameGET /api/users/username/{username}- Get user by usernameGET /api/users/created-between?startDate={date}&endDate={date}- Get users created between datesPUT /api/users/{id}- Update userDELETE /api/users/{id}- Delete user
POST /api/products- Create a new productGET /api/products- Get all productsGET /api/products/{id}- Get product by IDGET /api/products/search/name?name={name}- Search products by nameGET /api/products/search/keyword?keyword={keyword}- Search products by keywordGET /api/products/price-range?minPrice={price}&maxPrice={price}- Get products by price rangeGET /api/products/affordable?maxPrice={price}- Get affordable productsGET /api/products/in-stock?minQuantity={qty}- Get products in stockGET /api/products/out-of-stock-count- Get count of out-of-stock productsPUT /api/products/{id}- Update productPATCH /api/products/{id}/stock?stockQuantity={qty}- Update product stockDELETE /api/products/{id}- Delete product
curl -X POST http://localhost:8080/api/users \
-H "Content-Type: application/json" \
-d '{
"username": "johndoe",
"email": "john@example.com",
"firstName": "John",
"lastName": "Doe"
}'curl -X POST http://localhost:8080/api/products \
-H "Content-Type: application/json" \
-d '{
"name": "Laptop",
"description": "High-performance laptop",
"price": 999.99,
"stockQuantity": 10
}'curl "http://localhost:8080/api/products/search/keyword?keyword=laptop"- Layered Architecture: Controller → Service → Repository
- DTO Pattern: Data Transfer Objects for API communication
- Mapper Pattern: MapStruct for entity-DTO mapping
- Repository Pattern: JPA repositories for data access
- Exception Handling: Global exception handler with custom exceptions
- Validation: Bean Validation for input validation
- Transaction Management: @Transactional annotations
- Testing: Unit tests with Mockito and integration tests with MockMvc
This scaffold includes common patterns and features often asked about in interviews:
- CRUD Operations with proper HTTP status codes
- Input Validation with meaningful error messages
- Exception Handling with custom exceptions
- Database Queries with JPA and custom queries
- Service Layer with business logic
- Testing with comprehensive test coverage
- API Documentation through well-structured endpoints
- Logging for debugging and monitoring
- Configuration with YAML properties
This scaffold is designed to be easily customizable for different interview scenarios:
- Add new entities in the
entitypackage - Create corresponding DTOs in the
dtopackage - Add repositories in the
repositorypackage - Implement services in the
servicepackage - Create controllers in the
controllerpackage - Add tests in the
testpackage
- The project follows Spring Boot best practices
- All code is production-ready with proper error handling
- Comprehensive test coverage demonstrates testing skills
- Clean architecture makes it easy to extend and modify
- Well-documented API endpoints show API design skills
- Proper use of annotations and Spring features
This is a scaffold project for interview purposes. Feel free to modify and extend it based on your specific interview requirements.
This project is open source and available under the MIT License.