A comprehensive full-stack solution that combines SurveyJS survey creation, MongoDB data storage, advanced analytics processing, and Grafana visualization to create powerful survey analytics dashboards.
This project provides a complete survey analytics platform that enables users to:
- Create and manage surveys using SurveyJS
- Collect and store survey responses in MongoDB
- Process responses with advanced analytics and NLP
- Visualize data through interactive Grafana dashboards
- Scale from development to production environments
The system consists of four main components working together:
βββββββββββββββββββ βββββββββββββββββββ
β Redis Cache β β MongoDB β
β (Port 6379) β β (Port 27017) β
βββββββββββββββββββ βββββββββββββββββββ
β β
βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β SurveyJS β β Node.js β β Grafana β
β Frontend βββββΆβ Backend ββββββββββββΆ β Plugin β
β β β (Port 3000) β βββββββββββββββββββ
βββββββββββββββββββ βββββββββββββββββββ β
β βΌ
βΌ βββββββββββββββββββ
βββββββββββββββββββ β Grafana β
β NLP Service β β Dashboards β
β (Port 5000) β β (Port 3001) β
βββββββββββββββββββ βββββββββββββββββββ
surveyjs-mongo-grafana/
βββ π nlp-service/ # Natural Language Processing Service
β βββ app.py # FastAPI application
β βββ requirements.txt # Python dependencies
β βββ Dockerfile # Container configuration
β βββ readme.md # Service documentation
β
βββ π node-server/ # Core Backend Service
β βββ π src/ # TypeScript source code
β β βββ π db-adapters/ # Database adapters
β β βββ π routes/ # API route handlers
β β βββ π services/ # Analytics services
β β βββ db.ts # Database connections
β β βββ index.ts # Main server file
β βββ π tests/ # Test suites
β βββ package.json # Node.js dependencies
β βββ Dockerfile # Container configuration
β βββ README.md # Service documentation
β
βββ π grafana/ # Grafana Configuration
β βββ π provisioning/ # Auto-configuration
β β βββ π datasources/ # Data source configs
β β βββ π dashboards/ # Dashboard configs
β β βββ README.md # Provisioning docs
β βββ π surveyjs-grafana-datasource/ # Custom Grafana Plugin
β β βββ π src/ # Plugin source code
β β βββ package.json # Plugin dependencies
β β βββ README.md # Plugin documentation
β βββ π data/ # Grafana data persistence
β βββ Dockerfile # Grafana container config
β
βββ π mongo/ # MongoDB Configuration
β βββ init.js # Database initialization
β βββ π data/ # Database persistence
β
βββ docker-compose.yaml # Multi-service orchestration
βββ README.md # This file
- Docker and Docker Compose
- Git
- Basic understanding of surveys and analytics
# Clone the repository
git clone <repository-url>
cd surveyjs-mongo-grafana
# Create environment file
cp .env.example .env
# Edit .env with your configuration
Create a .env
file with the following variables:
# MongoDB Configuration
MONGO_ROOT_USER=admin
MONGO_ROOT_PASSWORD=your_secure_password
# Grafana Configuration
GRAFANA_ADMIN_USER=admin
GRAFANA_ADMIN_PASSWORD=your_grafana_password
# Start all services
docker-compose up -d
# View logs
docker-compose logs -f
- Grafana Dashboards: http://localhost:3001
- Username:
admin
(or your configured user) - Password: (your configured password)
- Username:
- Node.js API: http://localhost:3000
- NLP Service: http://localhost:5000
- MongoDB: localhost:27017
- Redis: localhost:6379
Purpose: Core backend service handling survey management, data collection, and analytics.
Key Features:
- Survey CRUD operations
- Response collection and storage
- Advanced analytics processing
- Grafana datasource API
- NLP integration
- Redis caching
Technology Stack:
- Node.js with TypeScript
- Express.js web framework
- MongoDB for data persistence
- Redis for caching
- SurveyJS Core for survey processing
API Endpoints:
/api/*
- Survey management and analytics/grafana/*
- Grafana datasource integration- Health checks and monitoring
Purpose: Natural Language Processing microservice for text analysis.
Key Features:
- Sentiment analysis using TextBlob
- Named Entity Recognition with spaCy
- Key phrase extraction
- RESTful API for text processing
Technology Stack:
- Python 3.9
- FastAPI web framework
- spaCy for NLP processing
- TextBlob for sentiment analysis
- Uvicorn ASGI server
API Endpoints:
GET /health
- Service health checkGET /sentiment?text={text}
- Sentiment analysisPOST /analyze
- Comprehensive text analysis
Purpose: Custom Grafana plugin for SurveyJS data visualization.
Key Features:
- Dynamic survey and question selection
- Multiple visualization types
- Real-time data updates
- Advanced query capabilities
- Sentiment analysis integration
Technology Stack:
- React with TypeScript
- Grafana SDK
- Custom data frame generation
- RESTful backend communication
Visualization Types:
- Bar charts for choice questions
- Statistical tables for numeric data
- Histograms for distributions
- Time series for temporal data
- Sentiment analysis displays
Purpose: Automated configuration of Grafana data sources and dashboards.
Key Features:
- Auto-configured data sources
- Pre-built sample dashboards
- Infrastructure-as-code deployment
- Real-time configuration updates
Configuration Files:
datasources/datasources.yaml
- Data source configurationdashboards/dashboards.yaml
- Dashboard provider settingsdashboards/burger_survey.json
- Sample dashboard
- Survey Creation: Users create surveys using SurveyJS Creator (external)
- Response Collection: Survey responses are submitted to the Node.js backend
- Data Storage: Responses are stored in MongoDB with metadata
- Analytics Processing: Backend processes responses and calculates statistics
- NLP Processing: Text responses are sent to NLP service for analysis
- Caching: Results are cached in Redis for performance
- Visualization: Grafana queries backend and displays data in dashboards
SurveyJS Frontend β Node.js Backend β MongoDB
β
NLP Service β Text Responses
β
Redis Cache β Analytics Results
β
Grafana Plugin β Dashboard Visualization
- Node.js β MongoDB: Survey and response data storage
- Node.js β Redis: Analytics caching and performance
- Node.js β NLP Service: Text analysis for sentiment and entities
- Grafana β Node.js: Data querying and visualization
- Docker Compose: Service orchestration and networking
# Check all services
curl http://localhost:3000/api/health # Node.js backend
curl http://localhost:5000/health # NLP service
curl http://localhost:3001/api/health # Grafana
# Create a new survey
curl "http://localhost:3000/api/create?name=Test%20Survey"
# Submit a test response
curl -X POST http://localhost:3000/api/post \
-H "Content-Type: application/json" \
-d '{"postId": "your_survey_id", "surveyResult": {"q1": "Test response"}}'
# Test sentiment analysis
curl "http://localhost:5000/sentiment?text=I love this product!"
# Test comprehensive analysis
curl -X POST http://localhost:5000/analyze \
-H "Content-Type: application/json" \
-d '{"text": "The customer service was excellent and very helpful."}'
- Open http://localhost:3001
- Login with your credentials
- Navigate to "Dashboards"
- Open "Burger Survey Analytics" (sample dashboard)
- Verify data is loading correctly
The project includes a comprehensive sample dashboard (burger_survey.json
) demonstrating:
- Total Responses: Stat panel showing response count
- Average Satisfaction: Bar gauge with color coding
- Choice Distributions: Bar charts for multiple choice questions
- Ranking Analysis: Bar charts for ranking questions
- Rating Distribution: Histogram for rating data
- Temporal Analysis: Monthly distribution charts
- Create Survey: Use SurveyJS Creator to design your survey
- Store Configuration: Save survey JSON to the backend
- Create Dashboard: Export dashboard from Grafana or create new one
- Add to Provisioning: Place dashboard JSON in
grafana/provisioning/dashboards/
- Add Question Types: Extend analytics services for new question types
- Custom Calculations: Add new statistical functions
- NLP Enhancements: Extend NLP service with additional analysis
- Visualization Types: Create new Grafana panel types
- Database Scaling: Configure MongoDB replica sets
- Caching: Implement Redis clustering
- Load Balancing: Add multiple Node.js instances
- Monitoring: Integrate with monitoring solutions
# Production environment variables
MONGO_ROOT_USER=production_admin
MONGO_ROOT_PASSWORD=secure_production_password
GRAFANA_ADMIN_USER=admin
GRAFANA_ADMIN_PASSWORD=secure_grafana_password
- Database Security: Use strong passwords and network isolation
- API Security: Implement authentication and rate limiting
- Container Security: Use non-root users and security scanning
- Network Security: Configure firewalls and SSL/TLS
- Database Indexing: Add appropriate MongoDB indexes
- Caching Strategy: Optimize Redis caching policies
- Resource Limits: Configure container resource limits
- Monitoring: Implement comprehensive monitoring
# Check service status
docker-compose ps
# View service logs
docker-compose logs [service-name]
# Restart specific service
docker-compose restart [service-name]
# Check MongoDB connectivity
docker-compose exec mongodb mongosh --eval "db.adminCommand('ping')"
# Check Redis connectivity
docker-compose exec redis redis-cli ping
- Verify data sources are configured correctly
- Check backend service connectivity
- Review Grafana logs for errors
- Ensure survey data exists in MongoDB
Enable debug logging for detailed troubleshooting:
# Node.js backend
NODE_ENV=development docker-compose up
# Grafana
GF_LOG_LEVEL=debug docker-compose up grafana
-
Advanced Analytics:
- Machine learning integration
- Predictive analytics
- Advanced statistical models
- Custom calculation engines
-
Enhanced Visualizations:
- Interactive charts
- Real-time dashboards
- Custom visualization types
- Mobile-responsive designs
-
Integration Capabilities:
- Webhook support
- API integrations
- Third-party service connections
- Export capabilities
-
User Experience:
- User authentication
- Role-based access control
- Custom dashboard creation
- Survey templates
- Fork the Repository: Create your own fork
- Create Feature Branch:
git checkout -b feature/new-feature
- Make Changes: Implement your enhancements
- Add Tests: Include comprehensive tests
- Submit Pull Request: Create PR with detailed description
- Follow TypeScript best practices
- Add comprehensive documentation
- Include unit and integration tests
- Use consistent code formatting
- Follow semantic versioning
- NLP Service Documentation
- Node.js Backend Documentation
- Grafana Plugin Documentation
- Grafana Provisioning Documentation
This project is licensed under the Apache-2.0 License - see the LICENSE file for details.
For support, questions, or contributions:
- Issues: Create GitHub issues for bugs or feature requests
- Discussions: Use GitHub discussions for questions
- Documentation: Check component-specific documentation
- Community: Join the SurveyJS community forums
- Clone the repository
- Configure environment variables
- Execute
npm i
command innode-server
folder - Build
node_server
project usingnpm run build
command - Install dependencies in
nlp-service
folder using thepip install -r requirements.txt
command - Download spaCy model in
nlp-service
folder using thepython -m spacy download en_core_web_sm
command - Execute
npm i
command ingrafana/surveyjs-grafana-datasource
folder - Build
surveyjs-grafana-datasource
project usingnpm run build
command - Start services with
docker-compose up -d
- Verify all services are running
- Access Grafana at http://localhost:3001
- Explore the sample dashboard
- Create your first survey
- Submit test responses
- View analytics in Grafana
- Customize dashboards for your needs
Clone this repo:
git clone https://github.com/tsv2013/surveyjs-mongo-grafana.git
Build SurveyJS Grafana datasource:
cd surveyjs-mongo-grafana/grafana/surveyjs-grafana-datasource
npm i
npm run build
Build NodeJS backend:
cd surveyjs-mongo-grafana/node-server
npm i
npm run build
Prepare NLP service:
pip install -r requirements.txt
python -m spacy download en_core_web_sm
Run containers:
docker compose up -d
Note that NLP server needs to download sentiment analyis model and build it that can take ~5 minutes.
Two sites are available after docker starts:
- http://localhost:3000/ - simple surveyjs backend: surveys list, run survey, display results in table form
- http://localhost:3001/ - grafana dashboard server site: login/password - admin/grafana
Happy Surveying and Analytics! πβ¨