Coding Standards
Coding rules are baked into the parent pom.xml via Spotless, Checkstyle, PMD, and SpotBugs so that
every module adopts the same style and design discipline. Breaking any rule fails the Maven build.
Spotless formatting
Checkstyle rules
PMD + SpotBugs
JaCoCo gate
Source layout & naming
- One module per bounded context. Package prefix:
com.newsun.<module>. - Public APIs live under
.api; domain logic under.domain; persistence under.infra. - Service classes suffix with
Service, controllers withController, configurations withConfig. - Feature toggles implemented via
@ConditionalOnProperty+modules.<name>.enabled. - Tests mirror main packages (e.g.
com.newsun.audit→com.newsun.auditinsrc/test).
audit-module/
src/main/java/com/newsun/audit/
api/AuditResource.java
domain/AuditPlanService.java
infra/persistence/AuditPlanRepository.java
src/test/java/com/newsun/audit/
domain/AuditPlanServiceTest.java
Checkstyle enforces package naming, class suffixes, and inline documentation. Violations break
mvn verify.
Language & API conventions
- Favor immutable DTOs and records for inbound/outbound contracts.
- Use constructor injection only; field injection is blocked via Checkstyle.
- No static utility singletons—prefer Spring-managed beans.
- REST controllers must live under
/api/v1/<module>and expose DTOs, not entities. System.out/erris forbidden; use SLF4J with structured logging.
Parent pom.xml enforcement block
Copy / verify this section exists in the parent POM. Any deviation should be handled through the shared config repo, not per-module overrides.
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>${spotless.version}</version>
<executions>
<execution>
<phase>validate</phase>
<goals><goal>apply</goal></goals>
<configuration><java><palantirJavaFormat/></java></configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven.checkstyle.version}</version>
<executions>
<execution>
<phase>verify</phase>
<goals><goal>check</goal></goals>
<configuration>
<configLocation>config/checkstyle/checkstyle.xml</configLocation>
<suppressionsLocation>config/checkstyle/suppressions.xml</suppressionsLocation>
</configuration>
</execution>
</executions>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${maven.pmd.version}</version>
<executions>
<execution><phase>verify</phase><goals><goal>check</goal></goals></execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>${spotbugs.maven.version}</version>
<executions>
<execution><phase>verify</phase><goals><goal>check</goal></goals></execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>