A modern, full-stack chatbot application built with React, TypeScript, and Node.js that integrates with BotDojo for supplement discovery and health recommendations.
- Real-time Chat: Interactive conversation with AI assistant
- Product Recommendations: Structured product suggestions with images and descriptions
- Suggested Questions: Dynamic follow-up questions based on context
- Structured Content: Support for guides, FAQs, lab results, images, and link lists
- Sidebar Navigation: Detailed view of recommendations and structured content
- TypeScript: Full type safety across frontend and backend
- Modular Architecture: Clean separation of concerns with services, utilities, and components
- Error Handling: Comprehensive error boundaries and logging
- Input Validation: Sanitization and validation for all user inputs
- Caching: Intelligent caching of BotDojo responses for improved performance
- Rate Limiting: Protection against abuse and excessive requests
- Security: Helmet.js security headers and CORS configuration
- Accessibility: ARIA labels, keyboard navigation, and screen reader support
- Testing: Unit tests for critical functions and API endpoints
- API Documentation: OpenAPI/Swagger specification
src/
βββ components/ # Reusable UI components
βββ contexts/ # React Context for state management
βββ types.ts # TypeScript type definitions
βββ App.tsx # Main application component
server/
βββ src/
β βββ config/ # Environment and configuration
β βββ services/ # Business logic services
β βββ utils/ # Utility functions
β βββ types/ # TypeScript type definitions
β βββ app.ts # Express application setup
βββ docs/ # API documentation
βββ dist/ # Compiled JavaScript
- Node.js 18+
- npm or yarn
- BotDojo API credentials
Create a .env file in the server directory:
# BotDojo Configuration
BOTDOJO_API_KEY=your_api_key_here
BOTDOJO_BASE_URL=https://api.botdojo.com
BOTDOJO_ACCOUNT_ID=your_account_id
BOTDOJO_PROJECT_ID=your_project_id
BOTDOJO_FLOW_ID=your_flow_id
# Server Configuration
PORT=3001
NODE_ENV=development
CORS_ORIGINS=http://localhost:5173,http://127.0.0.1:5173
# Cache Configuration
CACHE_TTL=300
CACHE_MAX_KEYS=1000
# Media Configuration
MEDIA_BASE=https://uat.gethealthy.store-
Clone the repository
git clone <repository-url> cd custom-chatbot-react
-
Install frontend dependencies
npm install
-
Install server dependencies
cd server npm install -
Build the frontend
npm run build
-
Start the development server
cd server npm run dev
# Start development server
npm run dev
# Type checking
npm run typecheck
# Linting
npm run lint
# Build for production
npm run buildcd server
# Start development server with TypeScript
npm run dev
# Build TypeScript
npm run build
# Start production server
npm run start
# Type checking
npm run typecheck
# Run tests
npm test
# Run tests with coverage
npm run test:coverageThe API is fully documented with OpenAPI/Swagger specification available at:
- Development:
http://localhost:3001/docs(if Swagger UI is configured) - Specification:
server/docs/openapi.yaml
POST /chat- Send messages to the chatbotPOST /suggestions- Get suggested follow-up questionsPOST /debug-botdojo- Debug BotDojo API responsesPOST /test-structured- Test structured content typesGET /health- Health check with cache statisticsGET /cache/stats- Cache performance metricsPOST /cache/clear- Clear all cached data
npm testcd server
npm test
npm run test:coverageThe application includes comprehensive test coverage for:
- BotDojo service integration
- Canvas data parsing
- Media utilities
- Error handling
- Input validation
- TTL: 5 minutes (300 seconds) for BotDojo responses
- Max Keys: 1000 cached items
- Hit Rate: Monitor via
/cache/statsendpoint
- Window: 15 minutes
- Max Requests: 100 per IP
- Endpoints:
/chat,/suggestions
- Helmet.js: Security headers
- CORS: Configurable origins
- Input Validation: All inputs sanitized
- Error Handling: No sensitive data exposure
- ARIA Labels: Screen reader support
- Keyboard Navigation: Full keyboard accessibility
- Focus Management: Proper focus indicators
- Color Contrast: WCAG compliant colors
- Mobile First: Optimized for mobile devices
- Dark Mode: Toggle between light and dark themes
- Flexible Layout: Adapts to different screen sizes
- Typing Indicators: Visual feedback during responses
- Message History: Persistent conversation state
- Error Recovery: Graceful error handling
- Loading States: Clear loading indicators
- Winston: Structured logging with multiple transports
- Request Tracking: Unique request IDs for debugging
- Performance Metrics: Response time monitoring
- Error Tracking: Comprehensive error logging
- Dependency Validation: BotDojo API connectivity
- Cache Statistics: Performance metrics
- Memory Usage: Resource monitoring
- React Context: Centralized state management
- Reducer Pattern: Predictable state updates
- Type Safety: Full TypeScript integration
- Stateless Design: No server-side session storage
- Cache Layer: Redis-like in-memory caching
- Configuration: Environment-based settings
# Frontend
npm run build
# Backend
cd server
npm run build
npm run start# Use the provided Dockerfile
docker build -t chatbot-app .
docker run -p 3001:3001 chatbot-appEnsure all required environment variables are set in production:
- BotDojo API credentials
- CORS origins
- Cache settings
- Logging configuration
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
- TypeScript: Strict type checking enabled
- ESLint: Code quality enforcement
- Prettier: Code formatting
- Testing: Unit tests for new features
- β Modular server architecture
- β TypeScript integration
- β Comprehensive error handling
- β Input validation and sanitization
- β Unit testing framework
- β Response caching
- β Rate limiting
- β Context API state management
- β OpenAPI documentation
- β Accessibility improvements
- β Performance optimizations
-
BotDojo API Errors
- Verify API credentials in environment variables
- Check network connectivity
- Review API rate limits
-
Cache Issues
- Clear cache via
/cache/clearendpoint - Monitor cache statistics
- Adjust TTL settings if needed
- Clear cache via
-
Build Errors
- Ensure Node.js version 18+
- Clear node_modules and reinstall
- Check TypeScript configuration
Enable debug mode in the UI settings to see:
- Raw BotDojo API responses
- Request/response details
- Cache hit/miss information
This project is licensed under the MIT License - see the LICENSE file for details.
- BotDojo for AI integration
- React and TypeScript communities
- Express.js and Node.js ecosystems
- Open source contributors