Skip to content

Commit caf5d8e

Browse files
authored
Merge pull request #4 from SebaSOFT/growth/njs-growth-01-reposition-public-surface
NJS-GROWTH-01: Reposition public surface
2 parents 864e392 + df4be85 commit caf5d8e

5 files changed

Lines changed: 196 additions & 75 deletions

File tree

README.md

Lines changed: 74 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,49 @@
44

55
# neuron-js
66

7-
> **A pluggable, serializable rules engine for functional programming rulesets.**
7+
> **AI-friendly TypeScript rules engine for serializable JSON business rules and deterministic workflow decisions.**
88
99
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
1010
[![Socket Badge](https://badge.socket.dev/npm/package/@sebasoft/neuron-js)](https://socket.dev/npm/package/@sebasoft/neuron-js)
1111
[![Node.js Version](https://img.shields.io/badge/node-%3E%3D24.0.0-blue.svg)](https://nodejs.org)
1212
[![Build Status](https://github.com/SebaSOFT/neuron-js/actions/workflows/ci.yml/badge.svg)](https://github.com/SebaSOFT/neuron-js/actions)
1313

14-
`neuron-js` is a lightweight, extensible rules engine designed to execute functional programming logic for other applications in a strictly serializable format. It uses a registry-based architecture—using **Neuron** for component management and **Synapse** as the execution engine—allowing you to build, store, and run complex functional rulesets that remain pure JSON.
14+
`neuron-js` lets teams define business rules and workflow decisions as pure JSON, execute them deterministically in Node.js or the browser, and extend the rule vocabulary with TypeScript actions, conditions, parameters, rules, and lifecycle hooks.
1515

16-
Perfect for dynamic business rules, automation workflows, and cross-application decision logic.
16+
Use it when hardcoded `if/else` logic is too rigid, but a heavyweight workflow or BPMN platform is too much machinery.
17+
18+
## Links
19+
20+
- Documentation: <https://sebasoft.github.io/neuron-js/>
21+
- npm: <https://www.npmjs.com/package/@sebasoft/neuron-js>
22+
- GitHub: <https://github.com/SebaSOFT/neuron-js>
23+
- Examples: planned under `examples/` as `NJS-GROWTH-02`
24+
- Schemas and validation docs: planned as `NJS-GROWTH-03`
25+
- AI-readable docs: planned as `NJS-GROWTH-04`
26+
27+
---
28+
29+
## Why neuron-js?
30+
31+
Use `neuron-js` when:
32+
33+
- Business rules need to be stored, versioned, audited, or changed without redeploying code.
34+
- Backend and frontend code need to share the same deterministic rule definitions.
35+
- AI assistants or workflow tools generate JSON rules that still need developer-owned validation and execution boundaries.
36+
- Product, pricing, eligibility, routing, or automation decisions change faster than application deployments.
37+
- A full workflow platform is too heavy, but hardcoded conditional logic is too brittle.
38+
39+
Do not use `neuron-js` when a simple hardcoded condition is clearer and rarely changes, when arbitrary user code execution is required, or when you need a full BPMN/process orchestration platform.
1740

1841
---
1942

2043
## ✨ Features
2144

22-
- 🛠 **Pluggable Architecture**: Easily register custom Actions, Conditions, and Parameters.
23-
- 📦 **JSON Serializable**: Logic scripts are pure JSON, perfect for database storage or remote transmission.
24-
-**Modern Toolchain**: Built with Node 24, TypeScript, Biome, and Vitest.
25-
- 🌓 **Dual-Module Support**: Native ESM and CommonJS support via `tshy`.
26-
- 🪝 **Lifecycle Hooks**: Comprehensive hook system for monitoring and side-effect management.
45+
- 🛠 **Pluggable TypeScript registry**: Register custom Actions, Conditions, Parameters, and Rules.
46+
- 📦 **JSON business rules**: Store, transmit, version, and audit logic as serializable JSON.
47+
-**Deterministic execution**: Run predictable workflow and business decisions in Node.js or the browser.
48+
- 🪝 **Lifecycle hooks**: Monitor script, rule, action, and error events around execution.
49+
- 🌓 **Dual-module support**: Native ESM and CommonJS bundles via `tshy`.
2750

2851
---
2952

@@ -37,83 +60,86 @@ yarn add @sebasoft/neuron-js
3760
npm install @sebasoft/neuron-js
3861
```
3962

40-
### Basic Usage
63+
### Executable rule example
4164

4265
```typescript
4366
import { Neuron, Synapse } from '@sebasoft/neuron-js';
4467

45-
// 1. Initialize the registry
4668
const neuron = new Neuron();
47-
48-
// 2. Setup the engine
4969
const synapse = new Synapse(neuron);
5070

51-
// 3. Define your logic script (JSON-serializable)
5271
const script = {
53-
id: 'hello-script',
72+
id: 'pricing-decision',
5473
rules: [
5574
{
56-
id: 'rule-1',
75+
id: 'vip-discount-rule',
5776
type: 'simple_rule',
5877
options: {},
5978
conditions: [
6079
{
61-
id: 'is-positive',
80+
id: 'minimum-order-value',
6281
type: 'compare_two_numbers',
82+
options: {},
6383
params: [
64-
{ name: 'op1', type: 'simple_number', value: '10' },
65-
{ name: 'comp', type: 'comparator', value: '>' },
66-
{ name: 'op2', type: 'simple_number', value: '0' }
84+
{ id: 'order-total', name: 'op1', type: 'simple_number', value: '125', options: {} },
85+
{ id: 'comparison', name: 'comp', type: 'comparator', value: '>', options: {} },
86+
{ id: 'threshold', name: 'op2', type: 'simple_number', value: '100', options: {} }
6787
]
6888
}
6989
],
7090
actions: [
7191
{
72-
id: 'add-log',
92+
id: 'calculate-discount',
7393
type: 'add_two_numbers',
94+
options: {},
7495
params: [
75-
{ name: 'op1', type: 'simple_number', value: '5' },
76-
{ name: 'op2', type: 'simple_number', value: '5' }
96+
{ id: 'base-discount', name: 'op1', type: 'simple_number', value: '10', options: {} },
97+
{ id: 'vip-bonus', name: 'op2', type: 'simple_number', value: '5', options: {} }
7798
]
7899
}
79100
]
80101
}
81102
]
82103
};
83104

84-
// 4. Execute
85105
const context = { messages: [], state: {} };
86106
const result = synapse.execute(script, context);
87107

88108
console.log(result.isSuccessful()); // true
89-
console.log(result.value); // 1 (number of rules executed)
109+
console.log(result.value); // 1 rule executed
110+
console.log(result.context.messages.map((message) => message.text)); // includes "Sum result: 15"
90111
```
91112

92113
---
93114

94115
## 🧬 Core Concepts
95116

96-
### Neuron (The Registry)
97-
The `Neuron` acts as the central hub where all element types (Actions, Conditions, Parameters, Rules) are registered. It ensures the runtime knows how to instantiate any element defined in your scripts.
117+
### Neuron: the registry
118+
119+
The `Neuron` registry knows which parameter, condition, action, and rule types are available. Applications keep control of this registry so generated or stored JSON can only use developer-approved capabilities.
120+
121+
### Synapse: the executor
98122

99-
### Synapse (The Executor)
100-
The `Synapse` is the engine that connects a `Neuron` registry to an `ExecutionScript`. It traverses the logic and manages the flow of the `ExecutionContext`.
123+
The `Synapse` engine connects a `Neuron` registry with a serializable script and an execution context. It evaluates rules, applies actions, and emits lifecycle hooks.
101124

102125
### Rule
126+
103127
A Rule is a logical unit containing conditions and actions.
104-
- **No Conditions**: If a rule has no conditions, it is an **"Always"** rule and will execute its actions on every run.
105-
- **No Actions**: If a rule has no actions, it will **"Do Nothing"**—it evaluates conditions but performs no operations.
128+
129+
- **No Conditions**: the rule is treated as always eligible.
130+
- **No Actions**: the rule evaluates conditions but performs no operation.
106131

107132
### Elements
108-
- **Action**: An operation to perform (e.g., "SendEmail", "UpdateDatabase").
109-
- **Condition**: A logical predicate (e.g., "UserIsAdmin", "ValueIsGreaterThanX").
110-
- **Parameter**: Configurable inputs for elements, enabling reusable logic templates.
133+
134+
- **Action**: An operation to perform, such as writing to context, calculating a value, or triggering an approved side effect.
135+
- **Condition**: A predicate that decides whether a rule should run.
136+
- **Parameter**: A serializable input for actions and conditions.
111137

112138
---
113139

114140
## 💾 Execution Context & State
115141

116-
The `ExecutionContext` is a shared state object that persists throughout the entire execution of a script. It allows Actions and Conditions to communicate and share data.
142+
The `ExecutionContext` is a shared state object that persists through script execution. Actions and conditions can read from it, and actions can return updated context for later rules.
117143

118144
```typescript
119145
interface ExecutionContext {
@@ -122,22 +148,24 @@ interface ExecutionContext {
122148
}
123149
```
124150

125-
### Using State in Actions
126-
Actions can read from the context and return an updated context to pass information to subsequent rules.
151+
---
127152

128-
```typescript
129-
// Example: An action that stores a value in the state
130-
execute(context: ExecutionContext): ExecutionResult {
131-
const newState = { ...context.state, lastCalculation: 42 };
132-
return new ExecutionResult(true, { ...context, state: newState });
133-
}
134-
```
153+
## Roadmap-aligned docs
154+
155+
The current public surface focuses on installation, positioning, core concepts, and runtime architecture.
156+
157+
Planned next adoption assets:
158+
159+
- Runnable examples: `NJS-GROWTH-02`
160+
- JSON Schemas, validation, and explain output: `NJS-GROWTH-03`
161+
- `llms.txt` and AI-assistant documentation: `NJS-GROWTH-04`
162+
- Comparison and migration pages: `NJS-GROWTH-05`
135163

136164
---
137165

138166
## 🛠 Development
139167

140-
We use a modern toolchain for high performance and developer ergonomics:
168+
We use a modern toolchain for high-signal development:
141169

142170
- **Linting & Formatting**: [Biome](https://biomejs.dev/)
143171
- **Testing**: [Vitest](https://vitest.dev/)
@@ -148,8 +176,9 @@ We use a modern toolchain for high performance and developer ergonomics:
148176

149177
```bash
150178
yarn test # Run test suite
151-
yarn lint # Check for linting issues
179+
yarn lint # Check linting and formatting
152180
yarn build # Generate ESM/CJS bundles
181+
yarn docs:build # Build API docs and VitePress site
153182
```
154183

155184
---

docs/.vitepress/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { defineConfig } from 'vitepress'
22

33
export default defineConfig({
44
title: "neuron-js",
5-
description: "Pluggable rules engine",
5+
description: "AI-friendly TypeScript rules engine for serializable JSON business rules and deterministic workflow decisions.",
66
base: '/neuron-js/',
77
ignoreDeadLinks: true,
88
themeConfig: {

docs/index.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ layout: home
33

44
hero:
55
name: neuron-js
6-
text: Pluggable, serializable rules engine
7-
tagline: Functional logic in pure JSON.
6+
text: AI-friendly TypeScript rules engine
7+
tagline: Serializable JSON business rules for deterministic workflow decisions.
88
image:
99
src: /img/neuron-cover640.png
1010
alt: neuron-js logo
@@ -17,10 +17,12 @@ hero:
1717
link: https://github.com/SebaSOFT/neuron-js
1818

1919
features:
20-
- title: Pluggable
21-
details: Easily extend the engine with custom actions and conditions.
22-
- title: Serializable
23-
details: Define logic in pure JSON, store it in a database, and execute it anywhere.
24-
- title: Modern
25-
details: Built with TypeScript, support for Node.js and browser environments.
20+
- title: JSON business rules
21+
details: Store, version, transmit, and audit rule definitions as serializable JSON.
22+
- title: Deterministic decisions
23+
details: Execute predictable workflow and business decisions in Node.js or the browser.
24+
- title: TypeScript extensibility
25+
details: Register custom actions, conditions, parameters, rules, and lifecycle hooks.
26+
- title: AI-friendly surface
27+
details: Designed for generated rules, future schema validation, explainability, and coding-assistant workflows.
2628
---

docs/overview.md

Lines changed: 85 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,94 @@
1-
# neuron-js: Pluggable Execution Runtime
1+
# neuron-js: AI-friendly TypeScript rules engine
22

3-
`neuron-js` is a lightweight, extensible, and JSON-serializable execution engine for JavaScript. It allows developers to define complex logic flows (functional scripts) that can be stored in a database, transmitted over the wire, and executed consistently in both Node.js and browser environments.
3+
`neuron-js` is a lightweight TypeScript rules engine for serializable JSON business rules and deterministic workflow decisions.
44

5-
## The Problem
6-
Hardcoding business logic often leads to rigid systems that are difficult to update without a full deployment. Workflow engines are often heavy, difficult to integrate, or use proprietary formats.
5+
It lets teams define logic as structured data, execute that logic through a developer-owned registry, and run the same deterministic rules in Node.js or the browser.
76

8-
## The Solution
9-
`neuron-js` provides a registry-based approach to execution logic:
10-
- **Neuron (Registry)**: Stores the definitions of what is possible (Actions, Conditions, Rules, Parameters).
11-
- **Synapse (Engine)**: Executes specific scripts by coordinating these definitions in a logical flow.
7+
## The problem
128

13-
By keeping the script format strictly serializable (JSON), `neuron-js` enables:
14-
- **Dynamic Logic**: Change business rules at runtime without redeploying code.
15-
- **Portability**: The same logic can run on a backend server or in a client's browser.
16-
- **Extensibility**: Easily add new capabilities by implementing simple Action or Condition interfaces.
9+
Hardcoded business logic is fast at first, but it becomes rigid when product, compliance, pricing, routing, eligibility, or workflow rules change often.
1710

18-
## Release Classification
19-
The `0.4.0` release is a **minor capability release**, not a major breaking change.
11+
Heavy workflow engines solve configurability, but they can add operational weight, proprietary formats, and integration overhead.
12+
13+
## The solution
14+
15+
`neuron-js` keeps business logic as JSON and executes it through a TypeScript registry.
16+
17+
- **Neuron** defines what is allowed: parameters, conditions, actions, and rules.
18+
- **Synapse** executes a serializable script against an execution context.
19+
- **ExecutionContext** carries shared state and messages through the run.
20+
- **Lifecycle hooks** expose script, rule, action, and error events for observability.
21+
22+
This gives applications configurable logic without giving up deterministic execution or developer-owned boundaries.
23+
24+
## Use neuron-js when
25+
26+
- Rules must be stored in a database or versioned in Git.
27+
- Product teams need configurable logic without redeploying code.
28+
- AI-generated rules need validation and approved execution boundaries before runtime.
29+
- Frontend and backend code need to share deterministic decisions.
30+
- Workflow automation needs a predictable decision node instead of probabilistic LLM branching.
31+
- A full BPMN/workflow platform is too heavy for the problem.
32+
33+
## Do not use neuron-js when
34+
35+
- A simple hardcoded condition is clearer and rarely changes.
36+
- Arbitrary user code execution is required.
37+
- You need a full BPMN/process orchestration platform.
38+
- Non-technical users need unrestricted rule authoring without validation, tests, review, and rollback.
39+
40+
## Core architecture
41+
42+
### Neuron: registry
43+
44+
The `Neuron` registry owns the vocabulary of executable elements. By default, it registers built-in parameters, conditions, actions, and rules. Applications can register custom types to expose only approved capabilities.
45+
46+
### Synapse: execution engine
47+
48+
`Synapse` receives a `Neuron`, a serializable script, and an execution context. It evaluates rules, executes actions, and returns an execution result.
49+
50+
### Script
51+
52+
A script is a serializable collection of rules. It can be stored, transmitted, reviewed, and versioned as JSON.
53+
54+
### Rule
55+
56+
A rule combines conditions and actions. Conditions decide whether the rule should run. Actions perform the approved operation.
57+
58+
### Context
59+
60+
The execution context stores messages and shared state for the run. Actions can return updated context for later rules.
61+
62+
### Hooks
63+
64+
Lifecycle hooks let applications monitor execution without embedding observability directly into rule definitions.
65+
66+
## Release classification
67+
68+
The `0.4.0` release is a minor capability release, not a major breaking change.
2069

2170
It expands the documented public API, adds extension base classes, makes missing `options` objects safe at runtime, and cleans package output. Existing JSON script behavior remains compatible; the release gives consumers more stable imports and clearer plugin ergonomics.
2271

23-
## Key Features
24-
- **JSON Serializable**: Logic is data.
25-
- **Shared Context**: State is managed and passed through the execution chain.
26-
- **Logical Grouping**: Complex AND/OR condition logic is supported out of the box.
27-
- **Lifecycle Hooks**: Monitor and react to every step of the execution.
72+
## Current and planned adoption assets
73+
74+
Available now:
75+
76+
- npm package: `@sebasoft/neuron-js`
77+
- GitHub repository: <https://github.com/SebaSOFT/neuron-js>
78+
- Documentation site: <https://sebasoft.github.io/neuron-js/>
79+
- Core concepts and use-case documentation in this site
80+
81+
Planned next:
82+
83+
- Runnable examples: `NJS-GROWTH-02`
84+
- JSON Schemas, validation, and explain output: `NJS-GROWTH-03`
85+
- `llms.txt` and AI-assistant documentation: `NJS-GROWTH-04`
86+
- Comparison and migration pages: `NJS-GROWTH-05`
87+
88+
## Key features
89+
90+
- **JSON Serializable**: Logic is data that can be stored, transmitted, and audited.
91+
- **Shared Context**: State and messages pass through the execution chain.
92+
- **Logical Grouping**: AND/OR condition logic is supported by the rule model.
93+
- **Lifecycle Hooks**: Observe execution at script, rule, action, and error boundaries.
2894
- **Type Safe**: Built with TypeScript for a robust developer experience.

0 commit comments

Comments
 (0)