Skip to content

Commit 2a36736

Browse files
committed
docs: add NJS-GROWTH-05 comparison guides
1 parent b56d48b commit 2a36736

15 files changed

Lines changed: 1484 additions & 14 deletions

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Use it when hardcoded `if/else` logic is too rigid, but a heavyweight workflow o
2323
- Examples: [`examples/`](examples/) with pricing, eligibility, and workflow-routing scenarios
2424
- Schemas and validation docs: [`docs/schemas-validation-explainability.md`](docs/schemas-validation-explainability.md)
2525
- AI-readable docs: [`docs/ai-coding-assistants.md`](docs/ai-coding-assistants.md), [`docs/public/llms.txt`](docs/public/llms.txt), and the official [`neuron-js` AI skill](docs/public/skills/neuron-js/SKILL.md)
26+
- Comparison and migration guides: [`docs/comparisons/`](docs/comparisons/) for json-rules-engine, JsonLogic, node-rules, and if/else migrations
2627

2728
---
2829

@@ -158,12 +159,9 @@ Available adoption assets:
158159

159160
- Runnable examples: [`examples/`](examples/)
160161
- JSON Schemas, validation, and explain output: [`docs/schemas-validation-explainability.md`](docs/schemas-validation-explainability.md)
162+
- Comparison and migration guides: [`docs/comparisons/`](docs/comparisons/) for choosing and migrating from json-rules-engine, JsonLogic, node-rules, and hand-written if/else
161163
- AI-readable docs: [`docs/ai-coding-assistants.md`](docs/ai-coding-assistants.md), [`docs/public/llms.txt`](docs/public/llms.txt), [`docs/public/llms-full.txt`](docs/public/llms-full.txt), and [`docs/public/skills/neuron-js/SKILL.md`](docs/public/skills/neuron-js/SKILL.md)
162164

163-
Planned next adoption assets:
164-
165-
- Comparison and migration pages: `NJS-GROWTH-05`
166-
167165
---
168166

169167
## 🛠 Development
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# Drafting fields
2+
3+
Title: Neuron-JS vs json-rules-engine: choosing the right JSON rules engine
4+
5+
Alias: neuron-js-vs-json-rules-engine
6+
7+
Description: A practical migration guide for teams comparing Neuron-JS with json-rules-engine, focused on TypeScript ownership, validation, explainability, and deterministic JSON business rules.
8+
9+
Tags: neuron-js, typescript, rules-engine, json-rules-engine, migration, business-rules, ai-agents
10+
11+
# Markdown body
12+
13+
## The short version
14+
15+
`json-rules-engine` is the established Node.js default for JSON rules. It is mature, recognizable, and built around facts, conditions, events, and rule priorities.
16+
17+
Neuron-JS takes a narrower position: **JSON business rules for TypeScript systems that need validation before runtime and explanation after execution**.
18+
19+
That difference matters when business rules become product infrastructure instead of a helper library.
20+
21+
Use `json-rules-engine` when your system already thinks in facts and events, and the existing ecosystem fit is more important than a built-in validation and explanation contract.
22+
23+
Use Neuron-JS when the rule layer must be:
24+
25+
- stored as JSON,
26+
- generated or edited outside deployment cycles,
27+
- validated before runtime,
28+
- executed through an approved TypeScript registry,
29+
- explained for support, audit, or tests.
30+
31+
## What each tool is optimized for
32+
33+
`json-rules-engine` gives teams a known model:
34+
35+
- facts describe the current world,
36+
- conditions decide whether something matches,
37+
- events describe what happened,
38+
- priorities help control rule order.
39+
40+
That is a good model. If your business logic already lives there and works, migration is not automatically valuable.
41+
42+
Neuron-JS is optimized for a different pressure point: **safe dynamic logic in TypeScript applications**.
43+
44+
The core model is:
45+
46+
- `Neuron` owns the approved rule vocabulary,
47+
- `Synapse` executes a serializable script,
48+
- schemas validate generated or stored JSON,
49+
- output summaries and explanation traces make the decision reviewable.
50+
51+
That makes it useful when rules become a governance problem, not only an execution problem.
52+
53+
## When Neuron-JS is the better fit
54+
55+
Choose Neuron-JS when you need a tighter contract around JSON business rules.
56+
57+
Good signs:
58+
59+
- AI agents generate candidate rules and you need to reject malformed scripts before execution.
60+
- Product or operations teams need rule changes without a code deployment.
61+
- The application must keep a constrained vocabulary of approved conditions and actions.
62+
- Support needs to answer “why did this decision happen?” with a trace, not a guess.
63+
- Backend and browser code need the same deterministic rule definition.
64+
65+
The point is not to be more abstract. The point is to make dynamic logic safer.
66+
67+
## When json-rules-engine is the better fit
68+
69+
Keep or choose `json-rules-engine` when:
70+
71+
- facts, events, and priorities match your mental model,
72+
- your current rule assets are stable,
73+
- the team values ecosystem familiarity over a different contract,
74+
- validation and explanation can remain project-owned,
75+
- migration would add risk without real operational gain.
76+
77+
A migration that does not improve safety, clarity, or operating speed is not engineering. It is churn.
78+
79+
## Migration pattern
80+
81+
Do not translate keywords mechanically. Translate the decision.
82+
83+
A `json-rules-engine` rule often looks like this:
84+
85+
```json
86+
{
87+
"conditions": {
88+
"all": [
89+
{ "fact": "customerTier", "operator": "equal", "value": "gold" },
90+
{ "fact": "cartTotal", "operator": "greaterThanInclusive", "value": 100 }
91+
]
92+
},
93+
"event": {
94+
"type": "apply-discount",
95+
"params": { "percent": 15 }
96+
}
97+
}
98+
```
99+
100+
In Neuron-JS, the same business decision becomes a script with explicit rule, condition, parameter, and action types:
101+
102+
```json
103+
{
104+
"id": "gold-customer-discount",
105+
"rules": [
106+
{
107+
"id": "gold-order-over-threshold",
108+
"type": "simple_rule",
109+
"options": {},
110+
"conditions": [
111+
{
112+
"id": "cart-total-threshold",
113+
"type": "compare_two_numbers",
114+
"options": {},
115+
"params": [
116+
{ "id": "cart-total", "name": "op1", "type": "simple_number", "value": "125", "options": {} },
117+
{ "id": "comparison", "name": "comp", "type": "comparator", "value": ">=", "options": {} },
118+
{ "id": "threshold", "name": "op2", "type": "simple_number", "value": "100", "options": {} }
119+
]
120+
}
121+
],
122+
"actions": [
123+
{
124+
"id": "discount-score",
125+
"type": "add_two_numbers",
126+
"options": {},
127+
"params": [
128+
{ "id": "base-discount", "name": "op1", "type": "simple_number", "value": "10", "options": {} },
129+
{ "id": "tier-bonus", "name": "op2", "type": "simple_number", "value": "5", "options": {} }
130+
]
131+
}
132+
]
133+
}
134+
]
135+
}
136+
```
137+
138+
Then validate and explain it:
139+
140+
```typescript
141+
import {
142+
Neuron,
143+
Synapse,
144+
explainExecution,
145+
summarizeExecutionOutput,
146+
validateExecutionContext,
147+
validateScript,
148+
} from '@sebasoft/neuron-js';
149+
150+
const context = { messages: [], state: { customerTier: 'gold', cartTotal: 125 } };
151+
152+
const scriptValidation = validateScript(script);
153+
const contextValidation = validateExecutionContext(context);
154+
155+
if (!scriptValidation.ok || !contextValidation.ok) {
156+
throw new Error('Invalid migrated rule input');
157+
}
158+
159+
const result = new Synapse(new Neuron()).execute(script, context);
160+
const output = summarizeExecutionOutput(result);
161+
const explanation = explainExecution({ script, result });
162+
```
163+
164+
## Migration checklist
165+
166+
- Map each fact to a parameter or context field.
167+
- Map each operator to an approved condition type.
168+
- Map each event to an approved action type.
169+
- Preserve rule order, priority, and conflict behavior with tests.
170+
- Validate every migrated script before execution.
171+
- Snapshot explanation traces for high-value rules.
172+
- Keep `json-rules-engine` if the existing model is already doing the job cleanly.
173+
174+
## Documentation
175+
176+
The full migration page is here:
177+
178+
[Neuron-JS vs json-rules-engine](https://sebasoft.github.io/neuron-js/comparisons/json-rules-engine.html)
179+
180+
Start with the comparison hub if you are deciding between multiple rules approaches:
181+
182+
[Neuron-JS comparison and migration guides](https://sebasoft.github.io/neuron-js/comparisons/)
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# Drafting fields
2+
3+
Title: Neuron-JS vs JsonLogic: predicate format or TypeScript rules engine?
4+
5+
Alias: neuron-js-vs-jsonlogic
6+
7+
Description: A practical guide for deciding between JsonLogic and Neuron-JS when JSON predicates grow into validated, explainable TypeScript business decisions.
8+
9+
Tags: neuron-js, jsonlogic, json-logic-js, typescript, rules-engine, migration, ai-agents
10+
11+
# Markdown body
12+
13+
## The short version
14+
15+
JsonLogic is excellent when the problem is a portable JSON predicate.
16+
17+
Neuron-JS is a better fit when that predicate has grown into a business decision that needs an owned TypeScript vocabulary, validation before runtime, approved actions, and explanation after execution.
18+
19+
The clean rule is this:
20+
21+
- Use JsonLogic for compact boolean logic.
22+
- Use Neuron-JS for governed JSON business decisions.
23+
24+
Both are useful. They solve different pressure points.
25+
26+
## JsonLogic is not the enemy
27+
28+
JsonLogic earned its place because it is small and portable. A rule like this is easy to store, transmit, and evaluate:
29+
30+
```json
31+
{
32+
"and": [
33+
{ ">=": [{ "var": "cart.total" }, 100] },
34+
{ "==": [{ "var": "customer.tier" }, "gold"] }
35+
]
36+
}
37+
```
38+
39+
That is a strong shape when the output is mostly true or false.
40+
41+
It becomes weaker when the system needs named rule components, approved actions, review workflows, generated rule validation, or explanation traces.
42+
43+
That is where Neuron-JS belongs.
44+
45+
## Where Neuron-JS changes the model
46+
47+
Neuron-JS does not only ask “is this predicate true?”
48+
49+
It asks:
50+
51+
- Is this script structurally valid?
52+
- Are the condition and action types approved by the application?
53+
- Can the runtime execute it deterministically?
54+
- Can the result be summarized?
55+
- Can a human review why it happened?
56+
57+
That is the difference between a predicate format and a rules engine contract.
58+
59+
## When to stay with JsonLogic
60+
61+
Stay with JsonLogic when:
62+
63+
- the rule is a compact boolean expression,
64+
- cross-language portability is the main requirement,
65+
- the team already has stable JsonLogic rules and operators,
66+
- the decision does not need approved actions,
67+
- validation and explanation can remain project-owned.
68+
69+
Do not migrate a clean predicate just to use a larger abstraction.
70+
71+
## When to move to Neuron-JS
72+
73+
Move to Neuron-JS when the rule becomes product logic.
74+
75+
Good triggers:
76+
77+
- business rules are edited or reviewed outside normal deployments,
78+
- AI agents generate rules and malformed JSON must be rejected safely,
79+
- the rule needs conditions and actions, not only true or false,
80+
- support or audit teams need explanation traces,
81+
- frontend and backend code need the same TypeScript-owned rule vocabulary.
82+
83+
## Migration pattern
84+
85+
Start by separating the predicate from the business action.
86+
87+
JsonLogic predicate:
88+
89+
```json
90+
{
91+
"and": [
92+
{ ">=": [{ "var": "cart.total" }, 100] },
93+
{ "==": [{ "var": "customer.tier" }, "gold"] }
94+
]
95+
}
96+
```
97+
98+
Neuron-JS script:
99+
100+
```json
101+
{
102+
"id": "gold-cart-eligibility",
103+
"rules": [
104+
{
105+
"id": "cart-over-threshold",
106+
"type": "simple_rule",
107+
"options": {},
108+
"conditions": [
109+
{
110+
"id": "cart-total-check",
111+
"type": "compare_two_numbers",
112+
"options": {},
113+
"params": [
114+
{ "id": "cart-total", "name": "op1", "type": "simple_number", "value": "125", "options": {} },
115+
{ "id": "operator", "name": "comp", "type": "comparator", "value": ">=", "options": {} },
116+
{ "id": "minimum", "name": "op2", "type": "simple_number", "value": "100", "options": {} }
117+
]
118+
}
119+
],
120+
"actions": [
121+
{
122+
"id": "eligibility-score",
123+
"type": "add_two_numbers",
124+
"options": {},
125+
"params": [
126+
{ "id": "base-score", "name": "op1", "type": "simple_number", "value": "1", "options": {} },
127+
{ "id": "tier-score", "name": "op2", "type": "simple_number", "value": "1", "options": {} }
128+
]
129+
}
130+
]
131+
}
132+
]
133+
}
134+
```
135+
136+
Validation and execution:
137+
138+
```typescript
139+
import {
140+
Neuron,
141+
Synapse,
142+
explainExecution,
143+
summarizeExecutionOutput,
144+
validateExecutionContext,
145+
validateScript,
146+
} from '@sebasoft/neuron-js';
147+
148+
const context = {
149+
messages: [],
150+
state: { cart: { total: 125 }, customer: { tier: 'gold' } },
151+
};
152+
153+
const scriptValidation = validateScript(script);
154+
const contextValidation = validateExecutionContext(context);
155+
156+
if (!scriptValidation.ok || !contextValidation.ok) {
157+
throw new Error('Invalid migrated rule input');
158+
}
159+
160+
const result = new Synapse(new Neuron()).execute(script, context);
161+
const output = summarizeExecutionOutput(result);
162+
const explanation = explainExecution({ script, result });
163+
```
164+
165+
## Migration checklist
166+
167+
- Keep pure predicates in JsonLogic when portability is the point.
168+
- Move only governed business decisions into Neuron-JS.
169+
- Replace anonymous operator trees with named conditions and actions.
170+
- Preserve null, missing value, string, and number coercion behavior in tests.
171+
- Validate scripts before runtime.
172+
- Use explanation traces for reviewer confidence.
173+
174+
## Documentation
175+
176+
Full guide:
177+
178+
[Neuron-JS vs JsonLogic / json-logic-js](https://sebasoft.github.io/neuron-js/comparisons/json-logic-js.html)
179+
180+
Comparison hub:
181+
182+
[Neuron-JS comparison and migration guides](https://sebasoft.github.io/neuron-js/comparisons/)

0 commit comments

Comments
 (0)