A modular Java backend platform for managing books, authors, and user authentication, built with Spring Boot, gRPC, and PostgreSQL. The project demonstrates modern backend practices, clean architecture, and microservice design.
Note
This repository is under active development. Some features may be incomplete or subject to change.
- Tech Stack
- Features
- Getting Started
- API Documentation
- Project Structure
- Design & Architecture
- License
- Java 21+
- Spring Boot 3.4.x
- Maven
- gRPC (with protobuf)
- PostgreSQL (main DB)
- H2 (for testing)
- Redis (for caching, via Spring Data Redis)
- OpenAPI/Swagger (API docs)
- JUnit 5, Hamcrest, Mockito, MockMVC (testing)
- Docker & Docker Compose (for local development)
- Modular multi-service architecture (auth, business, shared)
- gRPC-based internal communication
- RESTful APIs for external clients
- JWT-based authentication and session management
- Role-based access control following RBAC principles::
- Viewer/Unauthenticated: Can access public resources (read-only)
- Contributor: Can add new resources
- Editor: Can add, update, and delete resources
- Admin: Can manage permissions by promoting or demoting users
- CRUD for books and authors with advanced querying (pagination, filtering, nested sorting)
- Input validation and global exception handling
- Request/response logging and auditing
- Caching (in-memory and Redis)
- Comprehensive API documentation (Swagger UI)
- Containerized development and test environments
- Unit and integration tests
- Java 21 or higher
- Maven 4.0.0 or higher
- Docker & Docker Compose
mvn clean installEach service can be run independently. For local development, ensure Docker is running for PostgreSQL/Redis.
cd auth-service
mvn spring-boot:runcd business-service
mvn spring-boot:runTo complete setting up the admin role in the database, run the following script:
chmod +x update_admin_role.sh
APP_ADMIN_USERNAME=admin ./update_admin_role.shEach service has its own compose.yaml for DB dependencies.
- REST API: Available at
http://localhost:8081/swagger-ui(auth-service) andhttp://localhost:8082/swagger-ui( business-service) - gRPC API: See proto files in
grpc-shared/src/main/proto
books-api-repo/
βββ auth-service/ # Authentication microservice (gRPC client + REST)
βββ business-service/ # Business logic microservice (gRPC server + REST)
βββ grpc-shared/ # Shared gRPC proto definitions and generated code
βββ ...
- Each service is a standalone Spring Boot app with its own dependencies and configuration.
grpc-sharedis imported as a dependency in both services for gRPC contract sharing.
src/main/java/com/y/x/
βββ XApplication.java # Application entry point
βββ common/ # Shared utilities and base components
βββ domain/ # Feature domains (book, author, etc.)
βββ infrastructure/ # Cross-cutting concerns
domain/x/
βββ controller/ # REST API endpoints and API annotations
β βββ XApi.java # Interface defining the API specification
β βββ XController.java # Implementation of API specification
βββ model/ # Domain models
β βββ dto/ # Data Transfer Objects
β βββ entity/ # JPA entities
β βββ mapper/ # Object mappers
βββ repository/ # Data access layer
βββ service/ # Business logic
βββ facade/ # Exposes internal services to other local services
βββ gateway/ # Enable external local services for internal consumption
- While business-service is structured feature-wise then technical, auth-service is structured first by technical layer,
e.g.,
core/controllers/XController.java. This decision is made according to the service's complexity and requirements.
The system consists of the following main services:
- auth-service: Handles authentication, JWT issuance, and user credentials.
- business-service: Manages domain logic, books/authors/userProfiles CRUD, and authorization.
Services communicate internally using gRPC and expose REST API for clients.
- Separation of Concerns and Minimal Dependencies: Services whether local or global should have minimal coupling. Any interaction` between services is done through well-defined interfaces.
- gRPC for Internal APIs: Fast, strongly typed communication between services.
- REST for External APIs: Standard HTTP/JSON for client interaction.
- JWT Auth: Stateless authentication, where issuance and refreshing is done by the auth service, while validating access tokens is in the consumer service.
- Role-based Access Control: Different permissions for users.
- Clean Architecture: Feature-based package structure, clear layering (controller, service, repository, etc).
This project is licensed under the MIT License - see the LICENSE file for details.