A comprehensive incident reporting and alerting system that aggregates news, weather data, and user-reported incidents on an interactive map with real-time notifications.
- Real-time Incident Reporting: Users can report incidents with location, media uploads, and detailed descriptions
- Interactive Map Visualization: 3D globe view powered by Mapbox showing incidents by category and severity
- Live News Aggregation: Automated scraping and categorization of news from multiple sources (Times of India, CNN)
- Weather Integration: Real-time weather data integration from OpenWeatherMap
- AI-Powered Categorization: Automatic incident classification using keyword-based AI processing
- Real-time Updates: WebSocket-powered live updates for new incidents and alerts
- User Authentication: Secure registration, login, and profile management with JWT tokens
- Media Uploads: Support for images and videos with validation and thumbnail generation
- Multi-category Incidents: Support for accidents, crimes, fires, floods, storms, earthquakes, traffic, health, and weather incidents
- Location Services: GPS-based location capture and manual location input
- Statistics Dashboard: Comprehensive analytics and incident statistics
- Responsive Design: Modern UI with dark/light theme support
- RESTful API: Comprehensive backend API with proper error handling
- Database Migrations: Alembic-powered database version control
- File Handling: Secure media upload with size and type validation
- WebSocket Support: Real-time bidirectional communication
- Modern Frontend: React with TypeScript, modern UI components, and state management
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Frontend β β Backend β β External β
β React + TS βββββΊβ Flask + SQL βββββΊβ APIs β
β Vite + UI β β WebSocket β β News + Weatherβ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β
βββββββββββββββββββ
β PostgreSQL β
β Database β
βββββββββββββββββββ
- Framework: React 18 with TypeScript
- Build Tool: Vite
- Styling: Tailwind CSS
- UI Components: Radix UI primitives
- State Management: TanStack Query (React Query)
- Routing: React Router v6
- Maps: Mapbox GL JS
- Forms: React Hook Form with Zod validation
- Icons: Lucide React
- Framework: Flask 3.0
- Database: PostgreSQL with SQLAlchemy 2.0
- Migrations: Alembic
- Authentication: Flask-JWT-Extended with bcrypt
- Real-time: Flask-SocketIO
- Validation: Marshmallow
- Web Scraping: BeautifulSoup4 + Requests
- Image Processing: Pillow
- Maps: Mapbox (for interactive globe visualization)
- Weather: OpenWeatherMap API
- News Sources: Times of India, CNN (via web scraping)
Before you begin, ensure you have the following installed:
- Node.js (v18 or higher)
- Python (v3.8 or higher)
- PostgreSQL (v12 or higher)
- Git
- Mapbox Account (free tier available)
- OpenWeatherMap Account (free tier available)
For a quick setup, run these commands in sequence:
# Clone repository
git clone https://github.com/KarthickRaghul/Inci-Alert.git
cd Inci-Alert
# Backend setup
cd backend
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
cp .env.example .env
# Edit .env file with your configuration
cd ..
# Frontend setup
cd frontend
npm install
cp .env.example .env
# Edit .env file with your Mapbox token
cd ..
# Database setup
createdb inci_alert # or create using your preferred method
# Run migrations
cd backend
flask db upgradegit clone https://github.com/KarthickRaghul/Inci-Alert.git
cd Inci-Alertcd backend
# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate
# Install dependencies
pip install -r requirements.txtcd frontend
# Install dependencies
npm install# Create PostgreSQL database
createdb inci_alert
# Or using psql:
psql -c "CREATE DATABASE inci_alert;"Create a .env file in the backend directory by copying from the example:
cd backend
cp .env.example .envThen edit the .env file with your actual values:
# Database Configuration
DATABASE_URL=postgresql+psycopg://username:password@localhost:5432/inci_alert
# Security Keys (Generate strong random keys for production)
SECRET_KEY=your-secret-key-here-change-this-in-production
JWT_SECRET_KEY=your-jwt-secret-key-here-change-this-in-production
JWT_ACCESS_TOKEN_EXPIRES=86400
# External APIs
OPENWEATHER_API_KEY=your-openweather-api-key
# Get your free API key from: https://openweathermap.org/api
# File Upload Settings
UPLOAD_FOLDER=uploads
MAX_CONTENT_LENGTH=10485760 # 10MB
# Request Settings
REQUEST_TIMEOUT=10Create a .env file in the frontend directory by copying from the example:
cd frontend
cp .env.example .envThen edit the .env file with your actual values:
# Mapbox Configuration
VITE_MAPBOX_TOKEN=your-mapbox-token-here
# Get your free token from: https://mapbox.com/ (starts with 'pk.')
# API Configuration
VITE_API_BASE_URL=http://localhost:5000cd backend
# Initialize migration repository (if not already done)
flask db init
# Create initial migration
flask db migrate -m "Initial migration"
# Apply migrations
flask db upgradecd backend
# Activate virtual environment
source venv/bin/activate # or venv\Scripts\activate on Windows
# Run Flask development server
python app.pyThe backend will be available at http://localhost:5000
cd frontend
# Start Vite development server
npm run devThe frontend will be available at http://localhost:5173
Backend (.env)
# Use strong, randomly generated keys
SECRET_KEY=your-strong-production-secret-key
JWT_SECRET_KEY=your-strong-production-jwt-secret
# Use production database
DATABASE_URL=postgresql+psycopg://user:password@prod-db-host:5432/inci_alert
# Production API keys
OPENWEATHER_API_KEY=your-production-api-key
# Production settings
FLASK_ENV=production
DEBUG=FalseFrontend (.env.production)
VITE_MAPBOX_TOKEN=your-production-mapbox-token
VITE_API_BASE_URL=https://your-api-domain.comDocker support is planned for easier deployment. For now, use traditional deployment methods.
cd backend
# Install production dependencies
pip install gunicorn
# Run with Gunicorn (adjust workers based on your server)
gunicorn --worker-class eventlet -w 1 --bind 0.0.0.0:5000 app:app
# For systemd service
gunicorn --worker-class eventlet -w 1 --bind unix:/tmp/inci-alert.sock app:appcd frontend
# Build for production
npm run build
# Serve with nginx, apache, or any static file server
# Build files will be in the 'dist' directory# Backend API
upstream inci_backend {
server unix:/tmp/inci-alert.sock;
}
# Frontend
server {
listen 80;
server_name your-domain.com;
# Frontend static files
location / {
root /path/to/Inci-Alert/frontend/dist;
try_files $uri $uri/ /index.html;
}
# Backend API
location /api/ {
proxy_pass http://inci_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# WebSocket support
location /socket.io/ {
proxy_pass http://inci_backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
}
## π‘ API Documentation
### Base URL
### Authentication Endpoints
| Method | Endpoint | Description |
|--------|----------|-------------|
| POST | `/auth/register` | Register new user |
| POST | `/auth/login` | User login |
| POST | `/auth/logout` | User logout |
| GET | `/auth/profile` | Get user profile |
| PUT | `/auth/profile` | Update user profile |
### Incident Endpoints
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/incidents` | List all incidents |
| POST | `/incidents` | Create new incident |
| GET | `/incidents/{id}` | Get incident details |
| PUT | `/incidents/{id}` | Update incident |
| DELETE | `/incidents/{id}` | Delete incident |
### Data Ingestion Endpoints
| Method | Endpoint | Description |
|--------|----------|-------------|
| POST | `/ingest/news` | Trigger news scraping |
| POST | `/ingest/weather` | Fetch weather data |
### Statistics Endpoints
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/stats/overview` | Get overview statistics |
| GET | `/stats/incidents` | Get incident statistics |
### Media Endpoints
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/media/{type}/{filename}` | Get media file |
| GET | `/media/thumbnails/{filename}` | Get thumbnail |
## π Project Structure
Inci-Alert/ βββ frontend/ # React TypeScript frontend β βββ public/ # Static assets β βββ src/ β β βββ components/ # Reusable UI components β β β βββ ui/ # Base UI components (shadcn/ui) β β β βββ Map.tsx # Interactive map component β β β βββ Navbar.tsx # Navigation component β β β βββ ... β β βββ pages/ # Route components β β β βββ Home.tsx # Dashboard/home page β β β βββ LiveAlerts.tsx # Real-time alerts β β β βββ ReportIncident.tsx # Incident reporting β β β βββ ... β β βββ services/ # API client and utilities β β βββ hooks/ # Custom React hooks β β βββ constants/ # App constants and config β β βββ lib/ # Utility functions β βββ package.json β βββ vite.config.ts # Vite configuration β βββ backend/ # Flask Python backend β βββ models/ # SQLAlchemy models β β βββ incident.py # Incident model β β βββ user.py # User model β β βββ media.py # Media model β βββ routes/ # API route handlers β β βββ incidents.py # Incident endpoints β β βββ auth.py # Authentication endpoints β β βββ media.py # Media endpoints β β βββ stats.py # Statistics endpoints β βββ services/ # Business logic β β βββ scrapers/ # Web scraping modules β β βββ ai_processor.py # AI categorization β β βββ ingest.py # Data ingestion β βββ utils/ # Utility modules β β βββ db.py # Database configuration β β βββ validation.py # Data validation schemas β β βββ file_handler.py # File upload handling β βββ migrations/ # Database migrations β βββ requirements.txt # Python dependencies β βββ config.py # App configuration β βββ app.py # Flask application entry point β βββ README.md # This file βββ .gitignore # Git ignore rules
## π§ Development
### Running Tests
#### Backend Tests
```bash
cd backend
# Run all tests (if pytest is configured)
python -m pytest
# Run specific test file
python test_news_aggregator.py
Test the news scraping and categorization system:
cd backend
python test_news_aggregator.pyThis will test:
- News scraping from configured sources
- AI categorization system
- Database integration (optional)
cd frontend
# Lint code
npm run lint
# Build for production
npm run build
# Preview production build
npm run previewFollow PEP 8 standards. Use tools like black and flake8:
pip install black flake8
black .
flake8 .cd backend
flask db migrate -m "Description of changes"flask db upgradeflask db downgrade# WARNING: This will delete all data
flask db downgrade base
flask db upgradecd backend
source venv/bin/activate
# Start development server
python app.py
# Run with debug mode
FLASK_ENV=development python app.py
# Test news scraping
python test_news_aggregator.py
# Create new migration
flask db migrate -m "Your message"
# Apply migrations
flask db upgradecd frontend
# Start development server
npm run dev
# Build for production
npm run build
# Lint and fix
npm run lint
# Preview build
npm run preview- Navigate to
/report - Fill in incident details:
- Title and description
- Category selection
- Location (GPS or manual)
- Media uploads (optional)
- Submit the report
- Navigate to
/alerts - View incidents on the interactive map
- Filter by category or severity
- Click markers for detailed information
The system automatically scrapes news from configured sources. You can manually trigger:
curl -X POST http://localhost:5000/ingest/newsFetch weather data for a specific city:
curl -X POST http://localhost:5000/ingest/weather \
-H "Content-Type: application/json" \
-d '{"city": "New Delhi"}'We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch
git checkout -b feature/your-feature-name
- Make your changes
- Run tests and ensure code quality
- Commit your changes
git commit -m "Add: your feature description" - Push to your fork
git push origin feature/your-feature-name
- Create a Pull Request
- Follow existing code style and patterns
- Add tests for new features
- Update documentation as needed
- Ensure all tests pass
- Use descriptive commit messages
This project is licensed under the MIT License. See the LICENSE file for details.
sqlalchemy.exc.OperationalError: (psycopg.OperationalError) connection failed
Solutions:
- Ensure PostgreSQL is running:
sudo systemctl status postgresql - Verify database credentials in
.envfile - Check if database exists:
psql -l | grep inci_alert - Test connection:
psql postgresql://username:password@localhost:5432/inci_alert
Error: Mapbox access token is required
Solutions:
- Verify
VITE_MAPBOX_TOKENin frontend.envfile - Ensure token starts with
pk.(public token) - Check token validity on Mapbox Dashboard
- Restart development server after changing .env
Error scraping news: Connection timeout / HTTP errors
Solutions:
- Check internet connectivity
- Verify scraping targets haven't changed their structure
- Check if websites are blocking requests (user-agent issues)
- Review headers in
backend/services/scrapers/news_scraper.py
Error: File upload failed / Permission denied
Solutions:
- Check
uploads/directory permissions:chmod 755 uploads/ - Verify
UPLOAD_FOLDERpath in.env - Ensure
MAX_CONTENT_LENGTHallows your file size - Check available disk space
Error: Module not found / Import errors
Solutions:
- Clear node modules:
rm -rf node_modules package-lock.json && npm install - Check Node.js version:
node --version(should be 18+) - Verify all environment variables in
.env - Try:
npm run build:devfor development build
ModuleNotFoundError: No module named 'your_module'
Solutions:
- Ensure virtual environment is activated
- Reinstall dependencies:
pip install -r requirements.txt - Check Python path and virtual environment
- Verify all environment variables in
.env
Address already in use / Port 5000 is busy
Solutions:
- Find process using port:
lsof -i :5000ornetstat -nlp | grep 5000 - Kill process:
kill -9 <PID> - Use different port:
flask run --port 5001
Access blocked by CORS policy
Solutions:
- Verify frontend URL in backend CORS settings (
app.py) - Check if frontend and backend URLs match in
.env - Ensure proper headers are set in API requests
cd backend
export FLASK_ENV=development
export FLASK_DEBUG=1
python app.pycd frontend
# Development server provides detailed error messages
npm run dev- Check console output for detailed error messages
- Review Flask logs for database and API errors
- News scraper logs show scraping status
- Open browser developer tools (F12)
- Check Console tab for JavaScript errors
- Network tab shows API request/response details
- Check
REQUEST_TIMEOUTin backend.env - Monitor network connectivity
- Consider implementing caching
- Verify Mapbox token has proper permissions
- Check browser's network tab for failed requests
- Ensure stable internet connection
- Monitor PostgreSQL performance
- Consider indexing frequently queried columns
- Check database connection pool settings
If you're still experiencing issues:
- Check the logs in both frontend (browser console) and backend (terminal output)
- Search existing issues on GitHub
- Create a new issue with:
- Error message and full stack trace
- Your operating system and versions
- Steps to reproduce the problem
- Your configuration (without sensitive data)
If nothing else works:
# Backend reset
cd backend
deactivate # if virtual env is active
rm -rf venv/
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
cp .env.example .env
# Edit .env with your settings
flask db upgrade
# Frontend reset
cd ../frontend
rm -rf node_modules/ package-lock.json
npm install
cp .env.example .env
# Edit .env with your settingsFor support, please open an issue on GitHub or contact the maintainers.
- Mobile application (React Native)
- Email/SMS notifications
- Advanced AI categorization
- Integration with more news sources
- Incident verification system
- Advanced analytics dashboard
- Multi-language support
Made with β€οΈ by the Inci-Alert Team