Skip to content

Repository files navigation

Java Comprehensive Enterprise Template

A production-ready reference template covering best practices, architecture patterns, and working examples for enterprise Java development (Java 17+).


Table of Contents


Quick Start

# Build all modules
./mvnw clean verify
# Run the REST API example
./mvnw -pl examples/restful-api spring-boot:run
# Run unit tests only
./mvnw test# Run integration tests (requires Docker)
./mvnw verify -P integration-tests
# Format code
./mvnw spotless:apply -P format

Project Structure

├── pom.xml # Parent POM — dependency management & plugin config
├── .github/workflows/ci.yml # GitHub Actions CI/CD pipeline
├── docs/
│ ├── TUTORIAL.md # New developer walkthrough (start here!)
│ ├── TOOLCHAIN.md # Required tools, install guides, IDE setup
│ ├── EXTENDING.md # Adding modules, endpoints, dependencies
│ ├── SECURITY_SCANNING.md # SpotBugs, OWASP, PMD, Checkstyle config
│ ├── best-practices.md # Code style, error handling, logging (Java 17+)
│ ├── architecture-patterns.md # Microservices, hexagonal, CQRS, event sourcing
│ ├── third-party-libraries.md # Library catalog with usage examples
│ ├── documentation-standards.md # JavaDoc, OpenAPI/Swagger, README conventions
│ └── development-workflow.md # CI/CD, adding features, Docker, quality gates
├── examples/
│ ├── restful-api/ # REST server + 3 client implementations
│ ├── database/ # JPA entities, repositories, JDBC, Flyway
│ ├── hpc/ # Parallel streams, virtual threads, concurrency
│ ├── etl/ # Spark, Spring Batch, pipeline abstraction
│ ├── systems/ # JNI, off-heap memory, JMH, profiling
│ ├── patterns/ # Creational, structural, behavioral patterns
│ ├── simulation/ # Monte Carlo & discrete event simulation
│ └── testing/ # JUnit 5, Mockito, TestContainers, REST Assured

Example Modules

RESTful API

Path:examples/restful-api/ · README

Spring Boot 3 REST server with full CRUD, plus three client implementations.

ComponentDescription
ProductControllerREST endpoints with validation, OpenAPI annotations
ProductServiceService interface + in-memory implementation
GlobalExceptionHandlerCentralized error handling with ErrorResponse DTOs
ProductRestTemplateClientSynchronous client (RestTemplate + RestClient)
ProductWebClientExampleReactive client (WebFlux WebClient)
ProductJaxRsClientJAX-RS/Jersey client
OpenApiConfigSwagger UI via springdoc-openapi

Related docs: Best Practices (error handling), Documentation Standards (OpenAPI), Architecture Patterns (microservices)

Database

Path:examples/database/ · README

JPA/Hibernate entities with Spring Data repositories and raw JDBC access.

ComponentDescription
Order / OrderItemJPA entities with @OneToMany, optimistic locking, lifecycle callbacks
OrderRepositorySpring Data JPA — derived queries, JPQL, native SQL, bulk updates
OrderServiceTransactional service — propagation, isolation, read-only, rollback rules
JdbcOrderDaoJdbcTemplate + NamedParameterJdbcTemplate, batch operations
DataSourceConfigHikariCP connection pool configuration
V1__create_orders.sqlFlyway migration
application.ymlDual-profile config (H2 dev / PostgreSQL prod)

Related docs: Best Practices (resource management), Third-Party Libraries (HikariCP, Flyway)

High Performance Computing

Path:examples/hpc/ · README

Concurrency patterns using modern Java APIs.

ComponentDescription
ParallelStreamExamplesCustom ForkJoinPool, groupingByConcurrent, parallel reduction
CompletableFutureExamplesChaining, fan-out/fan-in, error handling, timeouts
ConcurrentCollectionsExamplesConcurrentHashMap, BlockingQueue, LongAdder, Semaphore, StampedLock
VirtualThreadExamplesJava 21+ virtual threads (Maven profile exclusion on Java 17)

Related docs: Best Practices (concurrency), Architecture Patterns (async patterns)

ETL & Batch Processing

Path:examples/etl/ · README

Three approaches to data processing: Spark, Spring Batch, and pure Java.

ComponentDescription
SparkEtlExampleRDD word count, DataFrame CSV→Parquet, Spark SQL, typed Datasets
CsvToJsonBatchConfigSpring Batch 5 chunk-oriented job with fault tolerance
DataPipelinePure-Java extract/filter/transform/load abstraction
DataPipelineTestUnit tests for the pipeline abstraction

Related docs: Architecture Patterns (CQRS, event sourcing), Third-Party Libraries (Spring Batch)

Systems Programming

Path:examples/systems/ · README

Low-level Java: native interop, memory management, and performance measurement.

ComponentDescription
JniExampleJNI native methods with Java fallback pattern
OffHeapMemoryExampleDirect ByteBuffer, Cleaner-based arrays, memory-mapped files
PerformanceBenchmarksJMH benchmarks (string concat, boxing, collections, streams)
ProfilingUtilsJVM snapshots via MXBeans, execution timing

Related docs: Best Practices (performance), Development Workflow (profiling)

Design Patterns

Path:examples/patterns/ · README

15 GoF patterns implemented with modern Java 17+ idioms (records, sealed interfaces, pattern matching).

FilePatterns
CreationalPatternsBuilder, Factory Method, Singleton, Prototype, Abstract Factory
StructuralPatternsAdapter, Decorator, Proxy, Composite, Facade
BehavioralPatternsStrategy, Observer, Command, Template Method, Chain of Responsibility

Related docs: Architecture Patterns (hexagonal, CQRS), Best Practices (code style)

Simulation

Path:examples/simulation/ · README

Statistical and event-driven simulation frameworks.

ComponentDescription
MonteCarloSimulationGeneric engine with Welford's online variance, Pi estimation, option pricing
DiscreteEventSimulationPriority-queue DES engine with M/M/1 queue example

Related docs: HPC module (parallel execution), Best Practices (functional style)

Testing

Path:examples/testing/ · README

Comprehensive testing strategy with examples for every layer.

ComponentDescription
JUnit5FeaturesTestParameterized, nested, conditional tests, tags
MockitoFeaturesTestMocking, stubbing, captors, BDD style, spies
PostgresContainerITTestContainers PostgreSQL integration test
RestAssuredITREST Assured API testing with httpbin container
ArchitectureRulesTestArchUnit architecture enforcement
Domain classesUser, UserRepository, UserService as test targets

Related docs: Development Workflow (CI/CD, quality gates), Documentation Standards (test documentation)

Documentation Guides

Tutorial

docs/TUTORIAL.md — New developer walkthrough: clone, build, run the REST API, explore with curl, run other examples, add a feature, run quality/security scans, Docker build. Start here if you're new to the project.

Toolchain

docs/TOOLCHAIN.md — Required tools (JDK 21, Maven wrapper, Docker), platform-specific install instructions (macOS, Linux, Windows), IDE setup (IntelliJ IDEA, VS Code), and quality tool reference.

Extending the Template

docs/EXTENDING.md — Step-by-step guides for adding a new Maven module, REST endpoint, service, third-party dependency, and quality rule/suppression.

Best Practices

docs/best-practices.md — 10 sections covering code style, naming conventions, error handling, logging, null safety, records & sealed classes, collections, concurrency, resource management, and general principles. All examples use Java 17+.

Architecture Patterns

docs/architecture-patterns.md — Microservices (Spring Boot, WebClient, Kafka, API Gateway, Resilience4j), hexagonal architecture (ports & adapters), CQRS (command/query separation), event sourcing (aggregate replay, event store, snapshots). Includes decision flowchart and anti-patterns.

Third-Party Libraries

docs/third-party-libraries.md — Catalog of recommended libraries: Spring ecosystem (6 starters), Apache Commons, Guava, Jackson, Lombok, MapStruct, Resilience4j, logging (SLF4J + Logback), database libs (HikariCP, Flyway, H2), and build plugins. Includes version reference table and selection decision guide.

Documentation Standards

docs/documentation-standards.md — JavaDoc conventions (tag ordering, class/method/record examples), README templates, OpenAPI/Swagger integration (springdoc-openapi, code-first vs contract-first, OpenAPI Generator), and changelog format.

Development Workflow & CI/CD

docs/development-workflow.md — GitHub Actions 4-stage pipeline, Dockerfile (Temurin 21 JRE Alpine), adding modules/features guide, quality gates (SpotBugs, Checkstyle, JaCoCo, OWASP), Docker Compose, git branching, conventional commits, and release process.

Security Scanning

docs/SECURITY_SCANNING.md — Detailed configuration and usage for SpotBugs, Checkstyle, PMD, and OWASP Dependency-Check. Includes suppression guides, CI integration, and a maturity roadmap.

Requirements

RequirementVersion
Java17+ (21 recommended for virtual threads)
Maven3.9+ (wrapper included)
DockerRequired for TestContainers and containerized deployment

Java Features Used

  • Records and sealed classes (Java 17)
  • Pattern matching for instanceof and switch (Java 17+)
  • Text blocks (Java 17)
  • Virtual threads (Java 21+, guarded by Maven profile)
  • Sequenced collections (Java 21+, where noted)

Coverage Checklist

RequirementModule / DocStatus
RESTful APIs (client + server)examples/restful-api/
Database (JPA, JDBC, pooling, transactions)examples/database/
High Performance Computingexamples/hpc/
ETL / MapReduceexamples/etl/
Systems Programmingexamples/systems/
Design Patterns (GoF)examples/patterns/
Simulation (Monte Carlo, DES)examples/simulation/
Testing (JUnit 5, TestContainers, REST Assured)examples/testing/
Best Practices Guidedocs/best-practices.md
Architecture Patternsdocs/architecture-patterns.md
Third-Party Librariesdocs/third-party-libraries.md
Documentation Standardsdocs/documentation-standards.md
Development Workflow & CI/CDdocs/development-workflow.md
Toolchain & IDE Setupdocs/TOOLCHAIN.md
Extending the Templatedocs/EXTENDING.md
New Developer Tutorialdocs/TUTORIAL.md
Security Scanningdocs/SECURITY_SCANNING.md
Project Setup (Maven multi-module)pom.xml
CI/CD Pipeline.github/workflows/ci.yml
Dockerexamples/restful-api/Dockerfile

License

Apache License 2.0

About

Comprehensive Java project template with Maven, Spring Boot, testing, security scanning, and Docker support

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages