A comprehensive AI-powered chat and workflow backend system with multiple integration options including Flutter frontend, n8n workflows, and direct API access.
- Python 3.8 or higher
- Git
- (Optional) Flutter for mobile app integration
- (Optional) n8n for workflow automation
git clone https://github.com/juinc/project-hack.git
cd project-hackpip install -r requirements_api.txt# Run the setup script to create .env file
python setup.pyOr manually create a .env file with:
LLM_KEY=your_openrouter_api_key_here
LLM_MODEL=openai/gpt-3.5-turbo# Start the main API server
python api.py
# Or start the workflow backend
python workflow_backend.py
# Or start the local backend
python local_backend.pyapi.py- Main Flask API server with OpenRouter integrationworkflow_backend.py- Backend optimized for n8n workflow integrationlocal_backend.py- Local development backendchat.py- Simple command-line chat interface
n8n_api.py- n8n workflow integrationpdf_learning_backend.py- PDF document processing backendtest_flutter_integration.py- Flutter integration testing
setup.py- Automated environment setuprequirements_api.txt- Python dependenciesenv_example.txt- Environment variables template
test_*.py- Various test files for different componentsdebug_api.py- API debugging utilitiesquick_test.py- Quick functionality tests
Port: 5000 (default) Endpoints:
POST /chat- Send message and get AI responseGET /health- Health checkPOST /upload- File upload support
# Start main API
python api.pyPort: 5001 (default) Features:
- Optimized for n8n integration
- Request/response logging
- Session management
# Start workflow backend
python workflow_backend.pyPort: 5002 (default) Features:
- Local development server
- Enhanced debugging
- CORS enabled
# Start local backend
python local_backend.pyInteractive command-line chat interface:
# Start CLI chat
python chat.pyThe project includes Flutter integration for mobile apps:
- See
FLUTTER_INTEGRATION_GUIDE.mdfor detailed setup - API service handles all backend communication
- Real-time chat functionality
For workflow automation:
- Use
workflow_backend.pyfor n8n integration - Configure webhooks in n8n to point to your backend
- Supports complex workflow scenarios
Simple HTTP requests to the API:
# Test the API
curl -X POST http://localhost:5000/chat \
-H "Content-Type: application/json" \
-d '{"message": "Hello, AI!"}'# Test API functionality
python test_api.py
# Test Flutter integration
python test_flutter_integration.py
# Test n8n integration
python test_n8n.py
# Test PDF learning
python test_pdf_learning.py
# Quick functionality test
python quick_test.py# Run with debug information
python debug_api.py- Navigate to the Flutter project directory
- Run
flutter pub get - Update API endpoints in
lib/services/api_service.dart - Run
flutter run
The Flutter app includes a complete API service with:
- Chat functionality
- File upload support
- Health check monitoring
- Error handling
- Start the workflow backend:
python workflow_backend.py - Configure n8n webhook nodes to point to your backend
- Use the provided workflow templates
- Request/response logging
- Session management
- Error handling
- Custom system prompts
-
API Key Not Found
- Check your
.envfile - Ensure
API_KEYis set correctly
- Check your
-
Port Already in Use
- Change port in the respective Python files
- Or kill existing processes using the port
-
CORS Issues
- All backends have CORS enabled
- Check your frontend URL configuration
-
Model Not Available
- Check model availability
- Try a different model in your
.envfile
# Check API health
curl http://localhost:5000/health
# Test with verbose output
python debug_api.py
# Check environment variables
python test_key.pyGET /health- Basic health checkGET /status- Detailed status informationGET /logs- Recent request logs
All backends include comprehensive logging:
- Request/response logging
- Error tracking
- Performance monitoring
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is open source and available under the MIT License.
For issues and questions:
- Check the troubleshooting section
- Review the test files for examples
- Check the Flutter integration guide
- Open an issue on GitHub
Happy Hacking! π