RiverGuard is a comprehensive video analysis platform that uses machine learning to detect garbage and debris in water bodies. The system processes video streams through a YOLO-based detection model and stores results in Firebase Firestore for tracking and analysis.
RiverGuard helps monitor and track pollution in rivers and water bodies by:
- Analyzing video streams for garbage detection
- Providing real-time statistics and visualizations
- Storing historical data for trend analysis
- Offering an intuitive web interface for uploads and viewing results
- Video Analysis API: RESTful API for processing video files
- YOLO Model Integration: Real-time garbage detection using trained YOLO models
- Firebase Integration: Automatic result persistence to Firestore
- Docker Containerization: Scalable microservices architecture
- Frame Extraction: Automatic frame sampling from video streams
- Multi-format Support: Handles MP4, AVI, MOV, MKV formats
- Modern UI: Built with Next.js 15 and React 19
- Drag & Drop Upload: Easy video file upload interface
- Stream URL Support: Process videos from URLs
- Dashboard: View statistics and analysis results
- Real-time Updates: Live feedback during processing
- Responsive Design: Works on desktop and mobile devices
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Frontend β β Backend API β β Model Server β
β (Next.js) βββββΆβ (FastAPI) βββββΆβ (YOLO Model) β
β β β β β β
β - Uploads video β β - Receives β β - Receives β
β - Sends userId β β video + userIdβ β images β
β - Gets results ββββββ - Processes ββββββ - Runs YOLO β
β β β via containersβ β prediction β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β
β βββββββββββββββββββ
β β Firebase β
βββββββββΆβ Firestore β
β β
β - Stores resultsβ
β - Persists data β
βββββββββββββββββββ
βββββββββββββββββββ
β Image Container β
β β
β - Extracts β
β frames β
β - Sends to β
β model β
βββββββββββββββββββ
- FastAPI: Modern Python web framework
- Docker & Docker Compose: Containerization and orchestration
- YOLO: Object detection model for garbage identification
- Firebase Admin SDK: Database integration
- FFmpeg: Video processing and frame extraction
- Uvicorn: ASGI server
- Next.js 15: React framework with App Router
- React 19: UI library
- Firebase Client SDK: Real-time database access
- CSS Modules: Scoped styling
Before you begin, ensure you have the following installed:
- Docker (version 20.10+)
- Docker Compose (version 2.0+)
- Node.js (version 18+)
- npm or yarn
- Python (version 3.13+ for local development)
- Firebase Account: Service account key file (
RiverGuardAccountKey.json)
git clone <repository-url>
cd RiverGuard-
Place your Firebase service account key file in the
BackEnd/directory:cp /path/to/your/RiverGuardAccountKey.json BackEnd/RiverGuardAccountKey.json
-
Ensure the Firebase project ID matches your configuration (default:
trashapi-6eced)
cd BackEnd
docker-compose up -dThis will:
- Build and start the API server on port
8000 - Build and start the model server on port
8001 - Create a Docker network for inter-container communication
- Set up health checks and auto-restart
# Check container status
docker-compose ps
# Test health endpoint
curl http://localhost:8000/health
# View logs
docker-compose logs -f api-servercd FrontEnd
npm installThe frontend uses config.js for configuration. Update if needed:
// FrontEnd/config.js
export const config = {
backendUrl: 'http://localhost:8000', // Update for production
// ... other config
}npm run devThe frontend will be available at http://localhost:3000
- Navigate to the Dashboard (
/dashboard) - Click "Upload Stream" or drag and drop a video file
- Enter a duration (optional)
- Click "Submit"
- Wait for processing to complete
- View results in the "View" tab
curl -X POST \
-F "video_file=@/path/to/video.mp4" \
-F "userId=user123" \
http://localhost:8000/api/analyze-videoResponse:
{
"success": true,
"userId": "user123",
"results": {
"ok": true,
"video": "video.mp4",
"frames_sent": 16,
"responses": [
{
"frame": "frame_00001.jpg",
"response": {
"garbage_count": 0,
"filename": "frame_00001.jpg",
"message": "Image processed successfully"
}
}
]
}
}curl http://localhost:8000/healthRiverGuard/
βββ BackEnd/
β βββ api_server.py # FastAPI server with Firebase integration
β βββ requirements.txt # Python dependencies
β βββ Dockerfile # API server container config
β βββ docker-compose.yml # Multi-container orchestration
β βββ RiverGuardAccountKey.json # Firebase service account key
β βββ temp_uploads/ # Temporary video storage
β βββ image_container/
β β βββ dockerfile
β β βββ image_client.py # Frame extraction client
β β βββ input/ # Test video directory
β βββ model_container/
β βββ dockerfile
β βββ main.py # YOLO prediction logic
β βββ model_server.py # Model HTTP server
β βββ FinalModel.pt # Trained YOLO model
β
βββ FrontEnd/
β βββ src/
β β βββ app/
β β β βββ page.js # Home page
β β β βββ dashboard/ # Dashboard page
β β β βββ about/ # About page
β β β βββ donate/ # Donate page
β β β βββ components/
β β β β βββ FileDrop/ # File upload component
β β β β βββ ViewStats/ # Statistics viewer
β β β β βββ Navbar/ # Navigation bar
β β β β βββ HowTo/ # Instructions component
β β β β βββ DonateOption/ # Donation component
β β β βββ api/ # Next.js API routes
β β βββ lib/
β β βββ firebase.js # Firebase client config
β βββ config.js # Frontend configuration
β βββ package.json
β βββ next.config.mjs
β
βββ README.md # This file
The image container supports these environment variables:
INPUT_PATH: Path to input video (set by API server)USER_ID: User identifier (set by API server)WORKER_URL: Model server URL (default:http://visionmodel:8001/)
Firebase integration requires:
- Service Account Key:
RiverGuardAccountKey.jsoninBackEnd/directory - Firestore Collection:
videos(automatically created) - Document Structure:
{ "userId": "user_id_string", "videoFilename": "original_filename.mp4", "uploadDate": "timestamp", "totalGarbageCount": 19, "framesProcessed": 16, "garbageCountPerFrame": [0, 0, 0, 1, 2, ...] }
- api-server: FastAPI server with Docker client capabilities
- visionmodel: YOLO model server for garbage detection
- imageclient: Temporary container for frame extraction
# Check if containers are running
docker ps
# Verify API server is running
curl http://localhost:8000/health
# Check logs
docker-compose logs api-server
# Restart services
docker-compose restart api-server# Check model server logs
docker-compose logs visionmodel
# Verify network connectivity
docker network inspect seniorprojtesting_my-network
# Test model server directly
curl http://localhost:8001/- Ensure video file exists and is accessible
- Check file permissions
- Verify FFmpeg is working:
docker exec imageclient ffmpeg -version - Check container logs for specific error messages
# Verify credentials file exists
ls BackEnd/RiverGuardAccountKey.json
# Check Firebase logs
docker-compose logs api-server | grep -i firebase
# Verify Firebase Admin SDK is installed
docker exec api-server pip list | grep firebase- Verify backend URL in
FrontEnd/config.js - Check CORS settings in
api_server.py - Ensure backend is running on the correct port
- Check browser console for errors
# View all container logs
docker-compose logs -f
# Check container status
docker-compose ps
# Inspect Docker network
docker network inspect seniorprojtesting_my-network
# Run container interactively
docker exec -it api-server /bin/bash
# Clean up and restart
docker-compose down
docker-compose up -d --build- Processing Time: ~3-5 seconds for a 15-second video (16 frames)
- Memory Usage: Containers are created and destroyed per request
- File Size Limits: Configured to handle videos up to 100MB (adjustable)
- Scalability: Each video processing request runs in isolation
- CORS: Currently set to allow all origins (
allow_origins=["*"]). Update for production. - File Upload: Implement file size and type validation
- Firebase: Keep service account keys secure and never commit to version control
- API Keys: Store sensitive configuration in environment variables
# Test health endpoint
curl http://localhost:8000/health
# Test video analysis
curl -X POST \
-F "video_file=@test_video.mp4" \
-F "userId=test_user" \
http://localhost:8000/api/analyze-videocd FrontEnd
# Run linting
npm run lint
# Test Firebase connection
npm run test:firestore
# Run simple tests
npm run test:simple- Environment Variables: Use environment variables for sensitive configuration
- CORS: Restrict CORS to your frontend domain
- Firebase: Use production Firebase project
- Docker: Use production-optimized Docker images
- SSL/TLS: Enable HTTPS for all services
- Monitoring: Set up logging and monitoring services
- Backup: Regular backups of Firebase data
# Build production images
docker-compose -f docker-compose.prod.yml build
# Start production services
docker-compose -f docker-compose.prod.yml up -dAnalyzes a video for garbage detection.
Request:
- Method:
POST - Content-Type:
multipart/form-data - Parameters:
video_file(file, required): Video file to analyzeuserId(string, required): User identifier
Response:
{
"success": true,
"userId": "user123",
"results": {
"ok": true,
"video": "video.mp4",
"frames_sent": 16,
"responses": [...]
}
}Health check endpoint.
Response:
{
"status": "healthy",
"service": "video-analysis-api"
}- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
[Specify your license here]
[Add author information]
- YOLO model for object detection
- FastAPI for the robust backend framework
- Next.js for the modern frontend framework
- Firebase for data persistence
For issues or questions:
- Check the troubleshooting section above
- Review container logs for specific error messages
- Ensure all services are running:
docker-compose ps - Test the health endpoint:
curl http://localhost:8000/health
RiverGuard - Protecting our waterways, one frame at a time. πβ»οΈ