A modern Spring Boot application built with Kotlin, featuring a responsive web interface and REST API endpoints.
- Modern Tech Stack: Spring Boot 3.5.3, Kotlin 2.2.10, Java 21 LTS
- Responsive UI: Bootstrap 5.3.3 with modern design
- REST API: JSON endpoints with timestamp support
- Health Monitoring: Spring Boot Actuator for application health
- Live Development: Spring Boot DevTools for automatic reload
- Interactive HTTP Debugging: Client-side HTTP request/response visualization
- Containerization: Docker support with multi-stage builds
- Comprehensive Testing: Unit, integration, and MVC tests
- Modern Kotlin: Constructor injection, data classes, and modern syntax
- Time-based Greeting: Personalized greeting changes depending on the time of day (Good Morning, Good Afternoon, Good Evening)
- Structured Logging: Enhanced logging with structured (JSON) logs for better analysis and aggregation
- API Caching: Frequently accessed API responses are cached for improved performance
- Backend: Spring Boot 3.5.3
- Language: Kotlin 2.2.10
- Java Version: 21 LTS
- Frontend: Bootstrap 5.3.3, Thymeleaf
- Build Tool: Gradle 9.0.0
- Testing: JUnit 5, AssertJ, MockMvc
- Containerization: Docker
- Logging: Logback, Logstash Logback Encoder (JSON logs), SLF4J
- Java 21 or higher
- Gradle 9.0.0 or higher
- Docker (optional)
-
Clone the repository
git clone <repository-url> cd template-lab1-git-race
-
Build the application
./gradlew build
-
Run the application
./gradlew bootRun
-
Access the application
- Web Interface: http://localhost:8080
- API Endpoint: http://localhost:8080/api/hello
- Health Check: http://localhost:8080/actuator/health
-
Using Docker Compose (Recommended):
docker-compose -f docker-compose.dev.yml up --build
-
Build and run development container:
docker build -f Dockerfile.dev -t modern-web-app-dev . docker run -p 8080:8080 -p 35729:35729 -v $(pwd):/app modern-web-app-dev
The development Docker setup includes:
- LiveReload Support: Automatic browser refresh on code changes
- Volume Mounting: Source code changes are immediately reflected
- Spring Boot DevTools: Automatic application restart on file changes
- Health Monitoring: Built-in health checks via Spring Boot Actuator
Run all tests:
./gradlew testRun specific test classes:
./gradlew test --tests "HelloControllerUnitTests"
./gradlew test --tests "IntegrationTest"
./gradlew test --tests "HelloControllerCacheTest"GET /- Main web page with interactive HTTP debugging toolsGET /?name={name}- Personalized greeting page (greeting changes based on time of day)
GET /api/hello- Returns JSON greeting with timestampGET /api/hello?name={name}- Returns personalized JSON greeting (time-based: morning, afternoon, evening) Note: Responses are cached per name parameter for faster repeated access.
GET /actuator/health- Application health statusGET /actuator/info- Application informationGET /actuator/metrics- Application metrics
- Web Page Testing: Test the main page with personalized greetings
- API Testing: Test REST endpoints with real-time request/response display
- Health Check Testing: Monitor application health status
- Live Reload: Spring Boot DevTools automatically reloads on file changes
src/
βββ main/
β βββ kotlin/
β β βββ controller/
β β β βββ HelloController.kt # Web and API controllers
β β βββ HelloWorld.kt # Main application class
β βββ resources/
β βββ logback-spring.xml
β βββ application.properties # Application configuration
β βββ templates/
β β βββ welcome.html # Thymeleaf template
β βββ public/
β βββ assets/
β βββ logo.svg # Application logo
βββ test/
βββ kotlin/
βββ controller/
β βββ HelloControllerUnitTests.kt # Unit tests
β βββ HelloControllerMVCTests.kt # MVC tests
β βββ HelloControllerCacheTest.kt # Cache tests
β βββ HelloControllerLogTests.kt # Log tests
βββ IntegrationTest.kt # Integration tests
Key configuration options in application.properties:
# Application settings
spring.application.name=modern-web-app
server.port=8080
# Custom message
app.message=Welcome to the Modern Web App!
# Actuator endpoints
management.endpoints.web.exposure.include=health,info,metricsThe application includes a development-focused Docker setup:
- Development Dockerfile: Uses JDK 21 Alpine for development with live reload
- Docker Compose: Orchestrates the development environment with volume mounting
- LiveReload: Spring Boot DevTools automatically reloads on file changes
- Volume Mounting: Source code changes are immediately reflected in the container
- Health Checks: Built-in health monitoring via Spring Boot Actuator
- Development Tools: Includes wget for health checks and debugging utilities
- Controllers: Add new endpoints in the controller package
- Templates: Add new Thymeleaf templates in
src/main/resources/templates/ - Tests: Add corresponding tests in the test package
- Configuration: Update
application.propertiesfor new settings
- Use modern Kotlin features (constructor injection, data classes)
- Follow Spring Boot best practices
- Write comprehensive tests for all functionality
- Use descriptive test method names with backticks
The application includes Spring Boot Actuator for monitoring:
- Health: Application and dependency health status
- Info: Application metadata and build information
- Metrics: JVM and application metrics
- Structured Logging: All controller actions are logged in structured JSON format using Logback and Logstash Logback Encoder.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- β Upgraded to Java 21 LTS for better performance
- β Modern Kotlin syntax with constructor injection
- β Separated web and API controllers for better organization
- β Added comprehensive test coverage
- β Implemented Spring Boot Actuator for monitoring
- β Created responsive Bootstrap 5.3.3 UI
- β Added Docker support with multi-stage builds
- β Fixed Bootstrap version inconsistencies
- β Enhanced error handling and validation
- β Added interactive features and API endpoints
Structured logs are written to logs/app-log.json in JSON format.
You can aggregate and visualize these logs using:
- ELK Stack: Configure Logstash to read the log file and send data to Elasticsearch, then visualize in Kibana.
- Grafana Loki: Use Promtail to scrape the log file and view logs in Grafana dashboards.
The application uses Spring Boot's caching abstraction to improve performance for frequently accessed data.
- API Caching: The
/api/helloendpoint is cached using the@Cacheableannotation. When the same name parameter is requested multiple times, the response is served from the cache instead of being recomputed. - Cache Provider: By default, the application uses an in-memory cache (
ConcurrentMapCache). It's possible to configure other providers (like Redis) if you want to manage large amounts of data.