Comprehensive overview of the Beas Rule Engine architecture and design patterns
The Beas Rule Engine follows a modern, scalable architecture designed for enterprise-grade rule processing. The system is built using Spring Boot with a layered architecture that promotes separation of concerns, maintainability, and extensibility.
REST Controllers, DTOs, Validation, Exception Handling
Services, Rule Engine Manager, Cache Controller, Cryptography
Repositories, MongoDB, Cache Stores, RSQL Queries
The presentation layer handles all external communication and provides a clean REST API interface.
@RestController
@RequestMapping("/beasre/v1/rule-engine")
public class RuleEngine {
@PostMapping("/evaluate")
public ResponseEntity<RuleResponse> evaluateRule(
@RequestBody RuleRequest request,
@RequestParam Map<String, Object> parameters
) {
// Rule evaluation logic
}
}
The business layer contains the core business logic and orchestrates rule processing.
@Service
public class RuleLibraryService extends BaseService<RuleLibrary> {
public RuleLibrary createRuleLibrary(RuleLibrary ruleLibrary) {
// Business logic for creating rule library
validateRuleLibrary(ruleLibrary);
return repository.save(ruleLibrary);
}
}
The data layer manages data persistence and provides data access abstractions.
@Repository
public interface RuleLibraryRepository extends MongoRepository<RuleLibrary, String> {
List<RuleLibrary> findByContainerName(String containerName);
@Query("{'name': {$regex: ?0, $options: 'i'}}")
List<RuleLibrary> findByNameContainingIgnoreCase(String name);
}
The Rule Engine Manager is the heart of the system, responsible for rule evaluation and processing.
public class RuleEngineManager {
public Object evaluateRule(String ruleName, Map<String, Object> parameters, Object payload) {
// 1. Load rule from cache or database
// 2. Compile and validate rule
// 3. Create execution context
// 4. Execute rule with parameters
// 5. Return result
}
}
The Cache Controller manages multiple caching layers for optimal performance.
@Component
public class CacheController {
public void syncCaches() {
// Synchronize all cache layers
functionCache.sync();
instanceCache.sync();
resultCache.sync();
}
}
The Cryptography Service provides data encryption and security features.
@Service
public class Cryptography {
public String encrypt(String data) {
// TripleDES encryption
return cryptoState.encrypt(data);
}
public String decrypt(String encryptedData) {
// TripleDES decryption
return cryptoState.decrypt(encryptedData);
}
}
Client Request
↓
REST Controller
↓
Authentication Filter
↓
Validation Layer
↓
Service Layer
↓
Rule Engine Manager
↓
Cache Controller
↓
Database/Repository
↓
Response Formatter
↓
Client Response
security:
oauth2:
resource:
jwt:
key-value: ${JWT_PUBLIC_KEY}
jwt:
secret: ${JWT_SECRET}
expiration: 3600
cryptography:
key: ${CRYPTO_KEY}
iv: ${CRYPTO_IV}
cache:
function:
ttl: 3600
max-size: 1000
instance:
ttl: 1800
max-size: 500
result:
ttl: 900
max-size: 2000
FROM openjdk:17-jdk-slim
COPY target/beas-rule-engine.jar app.jar
EXPOSE 8070
ENTRYPOINT ["java", "-jar", "/app.jar"]