OceanGuard is a cutting-edge full-stack web application that empowers citizens and authorities to collaboratively monitor, report, and respond to ocean hazards in real-time. From oil spills to marine debris, OceanGuard creates a safer, more sustainable ocean environment through technology and community engagement.
- β¨ Features
- π οΈ Tech Stack
- π Project Structure
- π Getting Started
- βοΈ Configuration
- π± Usage Guide
- π API Documentation
- π Authentication
- π Deployment
- π€ Contributing
- π License
- Interactive Map Visualization - View hazards on a live, interactive map powered by Leaflet and React Leaflet
- WebSocket Notifications - Instant real-time alerts when new hazards are reported using Socket.io
- Geolocation Support - Automatic location detection and nearby hazard discovery
- Multi-Step Report Wizard - User-friendly interface to report ocean hazards (oil spills, debris, pollution, etc.)
- Image Upload - Attach visual evidence to hazard reports with Multer file handling
- Severity Classification - Rate hazards on a scale of 1-10 for priority response
- Verification System - Admin and AI-based verification to ensure report credibility
- Secure JWT Authentication - Stateless, token-based authentication system
- Role-Based Access Control (RBAC) - User and admin roles with different permissions
- User Profiles - Customizable profiles with geolocation and contact information
- Account Security - bcrypt password hashing with 12 salt rounds
- Report Management - Verify, decline, or delete hazard reports
- User Administration - Manage users, change roles, and monitor activity
- Analytics & Insights - Comprehensive statistics, charts, and geographic hotspots
- Email Notifications - Automated alerts to ocean authorities via Nodemailer
- Curated News Feed - RSS feed aggregation from ocean conservation sources
- Social Media Integration - Reddit API integration for community discussions
- Government Alerts - Official warnings and announcements for ocean safety
- Sentiment Analysis - AI-powered sentiment analysis on news articles
- Data Visualization - Interactive charts using Recharts library
- Geographic Hotspots - Identify areas with highest hazard concentration
- Trend Analysis - Track hazards over time (daily, weekly, monthly)
- Report Statistics - Total reports, verified reports, severity distribution
- Ocean Weather Data - Real-time weather conditions using OpenWeather API
- Wave Height & Wind Speed - Marine-specific weather metrics
- Location-Based Forecasts - Weather data for specific coordinates
| Technology | Purpose | Version |
|---|---|---|
| React | UI Framework | 19.2.0 |
| TypeScript | Type-safe JavaScript | 5.9.3 |
| Vite | Build tool & dev server | 7.2.2 |
| React Router | Client-side routing | 7.10.0 |
| Leaflet | Interactive maps | 1.9.4 |
| React Leaflet | React bindings for Leaflet | 5.0.0 |
| Recharts | Data visualization | 3.4.1 |
| Tailwind CSS | Utility-first CSS | 4.1.17 |
| Socket.io Client | Real-time WebSocket | 4.8.1 |
| Technology | Purpose | Version |
|---|---|---|
| Node.js | JavaScript runtime | - |
| Express.js | Web framework | 4.18.2 |
| TypeScript | Type-safe JavaScript | 5.3.3 |
| MongoDB | NoSQL database | - |
| Mongoose | MongoDB ODM | 8.0.3 |
| Socket.io | Real-time WebSocket server | 4.8.1 |
| JWT | Authentication tokens | 9.0.2 |
| bcryptjs | Password hashing | 2.4.3 |
| Nodemailer | Email service | 7.0.10 |
| Multer | File upload handling | 2.0.2 |
| Zod | Schema validation | 4.1.13 |
| Axios | HTTP client | 1.13.2 |
| RSS Parser | RSS feed aggregation | 3.13.0 |
| Sentiment | Text sentiment analysis | 5.0.2 |
- MongoDB Atlas - Cloud-hosted MongoDB database
- OpenWeather API - Weather data and marine forecasts
- Nominatim (OpenStreetMap) - Reverse geocoding
- Reddit API - Social media integration
- RSS Feeds - Ocean conservation news sources
- Gmail SMTP - Email delivery via Nodemailer
ocean/
βββ OceanFrontend/ # React frontend application
β βββ src/
β β βββ components/ # React components
β β β βββ HomePage.tsx
β β β βββ MapPage.tsx
β β β βββ AdminDashboard.tsx
β β β βββ ReportHazardWizard.tsx
β β β βββ NewsFeedPage.tsx
β β β βββ AnalyticsPage.tsx
β β β βββ ...
β β βββ hooks/ # Custom React hooks
β β β βββ useGeolocation.ts
β β β βββ useNotifications.ts
β β βββ utils/ # Utility functions
β β β βββ api.ts # API client
β β βββ App.tsx # Main app component
β β βββ main.tsx # Entry point
β β βββ types.ts # TypeScript types
β βββ package.json
β βββ vite.config.ts
β
βββ oceanbackend/ # Node.js/Express backend
β βββ src/
β β βββ controllers/ # Request handlers
β β β βββ authController.ts
β β β βββ hazardController.ts
β β β βββ adminController.ts
β β β βββ newsController.ts
β β β βββ analyticsController.ts
β β βββ models/ # Mongoose schemas
β β β βββ User.ts
β β β βββ HazardReport.ts
β β β βββ NewsArticle.ts
β β β βββ EmailNotification.ts
β β βββ routes/ # API routes
β β β βββ authRoutes.ts
β β β βββ hazardRoutes.ts
β β β βββ adminRoutes.ts
β β β βββ ...
β β βββ middleware/ # Express middleware
β β β βββ auth.ts # JWT authentication
β β β βββ isAdmin.ts # Admin authorization
β β β βββ validate.ts # Input validation
β β β βββ upload.ts # File upload (Multer)
β β βββ services/ # Business logic
β β β βββ emailService.ts
β β β βββ notificationService.ts
β β β βββ rssFeedService.ts
β β β βββ socialMediaService.ts
β β βββ validators/ # Zod schemas
β β β βββ auth.ts
β β βββ config/ # Configuration
β β β βββ database.ts
β β βββ scripts/ # Utility scripts
β β β βββ seedData.ts
β β β βββ createAdmin.ts
β β βββ index.ts # Entry point
β βββ uploads/ # Uploaded files
β βββ package.json
β βββ tsconfig.json
β
βββ DEPLOYMENT.md # Deployment guide
βββ BACKEND_PRESENTATION_NOTES.md # Technical documentation
βββ build.bat # Build script (Windows)
βββ start.bat # Start script (Windows)
βββ README.md # This file
Before you begin, ensure you have the following installed:
- Node.js (v18 or higher) - Download
- npm or yarn - Package manager
- MongoDB - Local installation or MongoDB Atlas account
- Git - Download
-
Clone the Repository
git clone https://github.com/kartik-py12/ocean.git cd ocean -
Install Backend Dependencies
cd oceanbackend npm install -
Install Frontend Dependencies
cd ../OceanFrontend npm install -
Set Up Environment Variables
Create a
.envfile in theoceanbackenddirectory:# Database MONGODB_URI=mongodb://localhost:27017/oceanguard # or use MongoDB Atlas connection string # MONGODB_URI=mongodb+srv://<username>:<password>@cluster.mongodb.net/oceanguard # Authentication JWT_SECRET=your-super-secret-jwt-key-change-in-production # Email Service (Gmail) EMAIL_USER=your-email@gmail.com EMAIL_PASSWORD=your-gmail-app-password # SMS Service (Twilio - Optional) TWILIO_ACCOUNT_SID=your-twilio-sid TWILIO_AUTH_TOKEN=your-twilio-token TWILIO_PHONE_NUMBER=your-twilio-phone # External APIs OPENWEATHER_API_KEY=your-openweather-api-key # Frontend URL (for CORS) FRONTEND_URL=http://localhost:5173 # Server Port PORT=3000 # Environment NODE_ENV=development
Create a
.envfile in theOceanFrontenddirectory (optional for production):VITE_API_URL=http://localhost:3000/api VITE_SOCKET_URL=http://localhost:3000
-
Seed Database (Optional)
Populate the database with sample data:
cd oceanbackend npm run seed -
Create Admin User (Optional)
Create an admin account:
npm run create-admin
Option 1: Run Backend and Frontend Separately
Terminal 1 - Backend:
cd oceanbackend
npm run devTerminal 2 - Frontend:
cd OceanFrontend
npm run devOption 2: Use Batch Scripts (Windows)
From the project root:
# Build both frontend and backend
build.bat
# Start both servers
start.bat-
Build the Application
cd oceanbackend npm run build -
Start the Server
npm start
The application will be available at:
- Frontend: http://localhost:5173 (dev) or http://localhost:3000 (production)
- Backend API: http://localhost:3000/api
- Health Check: http://localhost:3000/api/health
Option 1: Local MongoDB
- Install MongoDB Community Edition
- Start MongoDB service:
mongod --dbpath /path/to/data/directory
- Use connection string:
mongodb://localhost:27017/oceanguard
Option 2: MongoDB Atlas (Recommended for Production)
- Create a free account at MongoDB Atlas
- Create a new cluster
- Add your IP to the IP whitelist (or allow all:
0.0.0.0/0) - Create a database user
- Get your connection string and add it to
.env
- Enable 2-Factor Authentication on your Gmail account
- Generate an App Password:
- Go to Google Account β Security
- Under "Signing in to Google", select "App passwords"
- Generate a password for "Mail"
- Add the email and app password to
.env
- Sign up at OpenWeather
- Generate a free API key
- Add the key to
.envasOPENWEATHER_API_KEY
-
Create an Account
- Navigate to the signup page
- Provide name, email, and password (min 6 characters)
- Optionally add phone number and location
-
Report a Hazard
- Click "Report Hazard" button
- Select hazard type (Oil Spill, Debris, Pollution, etc.)
- Choose location on map or use current location
- Set severity level (1-10)
- Add description and upload image (optional)
- Submit report
-
View Hazards on Map
- Navigate to Map page
- View all verified hazards
- Click markers for details
- Filter by hazard type or severity
-
Check News & Alerts
- View curated ocean conservation news
- Read government alerts and warnings
- Access social media discussions
-
Monitor Analytics
- View platform-wide statistics
- See geographic hotspots
- Analyze trends over time
-
Access Admin Dashboard
- Login with admin credentials
- Navigate to Admin Dashboard
-
Manage Hazard Reports
- Review pending reports
- Verify or decline reports
- Add decline reasons (sent via email)
- Delete inappropriate reports
-
Manage Users
- View all registered users
- Change user roles (user β admin)
- Suspend or activate accounts
- Delete user accounts
-
Post Government Alerts
- Create official alerts and warnings
- Broadcast to all users via Socket.io
- Track alert engagement
http://localhost:3000/api
Create a new user account.
Request Body:
{
"name": "John Doe",
"email": "john@example.com",
"password": "password123",
"phone": "+1234567890",
"location": {
"type": "Point",
"coordinates": [-120.5, 35.2]
}
}Response (201):
{
"message": "User created successfully",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": "64abc123",
"name": "John Doe",
"email": "john@example.com",
"role": "user"
}
}Login to existing account.
Request Body:
{
"email": "john@example.com",
"password": "password123"
}Response (200):
{
"message": "Login successful",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": "64abc123",
"name": "John Doe",
"email": "john@example.com",
"role": "user"
}
}Create a new hazard report.
Headers:
Authorization: Bearer <token>
Content-Type: multipart/form-data
Form Data:
type: String (Oil Spill, Debris, Pollution, Other)location[lat]: Numberlocation[lng]: Numberseverity: Number (1-10)description: String (optional)image: File (optional)
Response (201):
{
"message": "Hazard report created successfully",
"data": {
"_id": "64xyz789",
"type": "Oil Spill",
"location": { "lat": 35.2, "lng": -120.5 },
"severity": 8,
"verificationStatus": "unverified",
"reportedBy": "64abc123",
"createdAt": "2025-12-18T10:30:00Z"
}
}Get all verified hazard reports.
Query Parameters:
type: Filter by hazard typeverified: Boolean (filter by verification status)
Response (200):
{
"message": "Hazards retrieved successfully",
"data": [
{
"_id": "64xyz789",
"type": "Oil Spill",
"location": { "lat": 35.2, "lng": -120.5 },
"severity": 8,
"verificationStatus": "admin-verified",
"createdAt": "2025-12-18T10:30:00Z"
}
]
}Get dashboard statistics.
Headers:
Authorization: Bearer <admin-token>
Response (200):
{
"message": "Dashboard statistics retrieved",
"data": {
"totalReports": 245,
"verifiedReports": 198,
"pendingReports": 47,
"totalUsers": 1523,
"activeUsers": 1401,
"reportsByType": {
"Oil Spill": 89,
"Debris": 67,
"Pollution": 54
}
}
}Verify a hazard report.
Response (200):
{
"message": "Report verified successfully",
"data": { ... }
}Decline and delete a report.
Request Body:
{
"reason": "Insufficient evidence or duplicate report"
}Response (200):
{
"message": "Report declined and user notified"
}Get comprehensive platform analytics.
Response (200):
{
"message": "Analytics retrieved successfully",
"data": {
"totalReports": 245,
"verifiedReports": 198,
"avgSeverity": 6.3,
"reportsByType": [...],
"severityDistribution": [...],
"reportsOverTime": [...],
"geographicHotspots": [...]
}
}Connect:
import { io } from 'socket.io-client';
const socket = io('http://localhost:3000');Events:
hazard-reported- New hazard createdhazard-verified- Hazard verified by admingovernment-alert- New government alert posted
Example:
socket.on('hazard-reported', (data) => {
console.log('New hazard:', data);
// Update UI
});OceanGuard uses stateless JWT authentication:
- User Login β Server generates JWT token
- Token Storage β Client stores token in localStorage
- Authenticated Requests β Client sends token in Authorization header
- Token Verification β Server verifies signature and extracts user data
Token Format:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Token Expiration: 7 days
- Hashing Algorithm: bcrypt with 12 salt rounds
- Minimum Length: 6 characters
- Storage: Hashed passwords only, never plain text
- Comparison: Secure timing-safe comparison
| Route | User | Admin |
|---|---|---|
| View hazards | β | β |
| Report hazard | β | β |
| Verify reports | β | β |
| Manage users | β | β |
| Delete reports | β | β |
| Admin dashboard | β | β |
See DEPLOYMENT.md for detailed instructions.
Quick Setup:
- Push code to GitHub
- Import repository in Vercel
- Add environment variables
- Deploy
Important Notes:
- Vercel serverless functions don't support persistent WebSocket connections
- Socket.io will fallback to HTTP polling (less efficient)
- Consider deploying backend separately on Railway/Render
cd oceanbackend
railway login
railway init
railway up- Set
NODE_ENV=production - Use strong
JWT_SECRET - Configure MongoDB Atlas with IP whitelist
- Set up Gmail app password for emails
- Configure CORS with specific frontend URL
- Enable HTTPS
- Set up error monitoring (Sentry)
- Implement rate limiting
- Use cloud storage for uploads (Cloudinary/S3)
We welcome contributions from the community! Here's how you can help:
- Report Bugs - Open an issue with detailed steps to reproduce
- Suggest Features - Share your ideas for new features
- Submit Pull Requests - Fix bugs or add features
- Improve Documentation - Help make docs clearer
- Write Tests - Increase code coverage
-
Fork the Repository
git clone https://github.com/your-username/ocean.git cd ocean -
Create a Feature Branch
git checkout -b feature/your-feature-name
-
Make Changes
- Write clean, readable code
- Follow existing code style
- Add comments for complex logic
- Update documentation if needed
-
Test Your Changes
# Backend cd oceanbackend npm run build npm run dev # Frontend cd OceanFrontend npm run build npm run dev
-
Commit Changes
git add . git commit -m "feat: add awesome feature"
Commit Message Format:
feat:New featurefix:Bug fixdocs:Documentation changesstyle:Code style changesrefactor:Code refactoringtest:Adding testschore:Maintenance tasks
-
Push and Create Pull Request
git push origin feature/your-feature-name
- Use TypeScript for type safety
- Follow ESLint rules
- Use meaningful variable names
- Write self-documenting code
- Add comments for complex logic
- Keep functions small and focused
- Use async/await over callbacks
This project is licensed under the ISC License.
Copyright (c) 2025 OceanGuard
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- OpenStreetMap & Nominatim - Geocoding services
- OpenWeather - Weather data API
- React - UI framework
- Node.js & Express - Backend infrastructure
- MongoDB - Database
- Socket.io - Real-time communication
- Leaflet - Interactive maps
- All Contributors - Thank you for making OceanGuard better!
- Issues: GitHub Issues
- Discussions: GitHub Discussions
If you find OceanGuard useful, please consider giving it a β on GitHub. It helps us reach more people and makes the project more visible!
Made with β€οΈ for the Oceans
Together, we can make a difference in ocean conservation