refactor: 백엔드 리펙토링 진행 중

This commit is contained in:
DongHyeonka
2026-09-25 17:57:07 +09:00
parent fd80de369d
commit 2c7d1d58f3
44 changed files with 315 additions and 1852 deletions
@@ -1,53 +0,0 @@
package dev.caskeleton.grpc.core;
import java.util.Set;
/**
* Build-time invariants the Stable platform holds about its own module graph.
*
* <p>These are asserted from Java as well as from Gradle on purpose. The registry gate ({@code
* verifyCleanArchitectureDependencies}) is the one that fails a build, and it is the authority;
* this class is what a runtime component calls when it is handed a dependency set it did not
* compile against — a starter reading its own classpath, say — where the Gradle gate has nothing to
* look at.
*/
public final class GrpcStableBuildInvariant {
private GrpcStableBuildInvariant() {}
/**
* Whether a Stable module may depend on an Advanced one.
*
* <p>Always false, and it takes no argument for a reason: the answer does not vary by module, by
* capability or by environment. A method that could return true for some input would be the seam
* through which "just this one Advanced type in the starter" arrives.
*/
public static boolean advancedDependencyAllowed() {
return false;
}
/**
* Fails when a Stable module's dependency set reaches an Advanced module.
*
* @throws IllegalStateException naming every advanced dependency found
*/
public static void requireNoAdvancedDependency(String moduleId, Set<String> dependencies) {
GrpcIdentifiers.requireBounded(moduleId, "module id");
if (dependencies == null) {
throw new IllegalArgumentException("dependency set must not be null");
}
if (!GrpcStableModuleCatalog.standard().isStable(moduleId)) {
return;
}
Set<String> leaks = GrpcStableModuleCatalog.advancedLeaks(dependencies);
if (!leaks.isEmpty()) {
throw new IllegalStateException(
"Stable module '"
+ moduleId
+ "' must not depend on advanced modules "
+ leaks.stream().sorted().toList()
+ "; advanced capabilities are reached through an explicit feature flag, never by "
+ "being on the Stable classpath.");
}
}
}
@@ -1,79 +0,0 @@
package dev.caskeleton.grpc.core;
import java.util.LinkedHashSet;
import java.util.Set;
/**
* The exact set of Stable platform modules, and the exact set that is not Stable.
*
* <p>The Stable plan fixes its module list as a Global Constraint so that "this capability is
* Stable" is a fact with one owner instead of a property of whatever happens to be on a classpath.
* This repository's module registry ({@code src/config/architecture/modules.json}) is the SSOT for
* which Gradle projects exist; this catalog is the SSOT for which of them the Stable contract
* covers, and {@code GrpcStableModuleCatalogTest} holds the two together.
*
* <p>The names are this repository's leaf ids rather than the plan's, because the plan's four
* testkit modules are four strict test lanes here — see the adaptation design, §2.
*/
public record GrpcStableModuleCatalog(Set<String> modules) {
private static final Set<String> STABLE =
Set.of(
"grpc-core-api",
"grpc-proto-contract",
"grpc-codegen",
"grpc-policy",
"grpc-server",
"grpc-client",
"grpc-discovery",
"grpc-admin",
"grpc-observability",
"grpc-operation-ledger-jpa",
"grpc-spring-boot-starter",
"grpc-testkit");
private static final Set<String> ADVANCED =
Set.of(
"grpc-advanced-bootstrap",
"grpc-advanced-edition",
"grpc-advanced-streaming",
"grpc-advanced-resilience",
"grpc-advanced-compat",
"grpc-advanced-diagnostics");
/** Defensively copies, so a caller cannot widen the Stable set by mutating what it was given. */
public GrpcStableModuleCatalog {
if (modules == null || modules.isEmpty()) {
throw new IllegalArgumentException("a module catalog needs at least one module");
}
modules = Set.copyOf(modules);
}
/** The Stable module set. */
public static GrpcStableModuleCatalog standard() {
return new GrpcStableModuleCatalog(STABLE);
}
/** The Advanced and Experimental module set, which is disjoint from {@link #standard()}. */
public static Set<String> advancedModules() {
return ADVANCED;
}
/** Whether {@code moduleId} is part of the Stable contract. */
public boolean isStable(String moduleId) {
return modules.contains(moduleId);
}
/**
* The advanced module ids that appear in {@code candidateDependencies}.
*
* <p>Returned rather than thrown so a build or startup check can name every violation at once. A
* gate that reports the first advanced dependency it finds makes removing four of them a
* four-round conversation.
*/
public static Set<String> advancedLeaks(Set<String> candidateDependencies) {
Set<String> leaks = new LinkedHashSet<>(candidateDependencies);
leaks.retainAll(ADVANCED);
return Set.copyOf(leaks);
}
}
@@ -1,90 +0,0 @@
package dev.caskeleton.grpc.core;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Set;
import java.util.regex.Pattern;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
class GrpcStableModuleCatalogTest {
@Test
@DisplayName("the Stable module set is exact and excludes every advanced module")
void stableModuleSetIsExactAndAdvancedIsExcluded() {
GrpcStableModuleCatalog catalog = GrpcStableModuleCatalog.standard();
assertThat(catalog.modules())
.contains("grpc-core-api", "grpc-client", "grpc-server", "grpc-policy")
.doesNotContainAnyElementsOf(GrpcStableModuleCatalog.advancedModules());
assertThat(GrpcStableBuildInvariant.advancedDependencyAllowed()).isFalse();
}
@Test
@DisplayName("the optional gRPC registry is exactly classified as Stable or Advanced")
void registryAndCatalogStayTogether() throws Exception {
Path candidate = Path.of("").toAbsolutePath();
while (candidate != null
&& !Files.isRegularFile(candidate.resolve("src/config/architecture/modules.json"))) {
candidate = candidate.getParent();
}
assertThat(candidate).as("repository root").isNotNull();
String registry = Files.readString(candidate.resolve("src/config/architecture/modules.json"));
Pattern entry =
Pattern.compile(
"\\{[^{}]*\"id\"\\s*:\\s*\"(grpc-[^\"]+)\"[^{}]*"
+ "\"build\"\\s*:\\s*\"optional-grpc\"[^{}]*\\}",
Pattern.DOTALL);
Set<String> registered =
entry
.matcher(registry)
.results()
.map(result -> result.group(1))
.collect(java.util.stream.Collectors.toUnmodifiableSet());
Set<String> classified = new java.util.HashSet<>(GrpcStableModuleCatalog.standard().modules());
classified.addAll(GrpcStableModuleCatalog.advancedModules());
assertThat(registered).isNotEmpty().containsExactlyInAnyOrderElementsOf(classified);
}
@Test
@DisplayName("the Stable and Advanced sets are disjoint")
void stableAndAdvancedAreDisjoint() {
GrpcStableModuleCatalog catalog = GrpcStableModuleCatalog.standard();
assertThat(GrpcStableModuleCatalog.advancedModules()).isNotEmpty().noneMatch(catalog::isStable);
}
@Test
@DisplayName("a Stable module reaching an advanced module fails, naming every leak")
void stableModuleMayNotDependOnAdvanced() {
Set<String> dependencies =
Set.of("grpc-core-api", "grpc-advanced-streaming", "grpc-advanced-compat");
assertThatThrownBy(
() ->
GrpcStableBuildInvariant.requireNoAdvancedDependency(
"grpc-spring-boot-starter", dependencies))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("grpc-spring-boot-starter")
.hasMessageContaining("grpc-advanced-streaming")
.hasMessageContaining("grpc-advanced-compat");
}
@Test
@DisplayName("a Stable module with only Stable dependencies passes")
void stableOnlyDependenciesPass() {
GrpcStableBuildInvariant.requireNoAdvancedDependency(
"grpc-server", Set.of("grpc-core-api", "grpc-policy"));
}
@Test
@DisplayName("an advanced module is not judged by the Stable invariant")
void advancedModuleIsNotGovernedByTheStableRule() {
GrpcStableBuildInvariant.requireNoAdvancedDependency(
"grpc-advanced-compat", Set.of("grpc-advanced-bootstrap"));
}
}