Deployed Link: https://eventai-server.munymunyhom.tech/api/v1
Deployed N8N Link: https://eventai-server.munymunyhom.tech/n8n/workflow
A Node.js backend for the Event AI platform, built for AWS EC2 deployment with S3 storage and Supabase database. This server handles event management, AI-powered crowd simulation, and real-time notifications.
The server follows a modern cloud architecture using AWS and Supabase:
- AWS EC2: Virtual server hosting the Node.js application
- Express.js: Web application framework with REST API endpoints
- Amazon S3: File storage for datasets and charts
- Supabase (PostgreSQL): Event and simulation data storage
- Amazon SageMaker: AI model inference endpoint
- n8n Webhook: WhatsApp notification integration
- PM2: Process management for production deployment
- Event Management: Create, update, and manage events with file uploads
- AI Simulation: Trigger crowd flow simulations with real-time progress tracking
- Real-time Crowd Prediction: Dynamic prediction updates with support for live camera feeds
- Real-time Notifications: WhatsApp alerts via n8n workflow integration for high-priority recommendations
- File Management: Secure S3 integration for ticketing data and seating charts
- Camera Feed Integration: Support for real-time camera feeds for accurate crowd detection
- n8n Integration: Complete workflow automation for webhook processing and WhatsApp delivery
- Comprehensive Logging: Winston-based logging with request tracking
- Error Handling: Centralized error handling with proper HTTP status codes
- Security: Rate limiting, CORS, security headers, and input validation
- Database: Supabase PostgreSQL for data persistence with real-time features
event-ai-server/
βββ src/
β βββ controllers/
β β βββ eventController.js # Event management endpoints
β β βββ simulationController.js # Simulation management endpoints
β βββ services/
β β βββ s3Service.js # AWS S3 file operations
β β βββ supabaseService.js # Database operations with Supabase
β β βββ aiModelService.js # AI model integration
β β βββ notificationService.js # WhatsApp/n8n notifications
β βββ utils/
β β βββ errorHandler.js # Error handling utilities
β βββ server.js # Main Express server
βββ supabase/
β βββ schema.sql # Database schema
βββ scripts/
β βββ setup-s3.js # S3 bucket configuration
β βββ setup-supabase.js # Supabase setup and testing
βββ package.json # Dependencies and scripts
βββ ecosystem.config.js # PM2 configuration
βββ env.example # Environment variables template
- Node.js 18+
- AWS CLI configured with appropriate permissions
- PostgreSQL database (local or RDS)
- Serverless Framework CLI
- Clone and install dependencies:
git clone <repository-url>
cd event-ai-server
npm install- Configure environment variables:
cp env.example .env
# Edit .env with your actual configuration values- Set up the database:
# Generate Prisma client
npx prisma generate
# Run database migrations
npx prisma migrate dev --name init- Deploy to AWS:
# Deploy to development stage
npm run deploy
# Deploy to production
serverless deploy --stage prod# Start local development server
npm run dev
# Run with serverless offline
serverless offlineCreate a .env file based on env.example:
# AWS Configuration
AWS_REGION=us-east-1
AWS_ACCESS_KEY_ID=your_access_key
AWS_SECRET_ACCESS_KEY=your_secret_key
S3_BUCKET_NAME=event-ai-storage
# Database
DATABASE_URL=postgresql://user:password@localhost:5432/eventai_db
# AI Model
SAGEMAKER_ENDPOINT_NAME=event-ai-model-endpoint
# OR use custom API
AI_MODEL_API_URL=https://your-ai-api.com/predict
AI_MODEL_API_KEY=your_api_key
# n8n Integration (Primary notification method)
N8N_WEBHOOK_URL=https://your-n8n.com/webhook/event-ai-alert
NOTIFICATION_RECIPIENTS=+1234567890,+0987654321
# WhatsApp Direct API (Fallback method)
WHATSAPP_API_URL=https://api.whatsapp.com/send
WHATSAPP_API_KEY=your_whatsapp_api_key| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/events |
Create a new event |
| GET | /api/v1/events |
List all events (paginated) |
| GET | /api/v1/events/:eventId |
Get event details |
| PUT | /api/v1/events/:eventId |
Update an event |
| DELETE | /api/v1/events/:eventId |
Delete an event |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/simulations/run |
Start AI simulation |
| GET | /api/v1/simulations/:simulationId/status |
Get simulation status |
| GET | /api/v1/simulations/:simulationId/results |
Get simulation results |
| GET | /api/v1/simulations/:simulationId |
Get simulation details |
| DELETE | /api/v1/simulations/:simulationId |
Cancel/delete simulation |
| GET | /api/v1/simulations |
List simulations (filtered) |
Create Event:
curl -X POST https://your-api-gateway-url/api/v1/events \
-H "Content-Type: application/json" \
-d '{
"name": "Summer Music Festival",
"venue": "Central Park",
"expectedAttendees": 5000,
"eventDate": "2024-07-15T18:00:00Z",
"eventType": "festival",
"ticketingData": {...},
"seatingChart": {...}
}'Start Simulation:
curl -X POST https://your-api-gateway-url/api/v1/simulations/run \
-H "Content-Type: application/json" \
-d '{
"simulationId": "sim_12345",
"parameters": {
"crowdDensityThreshold": 0.8,
"simulationDuration": 3600,
"weatherConditions": "sunny"
}
}'- Rate Limiting: 100 requests per 15 minutes per IP
- CORS: Configurable allowed origins
- Security Headers: XSS protection, content type options, frame options
- Input Validation: Express-validator for request validation
- Error Handling: No sensitive information leaked in production
- Request Timeout: 30-second default timeout
- AWS IAM: Least-privilege permissions for AWS services
- Winston Logging: Structured JSON logs with multiple levels
- Request Tracking: Unique request IDs for tracing
- Error Tracking: Comprehensive error logging with context
- CloudWatch Integration: Automatic log aggregation in AWS
- Health Check:
/healthendpoint for monitoring
This server includes a complete n8n workflow integration for WhatsApp notifications:
- Import the workflow from
n8n-workflow.json - Configure WhatsApp Business API credentials
- Set up environment variables in n8n
- Update your server's
N8N_WEBHOOK_URLenvironment variable
# Test the n8n webhook integration
node test-webhook.js
# Set environment variables for testing
export N8N_WEBHOOK_URL="https://your-n8n-instance.com/webhook/event-ai-alert"
export TEST_RECIPIENTS="+1234567890,+0987654321"The server sends structured data to n8n:
{
"simulationId": "sim_12345",
"message": "Event AI simulation completed",
"recipients": ["+1234567890"],
"timestamp": "2024-01-01T12:00:00Z",
"priority": "high",
"type": "whatsapp_alert",
"recommendations": [
{
"id": "rec_1",
"type": "CROWD_CONTROL",
"priority": "HIGH",
"title": "Deploy Additional Staff",
"description": "High congestion detected",
"estimatedImpact": "Reduce wait time by 60%",
"implementationTime": "10 minutes"
}
]
}For detailed setup instructions, see n8n-setup-guide.md.
# Run tests
npm test
# Run tests in watch mode
npm run test:watch
# Run linting
npm run lint
# Fix linting issues
npm run lint:fix
# Test n8n webhook integration
node test-webhook.jsserverless deploy --stage devserverless deploy --stage prodThe serverless.yml supports multiple stages with different configurations:
- dev: Development environment with debug logging
- staging: Staging environment for testing
- prod: Production environment with optimized settings
# Generate Prisma client after schema changes
npx prisma generate
# Create and apply migrations
npx prisma migrate dev --name description
# Reset database (development only)
npx prisma migrate reset
# View database in Prisma Studio
npx prisma studioThe server implements comprehensive error handling:
- Custom AppError Class: Structured error responses
- AWS SDK Errors: Specific handling for AWS service errors
- Database Errors: Prisma error translation
- Validation Errors: Express-validator integration
- Global Error Handler: Centralized error processing
- Connection Pooling: Database connection optimization
- Async Operations: Non-blocking I/O operations
- Request Caching: Appropriate cache headers
- Compression: API Gateway compression enabled
- Cold Start Optimization: Minimal dependencies and optimized imports
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Create an issue in the repository
- Check the documentation
- Review the logs in CloudWatch
The prediction service supports multiple image sources with the following priority:
- Real-time Camera Feeds (Recommended)
- Forecast Data Images
- Event Attachments
- Demo Images (Fallback only)
# Update event with camera feeds
curl -X PUT http://localhost:3000/api/v1/events/{eventId} \
-H "Content-Type: application/json" \
-d '{
"cameraFeeds": {
"gate_1": "http://camera-server.com/gate1/live",
"gate_2": "http://camera-server.com/gate2/live"
}
}'Use public webcams from SkylineWebcams:
# Example: Rome landmarks
curl -X PUT http://localhost:3000/api/v1/events/evt_demo \
-H "Content-Type: application/json" \
-d '{
"cameraFeeds": {
"gate_1": "https://cdn.skylinewebcams.com/live205.jpg",
"gate_2": "https://cdn.skylinewebcams.com/live286.jpg",
"gate_3": "https://cdn.skylinewebcams.com/live1151.jpg"
}
}'
# Or run the test script
./test-live-webcam.shSee the complete guides:
- π Live Webcam Integration - NEW! Using public webcams
- π Webcam Quick Reference - NEW! Quick start guide
- π Camera Feed Setup Guide - Your own cameras
- π Fix Summary
- π Example Configuration
# Check if using real-time cameras
tail -f logs/combined.log | grep "Using real-time camera feed"
# Check for fallback warnings
tail -f logs/combined.log | grep "No real-time image available"-
v1.1.0 (2025-10-07): Camera Feed Integration & Prediction Improvements
- β Added real-time camera feed support
- β Fixed random image selection causing detection inconsistency
- β Implemented multi-priority image source system
- β Enhanced logging and monitoring for image sources
- π Added comprehensive camera setup documentation
-
v1.0.0: Initial release with core functionality
- Event management
- AI simulation integration
- WhatsApp notifications
- AWS serverless deployment