Skip to content

ita004/bitespeed-chatbot-flow-builder

Repository files navigation

Chatbot Flow Builder

A modern, intuitive visual flow builder for creating chatbot conversations. Built with React, TypeScript, and React Flow.

πŸ”— Live Demo: Live Demo

πŸ“‹ Table of Contents

✨ Features

Core Functionality

  • Drag and Drop Interface: Intuitive node placement on canvas
  • Visual Connection System: Connect nodes with visual edges to define conversation flow
  • Real-time Editing: Edit message content with instant visual feedback
  • Flow Validation: Smart validation ensures proper chatbot flow structure
  • Auto-Save to localStorage: Flow automatically persists and restores on page refresh
  • Responsive Design: Works seamlessly across different screen sizes

Technical Highlights

  • TypeScript: Full type safety across the application
  • Custom React Hooks: Reusable logic with useFlowValidation, useNodeOperations, useFlowPersistence
  • Clean Architecture: Well-organized, maintainable codebase
  • Extensible Design: Easy to add new node types
  • Commented Code: Comprehensive documentation for future developers
  • Production Ready: Optimized build with proper error handling

πŸ“Έ Screenshots

Main Interface

  • Canvas area with draggable nodes
  • Right panel showing available node types
  • Save button with validation

Settings Panel

  • Appears when a node is selected
  • Real-time text editing
  • Easy navigation back to nodes panel

Validation

  • Success notification when flow is valid
  • Error notification with descriptive message when flow is invalid

πŸ›  Tech Stack

  • React 18 - UI Framework
  • TypeScript - Type Safety
  • React Flow - Flow visualization and management
  • Vite - Build tool and dev server
  • CSS3 - Styling with modern features

πŸ“ Project Structure

src/
β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ FlowBuilder.tsx       # Main orchestrator component
β”‚   β”œβ”€β”€ TextNode.tsx           # Custom message node component
β”‚   β”œβ”€β”€ NodesPanel.tsx         # Panel with draggable node types
β”‚   β”œβ”€β”€ SettingsPanel.tsx      # Node editing interface
β”‚   └── SaveButton.tsx         # Validation and save functionality
β”œβ”€β”€ hooks/
β”‚   β”œβ”€β”€ index.ts               # Hooks barrel export
β”‚   β”œβ”€β”€ useFlowValidation.ts   # Validation & notification logic
β”‚   β”œβ”€β”€ useNodeOperations.ts   # Node CRUD operations
β”‚   └── useFlowPersistence.ts  # localStorage save/load logic
β”œβ”€β”€ types/
β”‚   └── index.ts               # TypeScript type definitions
β”œβ”€β”€ utils/
β”‚   └── validation.ts          # Flow validation logic
β”œβ”€β”€ styles/
β”‚   β”œβ”€β”€ FlowBuilder.css        # Main canvas styles
β”‚   β”œβ”€β”€ TextNode.css           # Node styling
β”‚   β”œβ”€β”€ NodesPanel.css         # Nodes panel styling
β”‚   β”œβ”€β”€ SettingsPanel.css      # Settings panel styling
β”‚   └── SaveButton.css         # Button and notification styles
β”œβ”€β”€ App.tsx                    # Root component
β”œβ”€β”€ main.tsx                   # Application entry point
└── index.css                  # Global styles

πŸš€ Getting Started

Prerequisites

  • Node.js (v18 or higher recommended)
  • npm or yarn

Installation

  1. Clone the repository
git clone <your-repo-url>
cd chatbot-flow-builder
  1. Install dependencies
npm install
  1. Start development server
npm run dev
  1. Open browser and navigate to http://localhost:5173

Build for Production

npm run build

The production-ready files will be in the dist/ directory.

πŸ“– Usage Guide

Adding Nodes

  1. Look at the Nodes Panel on the right side
  2. Find the Message node type
  3. Drag it onto the canvas
  4. Drop it where you want it placed

Connecting Nodes

  1. Click and drag from a node's source handle (right side)
  2. Connect to another node's target handle (left side)
  3. The edge (connection) will be created
  4. Note: Each source handle can only have ONE outgoing connection

Editing Node Content

  1. Click on a node to select it
  2. The Settings Panel appears on the right
  3. Edit the text in the textarea
  4. Changes are saved automatically
  5. Click the back button to return to the Nodes Panel

Saving Your Flow

  1. Click the Save Changes button (top right)
  2. The flow will be validated
  3. You'll see either:
    • βœ“ Success message if flow is valid (automatically saved to localStorage)
    • ⚠ Error message if flow has issues

Auto-Persistence

Your flow is automatically saved and restored:

  • On Save: When you click "Save Changes" and validation passes, the flow is saved to browser localStorage
  • On Load: When you refresh the page or return later, your flow is automatically restored
  • No Setup: Everything works out of the box - no configuration needed

Note: localStorage is browser-specific and domain-specific. Your flow persists across sessions but is stored locally in your browser.

βœ… Validation Rules

The flow builder enforces one key rule:

If there are more than one nodes, then more than one node cannot have empty target handles.

What does this mean?

  • Empty Target Handle: A node with no incoming connections
  • Valid Flow: At most ONE node can have an empty target (the start node)
  • Invalid Flow: Multiple nodes with empty targets means a disconnected flow

Examples

βœ… Valid Flows:

  • Single node (no connections needed)
  • Multiple nodes where only ONE has no incoming connection
  • All nodes connected in a sequence

❌ Invalid Flows:

  • Two or more disconnected nodes
  • Multiple "start" nodes with no incoming connections

πŸ”§ Extensibility

The codebase is designed for easy extension with custom React hooks and modular architecture.

Custom Hooks

The application uses three custom hooks for clean separation of concerns:

useFlowValidation

Handles flow validation and notification state management:

const { notification, validateAndSave } = useFlowValidation();
const isValid = validateAndSave(nodes, edges);

useNodeOperations

Provides methods for node CRUD operations:

const { updateNodeData, deleteNode, duplicateNode, getNodeById } =
  useNodeOperations({ nodes, setNodes });

useFlowPersistence

Manages localStorage save/load operations:

const { saveFlow, loadFlow, clearFlow, hasStoredFlow } =
  useFlowPersistence({ nodes, edges, setNodes, setEdges });

Adding New Node Types

Here's how to add a new node type:

1. Add Node Type Constant

// src/types/index.ts
export const NodeType = {
  TEXT_MESSAGE: 'textMessage',
  IMAGE_MESSAGE: 'imageMessage', // New type
} as const;

2. Create Node Data Interface

// src/types/index.ts
export interface ImageMessageData {
  imageUrl: string;
  caption: string;
}

3. Create Node Component

// src/components/ImageNode.tsx
import { memo } from 'react';
import { Handle, Position, type NodeProps } from 'reactflow';
import type { ImageMessageData } from '../types';

const ImageNode = ({ data }: NodeProps<ImageMessageData>) => {
  return (
    <div className="image-node">
      <Handle type="target" position={Position.Left} />
      <img src={data.imageUrl} alt={data.caption} />
      <Handle type="source" position={Position.Right} />
    </div>
  );
};

export default memo(ImageNode);

4. Register Node Type

// src/components/FlowBuilder.tsx
const nodeTypes = {
  [NodeType.TEXT_MESSAGE]: TextNode,
  [NodeType.IMAGE_MESSAGE]: ImageNode, // Register new type
};

5. Add to Nodes Panel

// src/components/NodesPanel.tsx
const availableNodes: DraggableNodeType[] = [
  {
    type: NodeType.TEXT_MESSAGE,
    label: 'Message',
    icon: 'πŸ’¬',
    description: 'Send a text message'
  },
  {
    type: NodeType.IMAGE_MESSAGE,
    label: 'Image',
    icon: 'πŸ–ΌοΈ',
    description: 'Send an image'
  },
];

🌐 Deployment

Deploy to Vercel (Recommended)

  1. Install Vercel CLI
npm install -g vercel
  1. Build the project
npm run build
  1. Deploy
vercel --prod

Deploy to Netlify

  1. Build the project
npm run build
  1. Drag and drop the dist folder to Netlify Drop

Or use Netlify CLI:

npm install -g netlify-cli
netlify deploy --prod --dir=dist

Deploy to GitHub Pages

  1. Install gh-pages
npm install --save-dev gh-pages
  1. Add to package.json
{
  "homepage": "https://yourusername.github.io/chatbot-flow-builder",
  "scripts": {
    "predeploy": "npm run build",
    "deploy": "gh-pages -d dist"
  }
}
  1. Deploy
npm run deploy

πŸ“ Assignment Completion

This project was built as a submission for the BiteSpeed Frontend Task. Here's how it meets all requirements:

βœ… Required Features Implemented

  1. Text Node - Custom node component with message display
  2. Nodes Panel - Draggable panel with available node types
  3. Edge - Visual connections between nodes
  4. Source Handle - Only one edge originating from source (enforced)
  5. Target Handle - Multiple edges can connect to target
  6. Settings Panel - Replaces nodes panel when node is selected
  7. Save Button - Validates flow and shows notifications

βœ… Technical Requirements

  • βœ“ Built with React and TypeScript
  • βœ“ Uses React Flow library
  • βœ“ Code is well-commented
  • βœ“ Extensible architecture for adding new node types
  • βœ“ Proper validation logic implemented
  • βœ“ Production build works correctly

🌟 Bonus Features Implemented

Beyond the basic requirements, this submission includes:

  1. Custom React Hooks - Three reusable hooks (useFlowValidation, useNodeOperations, useFlowPersistence)
  2. Auto-Persistence - Flow automatically saves to localStorage and restores on refresh
  3. Advanced TypeScript - Full type safety with no any types
  4. Clean Architecture - Separation of concerns (components, hooks, utils, types)
  5. Professional UI/UX - Smooth animations, hover states, and visual feedback
  6. Comprehensive Documentation - Detailed README, FEATURES.md, and SUBMISSION_GUIDE.md

πŸ“¦ Submission Checklist

  • βœ“ Code hosted on GitHub
  • βœ“ Application deployed and accessible
  • βœ“ README with deployment link
  • βœ“ All features working as specified
  • βœ“ Clean, commented code
  • βœ“ TypeScript for better code quality

🀝 Contributing

This is a submission project, but suggestions are welcome! Feel free to open an issue or reach out.

πŸ“„ License

MIT License - feel free to use this code for learning and development.

πŸ‘¨β€πŸ’» Author

Built with ❀️ for the BiteSpeed Frontend Task