This repository implements a decision tree processing backend in TypeScript. It enables defining and executing business logic tailored to specific needs.
- Decision Tree Definition: Create decision trees using a JSON format.
- Node Types: Supports various node types, including:
- Condition: Evaluate JavaScript expressions and branch based on the result.
- Action: Execute predefined actions, such as sending SMS or email (placeholder implementations are provided).
- Loop: Repeat a subtree for a specified number of iterations.
- DoNothing: Represents an empty branch for conditions.
- Action Extensibility: Easily add new action types by defining them in the
actions/actions.tsfile. - Serialization & Deserialization: Supports serializing and deserializing decision trees to/from JSON format.
- Error Handling: Includes basic error handling for unknown action types and invalid JSON input.
-
Clone the repository:
git clone https://github.com/furqan-abid/decision-tree.git
-
Navigate to the project directory:
cd decision-tree-backend -
Install dependencies:
npm install
-
Run the development server:
npm run dev
This will compile the TypeScript code and start the Node.js server.
The project includes example decision trees in the root directory:
christmas-tree.json: Sends an SMS on January 1st, 2025.email-sms-tree.json: Sends an emailoptional-emails-tree.json: Loops 10 times and sends an SMS if a random condition is met.
- Make sure you have the example JSON files in the
rootdirectory. - Run the server with
npm run dev. - The console output will show the results of the executed actions.
- Add New Actions: Define new actions in
actions/actions.ts. Remember to implement theexecutefunction for each action. - Modify Node Types: You can introduce new node types as needed to handle more complex decision-making scenarios.
- Enhance Error Handling: Implement more robust error handling for potential failures, invalid input, and unexpected conditions.