{"id":48631812,"url":"https://github.com/olx-india/java-service-template-clean-architecture","last_synced_at":"2026-04-09T05:32:47.340Z","repository":{"id":283649382,"uuid":"952455078","full_name":"olx-india/java-service-template-clean-architecture","owner":"olx-india","description":"Boilerplate project for Java Spring Boot Based on Clean Code Architecture","archived":false,"fork":false,"pushed_at":"2026-03-03T05:49:56.000Z","size":266,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-03T09:27:32.835Z","etag":null,"topics":["backend-service","clean-architecture","clean-code","domain-driven-design","java","java-21","microservice","springboot","template"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/olx-india.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-03-21T10:00:20.000Z","updated_at":"2026-03-03T05:47:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"0343bff8-fd43-4444-86e0-ff6095545dc9","html_url":"https://github.com/olx-india/java-service-template-clean-architecture","commit_stats":null,"previous_names":["olx-india/java-service-template-clean-architecture"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/olx-india/java-service-template-clean-architecture","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olx-india%2Fjava-service-template-clean-architecture","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olx-india%2Fjava-service-template-clean-architecture/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olx-india%2Fjava-service-template-clean-architecture/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olx-india%2Fjava-service-template-clean-architecture/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/olx-india","download_url":"https://codeload.github.com/olx-india/java-service-template-clean-architecture/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olx-india%2Fjava-service-template-clean-architecture/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31587852,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"online","status_checked_at":"2026-04-09T02:00:06.848Z","response_time":112,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backend-service","clean-architecture","clean-code","domain-driven-design","java","java-21","microservice","springboot","template"],"created_at":"2026-04-09T05:32:45.675Z","updated_at":"2026-04-09T05:32:47.328Z","avatar_url":"https://github.com/olx-india.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Java Service Template — Clean Architecture\n\nA production-ready **Spring Boot** template for building Java microservices using **Clean Architecture**. Use it to bootstrap new services with multi-tenancy, Redis caching, Kafka, database migrations, and observability built in.\n\n[![Java 21](https://img.shields.io/badge/Java-21-ED8B00?logo=openjdk)](https://docs.oracle.com/en/java/javase/21/)\n[![Spring Boot 3.1](https://img.shields.io/badge/Spring%20Boot-3.1-6DB33F?logo=spring)](https://spring.io/projects/spring-boot)\n[![Maven](https://img.shields.io/badge/Maven-3.6+-C71A36?logo=apachemaven)](https://maven.apache.org/)\n[![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\n---\n\n## Features\n\n- **Clean Architecture** — Layered design with clear separation: controllers, use cases, domain, and infrastructure\n- **Multi-tenant MySQL** — Database-per-tenant support with configurable data sources\n- **Redis** — Caching and session storage\n- **Kafka** — Event producer integration\n- **Flyway** — Versioned database migrations\n- **OpenAPI / Swagger** — Auto-generated API docs (SpringDoc)\n- **Resilience** — Retry, circuit breaker, and rate limiting (Resilience4j)\n- **Observability** — OpenTelemetry tracing, structured logging (Logstash logback encoder)\n- **Quality gates** — SpotBugs, OWASP dependency check, JaCoCo coverage, code formatter\n\n---\n\n## Tech Stack\n\n| Category        | Technology                    |\n|----------------|-------------------------------|\n| Runtime        | Java 21                        |\n| Framework      | Spring Boot 3.1.4              |\n| Build          | Maven 3.6+                     |\n| Database       | MySQL 8, Flyway                |\n| Cache          | Redis, Spring Data Redis       |\n| Messaging      | Apache Kafka                   |\n| API docs       | SpringDoc OpenAPI              |\n| Testing        | JUnit 5, Mockito, RestAssured, Cucumber, Testcontainers |\n\n---\n\n## Prerequisites\n\n- **JDK 21** (required; other versions may cause Lombok/build issues)\n- **Maven 3.6+**\n- **Docker \u0026 Docker Compose** (for local MySQL, Redis, and integration tests)\n- **Git**\n\n---\n\n## Quick Start\n\n### 1. Clone the repository\n\n```bash\ngit clone https://github.com/your-org/java-service-template-clean-architecture.git\ncd java-service-template-clean-architecture\n```\n\n### 2. Use JDK 21\n\nIf you have multiple JDKs, set Java 21 before building or running:\n\n```bash\n# macOS / Linux (bash/zsh)\nexport JAVA_HOME=$(/usr/libexec/java_home -v 21)   # macOS\n# or: export JAVA_HOME=/path/to/jdk21               # Linux\n\njava -version   # Should show 21.x\n```\n\n### 3. Build\n\n```bash\n# Full build (unit + integration tests; requires Docker)\nmvn clean package\n\n# Unit tests only (no Docker required)\nmvn clean package -DskipIntegration=true\n```\n\n### 4. Run locally (with Docker)\n\nStart dependencies and run the app:\n\n```bash\n# Start MySQL, Redis, OpenTelemetry collector\ndocker compose -f docker-compose-local.yml up -d\n\n# Run database migrations\n./migrate.sh\n\n# Run the application (local profile)\nmvn spring-boot:run -Dspring-boot.run.profiles=local\n```\n\nAPI: **http://localhost:8080**  \nSwagger UI: **http://localhost:8080/swagger-ui.html** (if enabled in profile)\n\n---\n\n## Project Structure\n\n```\n├── src/main/java/com/olx/boilerplate/\n│   ├── controller/       # REST API, DTOs, request/response mapping\n│   ├── usercase/         # Application use cases (business flows)\n│   ├── domain/           # Domain entities and interfaces\n│   ├── repository/       # Data access interfaces\n│   └── infrastructure/   # Config, DB, Redis, Kafka, HTTP clients, etc.\n├── src/test/\n│   ├── java/             # Unit tests (ut/), integration tests\n│   └── resources/        # Test config, Cucumber features, mocks\n├── docker-compose-local.yml\n├── Dockerfile\n├── migrate.sh            # Flyway migration runner\n├── formatter.xml         # Eclipse formatter (Maven formatter plugin)\n└── pom.xml\n```\n\n---\n\n## Architecture\n\nThe project follows **Clean Architecture**: outer layers depend on inner layers; the domain has no framework or infrastructure dependencies.\n\n![Clean Architecture](CleanArchitecture.jpg)\n\n| Layer            | Responsibility |\n|------------------|----------------|\n| **Controller**   | HTTP handling, validation, DTO mapping |\n| **Use case**     | Orchestrate business logic, call domain and repositories |\n| **Domain**       | Entities and business rules |\n| **Repository**   | Data access contracts (interfaces) |\n| **Infrastructure** | Implementations: DB, Redis, Kafka, HTTP, config |\n\nDependency injection is used so that use cases and controllers depend on **abstractions** (interfaces), not concrete implementations.\n\n---\n\n## Configuration\n\n- **Profiles:** `local`, `integration-test`, etc. (see `src/main/resources/application*.yaml`).\n- **Local:** Use `application-local.yaml` and `docker-compose-local.yml` for DB, Redis, and Kafka URLs.\n- **Environment variables:** Override config via env (e.g. datasource, Redis host, Kafka bootstrap servers).\n\n---\n\n## Testing\n\n### Unit tests\n\n- **Location:** `src/test/java/.../ut/`\n- **Run:** `mvn test`\n- **Stack:** JUnit 5, Mockito; dependencies mocked.\n\n### Integration tests\n\n- **Location:** Cucumber `.feature` files and Java step definitions; run with Failsafe.\n- **Run:** `mvn verify` or `mvn integration-test` (uses `integration-test` profile).\n- **Requirements:** Docker (MySQL, Redis, etc. via Testcontainers or `docker-compose-local.yml`).\n\n### Example Cucumber scenario\n\n```gherkin\nScenario: Create a new user successfully\n  Given I have /user API\n  And I have following headers\n    | Content-Type     |\n    | application/json |\n  And I have a request body in {\"name\":\"Test User\", \"email\": \"test@email.com\"}\n  When Execute POST request using REST\n  Then Validate status code is: 201\n  And Validate user response\n```\n\n---\n\n## Development\n\n### Code formatting\n\nFormat code and validate style:\n\n```bash\nmvn formatter:format\n# or use formatter:validate in CI\n```\n\nFormatter config: `formatter.xml` (Eclipse-style, used by Maven formatter plugin).\n\n### Quality and security\n\n- **SpotBugs:** `mvn spotbugs:check`\n- **OWASP dependency check:** `mvn dependency-check:check`\n- **JaCoCo:** Coverage reports in `target/coverage-reports/` and `target/site/jacoco/`\n\n### Run only unit tests\n\n```bash\nmvn clean test\n```\n\n### Build without integration tests\n\n```bash\nmvn clean package -DskipIntegration=true\n```\n\n---\n\n## Docker\n\n- **Build image:** The root `Dockerfile` builds a Java 21 image and copies the packaged JAR (e.g. `target/boilerplate-0.1.0.jar`). Build with `mvn package` first.\n- **Local stack:** `docker compose -f docker-compose-local.yml up -d` runs MySQL, Redis, and an OpenTelemetry collector; the app can be run from the host with the `local` profile.\n\n---\n\n## FAQ\n\n### Build fails with Lombok `TypeTag :: UNKNOWN` or “Unsupported class file major version”\n\nThe project **must** be built with **JDK 21**. Using a different JDK (e.g. 22 or 24) can break Lombok and the compiler.\n\n- Check: `java -version` and `mvn -version` (Maven uses `JAVA_HOME`).\n- Set JDK 21: `export JAVA_HOME=$(/usr/libexec/java_home -v 21)` (macOS) or point `JAVA_HOME` to your JDK 21 install.\n- List JDKs on macOS: `/usr/libexec/java_home -V`.\n\n### How do I add a new API or use case?\n\n1. Add or reuse a **domain** entity/interface under `domain/`.\n2. Define a **repository** interface under `repository/` if you need persistence.\n3. Implement the **use case** in `usercase/` (call domain + repository).\n4. Expose it via a **controller** in `controller/` and map DTOs.\n5. Add **infrastructure** (e.g. JPA, Redis) under `infrastructure/` if needed.\n\n### Where is the OpenAPI / Swagger spec?\n\nSpringDoc is included; the UI and JSON are typically available at `/swagger-ui.html` and `/v3/api-docs` when the app runs, depending on profile and configuration.\n\n---\n\n## Contributing\n\nContributions are welcome. Please read [CONTRIBUTING.md](CONTRIBUTING.md) for:\n\n- How to report bugs and suggest features\n- Development setup and code style\n- Branch and pull request process\n- Commit message guidelines\n\n---\n\n## License\n\nThis project is licensed under the **Apache License 2.0**. See the [LICENSE](LICENSE) file for the full text, or [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0).\n\n---\n\n## Acknowledgments\n\n- [Spring Boot](https://spring.io/projects/spring-boot)\n- [Clean Architecture](https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html) (Robert C. Martin)\n- All [contributors](https://github.com/your-org/java-service-template-clean-architecture/graphs/contributors) and users of this template\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folx-india%2Fjava-service-template-clean-architecture","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Folx-india%2Fjava-service-template-clean-architecture","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folx-india%2Fjava-service-template-clean-architecture/lists"}