Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Spring Boot Interview Scaffold

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.

🚀 Features

  • 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

🏗️ Project Structure

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

🛠️ Tech Stack

  • 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)

🚀 Quick Start

Prerequisites

  • Java 17 or higher
  • Maven 3.6 or higher

Running the Application

  1. Clone and navigate to the project:

    cd /Users/shaileshpant/src/java-sb
  2. Build the project:

    mvn clean install
  3. Run the application:

    mvn spring-boot:run
  4. Access the application:

Running Tests

# Run all tests
mvn test

# Run specific test class
mvn test -Dtest=UserControllerTest

# Run with coverage
mvn test jacoco:report

📚 API Endpoints

Health Check

  • GET /api/health - Application health status
  • GET /api/health/ready - Readiness check

Users API

  • POST /api/users - Create a new user
  • GET /api/users - Get all users
  • GET /api/users/{id} - Get user by ID
  • GET /api/users/search?name={name} - Search users by name
  • GET /api/users/username/{username} - Get user by username
  • GET /api/users/created-between?startDate={date}&endDate={date} - Get users created between dates
  • PUT /api/users/{id} - Update user
  • DELETE /api/users/{id} - Delete user

Products API

  • POST /api/products - Create a new product
  • GET /api/products - Get all products
  • GET /api/products/{id} - Get product by ID
  • GET /api/products/search/name?name={name} - Search products by name
  • GET /api/products/search/keyword?keyword={keyword} - Search products by keyword
  • GET /api/products/price-range?minPrice={price}&maxPrice={price} - Get products by price range
  • GET /api/products/affordable?maxPrice={price} - Get affordable products
  • GET /api/products/in-stock?minQuantity={qty} - Get products in stock
  • GET /api/products/out-of-stock-count - Get count of out-of-stock products
  • PUT /api/products/{id} - Update product
  • PATCH /api/products/{id}/stock?stockQuantity={qty} - Update product stock
  • DELETE /api/products/{id} - Delete product

🧪 Sample API Usage

Create a User

curl -X POST http://localhost:8080/api/users \
  -H "Content-Type: application/json" \
  -d '{
    "username": "johndoe",
    "email": "john@example.com",
    "firstName": "John",
    "lastName": "Doe"
  }'

Create a Product

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
  }'

Search Products

curl "http://localhost:8080/api/products/search/keyword?keyword=laptop"

🏛️ Architecture Patterns Demonstrated

  1. Layered Architecture: Controller → Service → Repository
  2. DTO Pattern: Data Transfer Objects for API communication
  3. Mapper Pattern: MapStruct for entity-DTO mapping
  4. Repository Pattern: JPA repositories for data access
  5. Exception Handling: Global exception handler with custom exceptions
  6. Validation: Bean Validation for input validation
  7. Transaction Management: @Transactional annotations
  8. Testing: Unit tests with Mockito and integration tests with MockMvc

🎯 Interview-Ready Features

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

🔧 Customization

This scaffold is designed to be easily customizable for different interview scenarios:

  1. Add new entities in the entity package
  2. Create corresponding DTOs in the dto package
  3. Add repositories in the repository package
  4. Implement services in the service package
  5. Create controllers in the controller package
  6. Add tests in the test package

📝 Notes for Interviews

  • 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

🤝 Contributing

This is a scaffold project for interview purposes. Feel free to modify and extend it based on your specific interview requirements.

📄 License

This project is open source and available under the MIT License.

About

A comprehensive Spring Boot scaffolding project designed for coding interviews with RESTful APIs, JPA, testing, and enterprise patterns

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages