Features¶
Production-ready capabilities included in this Spring Boot Clean Architecture template.
Differentiators first: ArchUnit-enforced layers, database-per-tenant MySQL, transactional outbox → Kafka, Cucumber + Testcontainers, ops/quality gates, and AI-agent docs (AGENTS.md).
Architecture and quality¶
- Clean Architecture — Layered design with controller, use case, domain, and infrastructure packages
- ArchUnit boundary tests — Enforces that domain and use cases do not depend on outer layers
- Use case pattern — Commands and application services separate HTTP from business logic
- Quality gates — SpotBugs, OWASP dependency-check, JaCoCo coverage, Eclipse formatter (Maven verify)
Data and persistence¶
- Multi-tenant MySQL — Database-per-tenant with read/write replica routing via
CustomRoutingDataSource - Flyway migrations — Versioned scripts in
common/and tenant-specific folders - Transactional outbox —
outbox_eventtable +OutboxRelaySchedulerrelay worker; events written atomically with business data (see outbox-pattern.md) - JPA repositories — Domain ports with infrastructure adapters and entity mapping
Caching and messaging¶
- Redis caching — Spring Cache on use cases with actuator cache eviction endpoint
- Kafka events — Domain events via
EventPublisherport (UserCreatedEventexample) - Configurable TTL — Redis entry TTL via
redis.timeToLive
API and documentation¶
- REST APIs — User and order CRUD with pagination (
PageResponse) - Validation — Jakarta Bean Validation on request DTOs
- OpenAPI / Swagger — SpringDoc with annotated controllers; reference spec in openapi.yaml
- Standard error handling — RFC 7807
ProblemDetailviaCustomExceptionHandler
Resilience and integrations¶
- External HTTP client — OkHttp with circuit breaker, retry, and rate limiter (Resilience4j)
- Per-client configuration — Retry and circuit breaker settings in
application.yaml
Security¶
- Optional JWT (HMAC) —
spring.security.enabled=trueandsecurity.mode=hmacwithsecurity.jwt.secret - OIDC resource server —
security.mode=oidcwithOAUTH2_JWK_SET_URI/spring.security.oauth2.resourceserver.jwt.jwk-set-uri - No-security default — open endpoints for local development
- Tenant headers —
X-Default-Tenantrequired on API requests (health/swagger excluded)
Observability¶
- Prometheus metrics — Exposed on management port 8081 at
/metrics - Health probes — Liveness and readiness endpoints for Kubernetes
- Correlation IDs —
CorrelationIdFilteraddstid/cidviaAppMdc - AppLogger —
com.olx.boilerplate.logging.AppLoggers(not a domain port); SLF4J is an infrastructure adapter only - OpenTelemetry — Agent in Dockerfile; Micrometer Tracing bridge for local runs; OTel collector in Compose
- Custom actuator endpoints — Cache eviction and custom health extensions
API conventions¶
- Versioned under
/api/v1/...(e.g./api/v1/users,/api/v1/orders) - Errors use RFC 7807
ProblemDetailfromCustomExceptionHandler
Testing¶
- Unit tests — JUnit 5 and Mockito for controllers and use cases
- Integration tests — Cucumber BDD scenarios with Testcontainers (MySQL, Redis, Kafka)
- RestAssured — HTTP assertions in integration step definitions
Developer experience¶
- Makefile —
make devloads.env, starts infra, migrates, and runs the app - Docker Compose — Local MySQL, Redis, Kafka, and OTel collector
- Environment template —
.env.exampledocuments required variables - Maven wrapper — Reproducible builds without a global Maven install
- AI-agent docs — AGENTS.md and ai-agents.md for Cursor / Claude Code
Tech stack summary¶
| Category | Technology |
|---|---|
| Runtime | Java 21 |
| Framework | Spring Boot 4.0 |
| Build | Maven 3.6+ |
| Database | MySQL 8, Flyway |
| Cache | Redis, Spring Cache |
| Messaging | Apache Kafka |
| API docs | SpringDoc OpenAPI |
| Testing | JUnit 5, Mockito, Cucumber, Testcontainers, RestAssured |