A comprehensive AI-powered system for predicting rockfall risks in mining and construction environments
The Rockfall Risk Prediction System is an advanced web application that leverages machine learning to assess and predict rockfall risks in mining operations, construction sites, and geological monitoring scenarios. Built with modern web technologies, it provides both real-time single predictions and bulk analysis capabilities for comprehensive risk management.
- Real-time Risk Assessment - Instant predictions with 13 geotechnical parameters
- Bulk Analysis - Process multiple scenarios via CSV upload
- AI-Powered Predictions - Machine learning model with feature importance analysis
- Interactive Dashboard - Beautiful, responsive UI with real-time data visualization
- Data Persistence - PostgreSQL database with Prisma ORM
- Alert System - Automatic notifications for high-risk scenarios
- Responsive Design - Works seamlessly on desktop and mobile devices
graph TB
A[Frontend Dashboard] --> B[Next.js API Routes]
B --> C[Python ML Model]
B --> D[PostgreSQL Database]
C --> E[Risk Prediction]
D --> F[Data Storage]
E --> G[Risk Assessment]
F --> H[Historical Data]
G --> I[Alert Generation]
H --> J[Analytics & Reporting]
| Component | Technology | Purpose |
|---|---|---|
| Frontend | Next.js 15.5.2 + React 19 | Modern web application framework |
| Styling | Tailwind CSS + shadcn/ui | Responsive design system |
| Forms | React Hook Form + Zod | Type-safe form validation |
| Backend | Next.js API Routes | Serverless API endpoints |
| Database | PostgreSQL + Prisma | Data persistence and ORM |
| ML Engine | Python + scikit-learn | Risk prediction model |
| Type Safety | TypeScript | End-to-end type safety |
- Node.js 18+ and npm
- Python 3.8+ with pip
- PostgreSQL 13+
- Git
git clone https://github.com/your-username/rockfall-risk-prediction.git
cd rockfall-risk-prediction# Install Node.js dependencies
npm install
# Install Python dependencies
cd ml
pip install -r requirements.txt
cd ..Create a .env.local file in the root directory:
# Database
DATABASE_URL="postgresql://username:password@localhost:5432/rockfall_db"
# Optional: Add other environment variables
NEXT_PUBLIC_APP_URL="http://localhost:3000"# Generate Prisma client
npx prisma generate
# Run database migrations
npx prisma db push
# (Optional) Seed the database
npx prisma db seed# Start the development server
npm run devVisit http://localhost:3000 to see the application in action!
Use the manual analysis form to input 13 geotechnical parameters:
| Parameter | Unit | Description |
|---|---|---|
| Rainfall | mm/day | Daily precipitation impacting slope saturation |
| Depth to Groundwater | m | Vertical distance to the water table |
| Pore Water Pressure | kPa | Water pressure within soil/rock pores |
| Surface Runoff | m³/s | Overland flow affecting erosion/loading |
| Unit Weight | kN/m³ | Material density × gravity |
| Cohesion | kPa | Shear strength independent of normal stress |
| Internal Friction Angle | ° | Shear resistance due to particle friction |
| Slope Angle | ° | Inclination of slope face |
| Slope Height | m | Vertical height of slope |
| Pore Water Pressure Ratio | 0–1 | Ru ratio for saturation effects |
| Bench Height | m | Vertical dimension of a bench |
| Bench Width | m | Horizontal width of a bench |
| Inter-Ramp Angle | ° | Angle between benches across ramps |
- Prepare CSV File: Create a CSV with headers matching the parameter names above
- Upload: Drag and drop or click to upload your CSV file
- Process: Click "Process X Records" to run bulk predictions
- Review: Analyze results with risk level distribution and detailed breakdowns
rainfall,depthToGroundwater,poreWaterPressure,surfaceRunoff,unitWeight,cohesion,internalFrictionAngle,slopeAngle,slopeHeight,pwpRatio,benchHeight,benchWidth,interRampAngle
15.5,2.3,45.2,0.8,18.5,25.0,35.0,45.0,12.0,0.3,3.0,4.0,15.0
8.2,1.8,38.7,0.6,19.2,28.5,32.0,38.0,10.5,0.25,2.8,3.5,12.0POST /api/predict
Content-Type: application/json
{
"features": [15.5, 2.3, 45.2, 0.8, 18.5, 25.0, 35.0, 45.0, 12.0, 0.3, 3.0, 4.0, 15.0]
}POST /api/predict/bulk
Content-Type: application/json
{
"rows": [
[15.5, 2.3, 45.2, 0.8, 18.5, 25.0, 35.0, 45.0, 12.0, 0.3, 3.0, 4.0, 15.0],
[8.2, 1.8, 38.7, 0.6, 19.2, 28.5, 32.0, 38.0, 10.5, 0.25, 2.8, 3.5, 12.0]
]
}GET /api/predictions# Test single prediction API
node test_api.js
# Test bulk prediction API
node test_bulk_api.js
# Run TypeScript checks
npm run build- Start the development server:
npm run dev - Open the dashboard: Navigate to
http://localhost:3000/dashboard - Test single prediction: Fill out the form and click "Analyze Risk"
- Test bulk analysis: Upload a CSV file and process it
The application uses a well-structured PostgreSQL database with the following entities:
- MonitoredLocation: Represents specific monitoring sites
- SensorReading: Stores time-series sensor data
- Prediction: Contains AI model predictions and risk assessments
- Alert: Logs high-risk alerts and notifications
erDiagram
MonitoredLocation ||--o{ SensorReading : has
MonitoredLocation ||--o{ Prediction : generates
SensorReading ||--o| Prediction : triggers
Prediction ||--o{ Alert : creates
MonitoredLocation {
int id PK
string name UK
string description
datetime createdAt
}
SensorReading {
bigint id PK
datetime timestamp
int locationId FK
float rainfall
float depthToGroundwater
float poreWaterPressure
float surfaceRunoff
float unitWeight
float cohesion
float internalFrictionAngle
float slopeAngle
float slopeHeight
float poreWaterPressureRatio
float benchHeight
float benchWidth
float interRampAngle
}
Prediction {
bigint id PK
datetime predictionTimestamp
float riskScore
enum riskLevel
json contributingFactors
int locationId FK
bigint sourceReadingId FK
}
Alert {
int id PK
datetime alertTimestamp
string message
bigint predictionId FK
}
| Variable | Description | Required | Default |
|---|---|---|---|
DATABASE_URL |
PostgreSQL connection string | ✅ | - |
NEXT_PUBLIC_APP_URL |
Application URL | ❌ | http://localhost:3000 |
The ML model requires the following Python packages:
numpy>=1.21.0
scikit-learn>=1.0.0
pandas>=1.3.0
- Connect your repository to Vercel
- Set environment variables in the Vercel dashboard
- Deploy with automatic builds on push
# Build the application
docker build -t rockfall-risk-app .
# Run with PostgreSQL
docker-compose up -d- Build the application:
npm run build - Start the production server:
npm start - Configure reverse proxy (nginx/Apache)
- Set up SSL certificates
We welcome contributions! Please follow these steps:
- 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
- Follow TypeScript best practices
- Write tests for new features
- Update documentation as needed
- Follow the existing code style
- Single Prediction: < 2 seconds
- Bulk Processing: ~100 records/minute
- Database Queries: Optimized with Prisma
- Frontend: Server-side rendering with Next.js
- Input validation with Zod schemas
- SQL injection protection via Prisma ORM
- CORS configuration
- Environment variable security
- Rate limiting on API endpoints
- Real-time Monitoring - WebSocket integration for live data
- Advanced Analytics - Historical trend analysis
- Mobile App - React Native companion app
- API Documentation - OpenAPI/Swagger integration
- Multi-tenant Support - Organization-based data isolation
- Machine Learning Pipeline - Automated model retraining
Database Connection Error
# Check if PostgreSQL is running
sudo service postgresql status
# Verify connection string
echo $DATABASE_URLPython Model Not Found
# Ensure model.pkl exists
ls -la ml/model.pkl
# Check Python dependencies
pip install -r ml/requirements.txtBuild Errors
# Clear Next.js cache
rm -rf .next
# Reinstall dependencies
rm -rf node_modules package-lock.json
npm installThis project is licensed under the MIT License - see the LICENSE file for details.
- Geotechnical Engineering Community for domain expertise
- Next.js Team for the amazing framework
- Prisma Team for the excellent ORM
- Open Source Contributors who made this possible
- Documentation: Wiki
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: support@rockfall-risk.com
Built with care for safer mining and construction operations