A modern Spring Boot 3.3.3 REST API application with PostgreSQL database support, Docker Compose integration, and comprehensive testing using Testcontainers.
- Spring Boot 3.3.3 with Java 21
- PostgreSQL database with Docker Compose support
- Testcontainers for integration testing
- JaCoCo test coverage reporting
- SonarCloud code quality analysis
- GitHub Actions CI/CD pipeline
- RESTful API for Topics and Courses management
- Java 21
- Spring Boot 3.3.3
- Spring Data JPA
- PostgreSQL 16
- Docker & Docker Compose
- Testcontainers
- JUnit 5
- Mockito
- JaCoCo (Test Coverage)
- Maven
- GitHub Actions
- Java 21
- Docker and Docker Compose
- Maven 3.6+
-
Clone the repository
git clone https://github.com/fayo-labs/spring-api-mysql.git cd spring-api-mysql
-
Start PostgreSQL with Docker Compose
docker-compose up -d
-
Run the application
mvn spring-boot:run
The application will start on http://localhost:8080
Run all tests:
mvn test
Run tests with coverage:
mvn clean test jacoco:report
View coverage report:
Open target/site/jacoco/index.html
in your browser
GET /topics
- Get all topicsGET /topics/{id}
- Get topic by IDPOST /topics
- Create new topicPUT /topics/{id}
- Update topicDELETE /topics/{id}
- Delete topic
GET /topics/{topicId}/courses
- Get courses for a topicGET /topics/{topicId}/courses/{id}
- Get specific coursePOST /topics/{topicId}/courses
- Create new coursePUT /topics/{topicId}/courses/{id}
- Update courseDELETE /topics/{topicId}/courses/{id}
- Delete course
Create a topic:
curl -X POST http://localhost:8080/topics \
-H "Content-Type: application/json" \
-d '{"name": "Spring Boot", "description": "Learn Spring Boot framework"}'
Get all topics:
curl http://localhost:8080/topics
The application uses PostgreSQL as the primary database. Configuration is handled through:
- Development: Docker Compose (
compose.yaml
) - Testing: Testcontainers with PostgreSQL
- Production: Environment variables
SPRING_DATASOURCE_URL
- Database URLSPRING_DATASOURCE_USERNAME
- Database usernameSPRING_DATASOURCE_PASSWORD
- Database password
- Service layer testing with Mockito
- Repository layer testing with
@DataJpaTest
- Full application context testing with Testcontainers
- Controller testing with MockMvc
- Database integration testing
- Minimum coverage threshold: 50%
- JaCoCo reports generated automatically
- Coverage uploaded to Codecov and SonarCloud
The project uses GitHub Actions for:
- Build and Test: Compile code and run all tests
- Test Coverage: Generate and upload coverage reports
- Code Quality: SonarCloud analysis
- Docker Support: PostgreSQL service for testing
# Start PostgreSQL
docker-compose up -d postgres
# Stop services
docker-compose down
# Build application
mvn clean package
# Run with Docker Compose
docker-compose up --build
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- SonarCloud: Automated code quality analysis
- Spotless: Code formatting with Google Java Format
- JaCoCo: Test coverage reporting
- GitHub Actions: Automated CI/CD pipeline
This project is licensed under the MIT License - see the LICENSE file for details.
- Spring Boot team for the excellent framework
- Testcontainers for making integration testing easier
- PostgreSQL for the robust database system