A Spring Boot application for managing library operations including books, users, and borrowing records.
- Java 17
- Spring Boot 2.5.4
- Spring Data JPA
- Spring Security
- PostgreSQL
- Maven
- JUnit & Mockito
Controllers (src/main/java/com/avan/libraryapp1/controller/
)
BookController
- Book CRUD operations and borrowingUserController
- User managementBorrowRecordController
- Borrowing history tracking
Services (src/main/java/com/avan/libraryapp1/services/
)
BookService
- Business logic for book operationsUserService
- User management logicBorrowRecordService
- Borrowing workflow management
Models (src/main/java/com/avan/libraryapp1/model/
)
Book
- Book entity with validationUser
- User entity with role-based accessBorrowRecord
- Borrowing transaction records
Repositories (src/main/java/com/avan/libraryapp1/repository/
)
- Spring Data JPA repositories for data persistence
Security (src/main/java/com/avan/libraryapp1/security/
)
- Authentication and authorization configuration
- Custom user details service
DTOs (src/main/java/com/avan/libraryapp1/dto/
)
- Data transfer objects with validation
Exception Handling (src/main/java/com/avan/libraryapp1/exceptions/
)
- Global exception handler with custom exceptions
- Complete CRUD operations for books and users
- Book borrowing and return system
- Role-based security authentication
- RESTful API endpoints
- Input validation and error handling
- PostgreSQL database integration
GET /api/books
- List all booksGET /api/books/{id}
- Get book by IDPOST /api/books
- Create new bookPUT /api/books/{id}
- Update bookDELETE /api/books/{id}
- Delete bookPOST /api/books/{bookId}/borrow/{userId}
- Borrow bookPOST /api/books/{bookId}/return
- Return book
GET /api/users
- List all usersGET /api/users/{id}
- Get user by IDPOST /api/users
- Create new userPUT /api/users/{id}
- Update userDELETE /api/users/{id}
- Delete user
GET /api/borrow-records
- List all borrow recordsGET /api/borrow-records/{id}
- Get borrow record by IDPOST /api/borrow-records
- Create borrow recordPUT /api/borrow-records/{id}
- Update borrow recordDELETE /api/borrow-records/{id}
- Delete borrow record
The project includes comprehensive unit tests using JUnit and Mockito.
Test Structure:
- Unit tests:
src/test/java/com/avan/libraryapp1/unittests/
- Integration tests:
src/test/java/com/avan/libraryapp1/integrationtests/
Run tests:
mvn test
Current test coverage includes:
- BookService unit tests with mocking
- Application context loading tests
- Exception handling validation
- Java 17 or higher
- Maven 3.6+
- PostgreSQL 12+
Update src/main/resources/application.yml
:
spring:
datasource:
url: jdbc:postgresql://localhost:5432/LibraryManagement
username: your_username
password: your_password
# Clone repository
git clone [repository-url]
# Build application
mvn clean install
# Run application
mvn spring-boot:run
The application will start on http://localhost:8080
- Form-based authentication
- BCrypt password encoding
- Role-based access control
- Session management with CSRF protection
I've deliberately chosen trunk-based development over TDD for this project. While I respect TDD's place in enterprise environments and have extensive experience with it, I find compiler-driven development more efficient for rapid iteration. My preference is trunk-based workflow with rigorous code reviews as quality gates rather than extensive upfront test coverage. This approach delivers working software faster while maintaining quality through systematic review processes. I adapt to team methodologies as needed, but this represents my preferred development philosophy.
The application uses JPA with automatic DDL generation. Tables are created automatically on startup:
books
- Book information and availabilityusers
- User accounts and rolesborrow_record
- Borrowing transaction history