Date: 2025-12-10
Status: Accepted
Context: Standardization of Java package structure across all modules using Clean Architecture principles
The codebase had inconsistent package structures across modules:
This inconsistency made the codebase harder to navigate, understand, and maintain. New developers had to learn different patterns for each module.
We will adopt Clean Architecture package structure standards across all modules. All API and implementation modules must follow these standards.
forge-api) and implementations (forge-impl)Forge Kit is organized as a library/framework repository with two main module categories:
forge-api/: API modules defining contracts, interfaces, annotations, and DTOsforge-impl/: Implementation modules providing concrete implementationsAll modules follow the pattern: io.forge.kit.{module}.{api|impl}.{layer}
{module}: The module name (e.g., security, metrics, throttle, common, health){api|impl}: Either api for contracts or impl for implementations{layer}: The architectural layer (e.g., domain, infrastructure, rest, dto)forge-api/{module}-api)API modules define contracts, interfaces, annotations, and shared DTOs:
io.forge.kit.{module}.api/
├── domain/ # Domain interfaces and contracts
│ ├── exception/ # Domain exceptions
│ ├── support/ # Support interfaces/utilities
│ └── [Domain interfaces]
├── dto/ # Data transfer objects
│ └── [DTOs]
├── infrastructure/ # Infrastructure contracts
│ └── [Infrastructure interfaces]
├── rest/ # REST layer annotations
│ ├── exception/ # Exception-related annotations
│ └── [REST annotations]
├── jwt/ # JWT-related contracts (if applicable)
│ └── [JWT interfaces]
├── key/ # Key resolution contracts (if applicable)
│ └── resolver/
│ └── [Key resolver interfaces]
├── faulttolerance/ # Circuit breaker contracts (if applicable)
│ └── [Fault tolerance interfaces]
└── persistence/ # Persistence contracts (if applicable)
└── [Persistence interfaces]
forge-impl/{module})Implementation modules provide concrete implementations of API contracts:
io.forge.kit.{module}.impl/
├── domain/ # Domain implementations
│ ├── exception/ # Exception mappers/handlers
│ ├── recorder/ # Metrics recorders (if applicable)
│ ├── support/ # Support implementations
│ └── [Domain implementations]
├── dto/ # Implementation-specific DTOs (if any)
│ └── [DTOs]
├── infrastructure/ # Infrastructure implementations
│ ├── config/ # Configuration producers
│ ├── [Infrastructure implementations]
│ └── [Sub-packages for specific concerns]
├── rest/ # REST layer implementations
│ ├── exception/ # Exception mappers
│ └── [REST implementations]
├── jwt/ # JWT implementations (if applicable)
│ └── [JWT implementations]
├── key/ # Key resolution implementations (if applicable)
│ └── resolver/
│ └── [Key resolver implementations]
├── strategy/ # Strategy implementations (if applicable)
│ └── [Strategy implementations]
├── faulttolerance/ # Circuit breaker implementations (if applicable)
│ ├── recorder/
│ └── [Fault tolerance implementations]
├── persistence/ # Persistence implementations (if applicable)
│ ├── recorder/
│ └── [Persistence implementations]
├── logging/ # Logging implementations (if applicable)
│ └── [Logging implementations]
├── lang/ # Language utilities (if applicable)
│ └── [Language utilities]
├── inject/ # CDI utilities (if applicable)
│ └── [CDI implementations]
├── reference/ # Reference implementations/examples
│ └── [Reference code]
└── test/ # Test profiles and test utilities
└── [Test profiles]
{Purpose}Provider.java, {Purpose}Validator.java
TokenValidator, UserAuthenticationProvider, ServiceAuthenticationProvider{Purpose}Interface.java or descriptive names
RateLimiter, MetricsRecorderBucket4jRateLimiter (implements RateLimiter){Service}Producer.java
Bucket4jRateLimiterProducer, RateLimiterPropertiesProducer{Purpose}Resolver.java
AllowedServicesResolver, JwtPrincipalResolver, MetricsRecorderResolver{Purpose}Interceptor.java
ServiceMetricsInterceptor, DatabaseMetricsInterceptor{Entity}Mapper.java
AuthenticationExceptionMapper, ValidationExceptionMapperSecured, AllowedServices, LogMethodEntry{Purpose}Request.java, {Purpose}Response.java, {Entity}.java
AuthResponse, TokenValidation, AuthIdentity, MetricsResultIndicatordomain/ in both API and implementation modulesinfrastructure/ in both API and implementation modulesrest/ in both API and implementation modulesdto/ in API modules (shared DTOs) or implementation modules (implementation-specific DTOs)TokenValidator, UserAuthenticationProvider), DTOs, JWT contracts, REST annotationsMetricsRecorder), DTOs, fault tolerance contracts, persistence contractsRateLimiter), key resolver interfacesLogMethodEntry)API (forge-api/forge-security-api):
io.forge.kit.security.api/
├── domain/
│ ├── exception/
│ │ └── AuthenticationException.java
│ ├── TokenValidator.java
│ ├── ServiceAuthenticationProvider.java
│ └── UserAuthenticationProvider.java
├── dto/
│ ├── AuthIdentity.java
│ ├── AuthResponse.java
│ └── TokenValidation.java
├── jwt/
│ ├── JwtPrincipal.java
│ └── JwtPrincipalExtractor.java
└── rest/
├── AllowedServices.java
└── Secured.java
Implementation (forge-impl/forge-security):
io.forge.kit.security.impl/
├── infrastructure/
│ └── AllowedServicesResolver.java
├── jwt/
│ ├── JwtPayloadParser.java
│ ├── JwtPrincipalResolver.java
│ ├── JwtServicePrincipalAccessor.java
│ ├── JwtTokenExtractor.java
│ └── JwtUserPrincipalAccessor.java
└── rest/
└── exception/
└── AuthenticationExceptionMapper.java
Positive:
All new modules must follow these standards from creation.
Existing modules should be refactored to follow these standards when:
Note: Not all modules need immediate refactoring. Standards apply to new code and major changes.
Code reviews should verify:
forge-api/{module}-apiforge-impl/{module}domain/infrastructure/rest/dto/ and placed appropriately (API vs implementation)io.forge.kit.{module}.{api|impl}.{layer}The current structure generally follows these standards. Key observations:
forge-api and forge-impl modulesdomain/, infrastructure/, rest/, dto/ layersio.forge.kit.{module}.{api|impl}.{layer} patternjwt/, key/, faulttolerance/, persistence/)Minor Observations:
reference/ for reference implementations (e.g., forge-throttle) - this is acceptable for examplestest/ for test profiles (e.g., forge-throttle) - this is acceptable for test utilitiesforge-common-api module is minimal (only logging/LogMethodEntry.java) - this is acceptable for simple annotation-only modulesDecision Owner: Architecture Team
Review Cycle: Review annually or when new module types are introduced