-
Notifications
You must be signed in to change notification settings - Fork 5
docs: modernize README with comprehensive documentation #230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,59 +1,218 @@ | ||
| # 🧪 RESTful Web Service with Spring Boot | ||
|
|
||
| ## Status | ||
| # 🧪 RESTful API with Java and Spring Boot | ||
|
|
||
| [](https://github.com/nanotaboada/java.samples.spring.boot/actions/workflows/maven.yml) | ||
| [](https://sonarcloud.io/summary/new_code?id=nanotaboada_java.samples.spring.boot) | ||
| [](https://app.codacy.com/gh/nanotaboada/java.samples.spring.boot/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) | ||
| [](https://codecov.io/gh/nanotaboada/java.samples.spring.boot) | ||
| [](https://www.codefactor.io/repository/github/nanotaboada/java.samples.spring.boot) | ||
| [](https://opensource.org/licenses/MIT) | ||
|
|
||
| > A production-ready RESTful Web Service demonstrating clean architecture patterns with Spring Boot 3, comprehensive testing, and containerized deployment. | ||
| ## Table of Contents | ||
|
|
||
| - [About](#about) | ||
| - [Features](#features) | ||
| - [Architecture](#architecture) | ||
| - [Prerequisites](#prerequisites) | ||
| - [Getting Started](#getting-started) | ||
| - [Local Development](#local-development) | ||
| - [Docker Deployment](#docker-deployment) | ||
| - [API Reference](#api-reference) | ||
| - [Testing](#testing) | ||
| - [Documentation](#documentation) | ||
| - [Contributing](#contributing) | ||
| - [License](#license) | ||
|
|
||
| ## About | ||
|
|
||
| Proof of Concept for a RESTful Web Service made with [Spring Boot 3](https://spring.io/blog/2024/02/22/spring-boot-3-2-3-available-now) targeting [JDK 21](https://openjdk.org/projects/jdk/21/) | ||
| A proof-of-concept RESTful Web Service built with **Spring Boot 3** targeting **JDK 21 (LTS)**. This project demonstrates best practices for building a layered, testable, and maintainable API implementing CRUD operations for a Books resource. | ||
|
|
||
| The service showcases: | ||
|
|
||
| - Multi-layer architecture (Controllers → Services → Repositories) | ||
| - In-memory H2 database with JPA/Hibernate | ||
| - Spring Cache abstraction for performance optimization | ||
| - Comprehensive test coverage with JUnit 5, Mockito, and AssertJ | ||
| - OpenAPI 3.0 documentation with Swagger UI | ||
| - Production-ready monitoring with Spring Boot Actuator | ||
| - Containerized deployment with Docker | ||
|
|
||
| ## Features | ||
|
|
||
| ## Structure | ||
| - ✅ **RESTful API** - Full CRUD operations for Books resource | ||
| - ✅ **Clean Architecture** - Layered design with clear separation of concerns | ||
| - ✅ **Validation** - Jakarta Bean Validation with custom constraints (ISBN, URL) | ||
| - ✅ **Caching** - Spring Cache with `@Cacheable`, `@CachePut`, `@CacheEvict` | ||
| - ✅ **API Documentation** - Interactive Swagger UI powered by SpringDoc OpenAPI | ||
| - ✅ **Health Monitoring** - Spring Boot Actuator endpoints | ||
| - ✅ **Test Coverage** - JaCoCo reports with Codecov/Codacy integration | ||
| - ✅ **Docker Support** - Multi-stage builds with Eclipse Temurin Alpine images | ||
| - ✅ **CI/CD Ready** - GitHub Actions and Azure Pipelines configurations | ||
|
|
||
| ## Architecture | ||
|
|
||
|  | ||
|
|
||
| _Figure: Simplified, conceptual project structure and main application flow. Not all dependencies are shown._ | ||
|
|
||
| ## Documentation | ||
| **Layer Responsibilities:** | ||
|
|
||
| - **Controller** (Green) - HTTP request handling, DTO validation, OpenAPI annotations | ||
| - **Service** (Yellow) - Business logic, caching, Entity-DTO mapping | ||
| - **Repository** (Red) - Data access via Spring Data JPA | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| Before you begin, ensure you have the following installed: | ||
|
|
||
| - **Java Development Kit (JDK) 21** - [Download](https://adoptium.net/temurin/releases/?version=21) | ||
| - ⚠️ **Critical**: JDK 21 is required. Newer versions (22+) cause Mockito/ByteBuddy compatibility issues. | ||
| - Verify with: `java -version` | ||
| - **Maven 3.9+** (optional) - Project includes Maven wrapper (`./mvnw`) | ||
| - **Docker** (optional) - For containerized deployment | ||
|
|
||
| **macOS Users**: Set `JAVA_HOME` if needed: | ||
|
|
||
| ```console | ||
| http://localhost:9000/swagger/index.html | ||
| ```bash | ||
| export JAVA_HOME=$(/usr/libexec/java_home -v 21) | ||
| ``` | ||
|
|
||
|  | ||
| ## Getting Started | ||
|
|
||
| ### Local Development | ||
|
|
||
| 1. **Clone the repository** | ||
|
|
||
| ```bash | ||
| git clone https://github.com/nanotaboada/java.samples.spring.boot.git | ||
| cd java.samples.spring.boot | ||
| ``` | ||
|
|
||
| 2. **Build the project** | ||
|
|
||
| ```bash | ||
| ./mvnw clean package | ||
| ``` | ||
|
|
||
| ## Container | ||
| 3. **Run the application** | ||
|
|
||
| ### Docker Compose | ||
| ```bash | ||
| ./mvnw spring-boot:run | ||
| ``` | ||
|
|
||
| This setup uses [Docker Compose](https://docs.docker.com/compose/) to build and run the app | ||
| 4. **Verify it's running** | ||
| - API Server: `http://localhost:9000` | ||
| - Health Check: `http://localhost:9001/actuator/health` | ||
| - Swagger UI: `http://localhost:9000/swagger/index.html` | ||
|
|
||
| #### Build the image | ||
| ### Docker Deployment | ||
|
|
||
| **Quick Start:** | ||
|
|
||
| ```bash | ||
| docker compose build | ||
| docker compose up | ||
| ``` | ||
|
|
||
| #### Start the app | ||
| **Detached Mode:** | ||
|
|
||
| ```bash | ||
| docker compose up | ||
| docker compose up -d | ||
| ``` | ||
|
|
||
| #### Stop the app | ||
| **Stop Containers:** | ||
|
|
||
| ```bash | ||
| docker compose down | ||
| ``` | ||
|
|
||
| ## Credits | ||
| **Exposed Ports:** | ||
|
|
||
| - `9000` - Main API server | ||
| - `9001` - Actuator management endpoints | ||
|
|
||
| ## API Reference | ||
|
|
||
| The Books API provides standard CRUD operations: | ||
|
|
||
| | Method | Endpoint | Description | Request Body | Response | | ||
| |--------|----------|-------------|--------------|----------| | ||
| | `GET` | `/books` | Retrieve all books | - | `200 OK` with `BookDTO[]` | | ||
| | `GET` | `/books/{isbn}` | Retrieve book by ISBN | - | `200 OK` with `BookDTO` or `404 Not Found` | | ||
| | `POST` | `/books` | Create a new book | `BookDTO` | `201 Created` with `BookDTO` | | ||
| | `PUT` | `/books/{isbn}` | Update existing book | `BookDTO` | `200 OK` with `BookDTO` or `404 Not Found` | | ||
| | `DELETE` | `/books/{isbn}` | Delete book by ISBN | - | `204 No Content` or `404 Not Found` | | ||
|
|
||
| **BookDTO Schema:** | ||
|
|
||
| ```json | ||
| { | ||
| "isbn": "978-0-596-52068-7", | ||
| "title": "RESTful Web Services", | ||
| "author": "Leonard Richardson, Sam Ruby", | ||
| "published": "2007-05-08", | ||
| "publisher": "O'Reilly Media", | ||
| "pages": 448, | ||
| "description": "An in-depth guide to building web services...", | ||
| "website": "https://example.com" | ||
| } | ||
| ``` | ||
|
|
||
| For complete API documentation with request/response examples, visit the **Swagger UI** at: | ||
|
|
||
| `http://localhost:9000/swagger/index.html` | ||
|
|
||
|  | ||
|
|
||
| ## Testing | ||
|
|
||
| Run the full test suite with coverage: | ||
|
|
||
| ```bash | ||
| ./mvnw verify | ||
| ``` | ||
|
|
||
| **View Coverage Report:** | ||
|
|
||
| ```bash | ||
| open target/site/jacoco/index.html | ||
| ``` | ||
|
|
||
| **Test Structure:** | ||
|
|
||
| - **Unit Tests** - `@WebMvcTest`, `@DataJpaTest` for isolated layer testing | ||
| - **Mocking** - Mockito for dependency mocking | ||
| - **Assertions** - AssertJ fluent assertions | ||
| - **Naming Convention** - BDD style: `given<Condition>_when<Action>_then<Expected>` | ||
|
|
||
| **Coverage Targets:** | ||
|
|
||
| - Controllers: 100% | ||
| - Services: 100% | ||
| - Repositories: Custom query methods (interfaces excluded by JaCoCo design) | ||
|
|
||
| ## Documentation | ||
|
|
||
| - **API Documentation**: Swagger UI at `http://localhost:9000/swagger/index.html` | ||
| - **OpenAPI Spec**: Available at `http://localhost:9000/v3/api-docs` | ||
| - **Actuator Endpoints**: `http://localhost:9001/actuator` | ||
| - **Agent Onboarding**: See `.github/copilot-instructions.md` for development guidelines | ||
|
|
||
| ## Contributing | ||
|
|
||
| Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for: | ||
|
|
||
| - Code of Conduct | ||
| - Development workflow | ||
| - Commit message conventions | ||
| - Pull request process | ||
|
|
||
| ## License | ||
|
|
||
| This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. | ||
|
|
||
| The solution has been coded using [Visual Studio Code](https://code.visualstudio.com/) with the [Extension Pack for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack) | ||
| ## Acknowledgments | ||
|
|
||
| ## Terms | ||
| This solution has been developed using [Visual Studio Code](https://code.visualstudio.com/). | ||
|
|
||
| All trademarks, registered trademarks, service marks, product names, company names, or logos mentioned on this repository are the property of their respective owners. All usage of such terms herein is for identification purposes only and constitutes neither an endorsement nor a recommendation of those items. Furthermore, the use of such terms is intended to be for educational and informational purposes only. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Verify referenced files exist in the repository.
The README references external files that must be present for the documentation to be complete:
.github/copilot-instructions.md(line 199)CONTRIBUTING.md(line 203)assets/images/structure.svg(line 55)assets/images/swagger.png(line 165)Run the following script to verify these files are present in the repository:
Also verify that
docker-compose.ymlexists to support the Docker Deployment instructions (lines 109-127).Also applies to: 203-203
🏁 Script executed:
Length of output: 200
🏁 Script executed:
Length of output: 179
docker-compose.yml is missing and required to support documented Docker Deployment instructions.
The README's Docker Deployment section (lines 109–127) provides commands like
docker compose upthat expect adocker-compose.ymlfile to exist in the repository root. Without it, users following the documentation will encounter failures. The file must be created to make the Docker Deployment instructions functional.All other referenced files (
.github/copilot-instructions.md,CONTRIBUTING.md,assets/images/structure.svg,assets/images/swagger.png) are present and valid.🧰 Tools
🪛 LanguageTool
[uncategorized] ~199-~199: The official name of this software platform is spelled with a capital “H”.
Context: ...1/actuator
- **Agent Onboarding**: See.github/copilot-instructions.md` for developmen...(GITHUB)
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file already exists:
compose.yaml
More info: https://docs.docker.com/compose/intro/compose-application-model/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Length of output: 356
@nanotaboada, you're absolutely right, and I apologize for the oversight!
The
compose.yamlfile does exist in the repository, and it's the modern, recommended naming convention for Docker Compose files. Bothcompose.yamlanddocker-compose.ymlare valid, but Docker's documentation now favorscompose.yaml.I've verified the file, and it correctly defines the service with ports 9000 and 9001 as documented in your README. The Docker Deployment instructions are fully supported. Thank you for the clarification and the helpful link!
✏️ Learnings added
🧠 Learnings used