TinyRuleKit
Getting Started
Many small engines start with a few direct if statements:
void onPlayerJoined(Player player, GameCalendar calendar) {
if (player.level() >= 5 && player.hasPermission("vip")) {
player.wallet().addCoins(25);
}
if (player.level() >= 10 && player.completedQuest("tutorial")) {
player.badges().unlock("veteran");
}
if (calendar.isWeekend() && player.region() == Region.EU) {
player.boosts().add("weekend_bonus");
}
}
That can be fine for three rules. With 30 or 50, the class starts mixing matching logic, parameters, and side effects in one place. Changing an amount, disabling a rule for one environment, or letting a non-engine author adjust a rule usually means touching Java code and redeploying the application.
A heavy weight rules platform can solve that, but often adds more runtime model, syntax, and infrastructure than a small game, tool, or app needs.
TinyRuleKit sits in that middle ground.
What TinyRuleKit Provides
TinyRuleKit lets applications keep domain behavior in Java while moving rule configuration to JSON:
[
{
"id": "vip_join_reward",
"trigger": "PLAYER_JOINED",
"conditions": [
{
"type": "LEVEL_AT_LEAST",
"params": {
"level": 5
}
}
],
"actions": [
{
"type": "GIVE_COINS",
"params": {
"amount": 25
}
}
]
}
]
The framework compiles that JSON once into executable Java functions. At runtime, firing a trigger only evaluates rules indexed for that trigger.
engine.fire(GameTrigger.PLAYER_JOINED, context);
Basic Shape
The first useful TinyRuleKit setup has four Java pieces:
- Token enums for the JSON vocabulary: triggers, conditions, and actions.
- A
RuleContextthat exposes the data rules can read. - A static
conditionfactory that converts condition token names and parameters intoCompiledConditionfunctions. - A static
actionfactory that converts action token names and parameters intoCompiledActionfunctions.
Those pieces are the basic surface of the framework. The JSON does not decide Java behavior by itself; it selects from the enum vocabulary and passes parameters that your factories validate during engine construction.
What Stays In Java
Your application still owns the real behavior:
static CompiledAction<GameContext> action(String type, RuleParams params) {
return switch (RuleToken.enumValue(GameAction.class, type)) {
case GIVE_COINS -> {
int amount = params.getInt("amount", 1);
yield (context, variables) -> context.wallet().addCoins(amount);
}
};
}
TinyRuleKit is useful when rules are simple enough to express as triggers, conditions, actions, and parameters, but should remain configurable outside the compiled application.
Move to Setup when you are ready to add TinyRuleKit to a project.