Skip to content

kasimlohar/AquaSafe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

111 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AquaSafe 🌊

Real-time Beach Safety Monitoring with AI-Powered Risk Assessment

A comprehensive beach safety monitoring system that combines real-time weather tracking, AI-driven risk analysis, and community reporting to prevent accidents and make beach safety data accessible and actionable for beachgoers and tourists.

Status License Node React


🎯 Problem & Solution

The Challenge: Beachgoers lack real-time, actionable safety information, leading to preventable accidents and poor decision-making about water activities.

Our Solution: AquaSafe provides instant access to comprehensive beach conditions, AI-powered risk assessments, community-reported incidents, and emergency protocolsβ€”all in one integrated platform.


✨ Key Features

  • 🌦️ Real-Time Weather Monitoring - Live weather data, water conditions, and environmental metrics
  • πŸ€– AI-Powered Risk Assessment - Machine learning analysis of incident patterns and risk factors
  • πŸ‘₯ Community Reporting - User-generated incident reports and safety observations
  • 🚨 Emergency Protocols - Quick access to emergency procedures and contact information
  • ⚑ Real-Time Alerts - WebSocket-based instant notifications for safety updates
  • πŸ“ Geospatial Data - Location-based beach monitoring and incident mapping
  • πŸ” Secure Authentication - JWT-based authentication with bcrypt encryption

πŸ› οΈ Tech Stack

Frontend

  • React 18 with TypeScript for type-safe, scalable UI
  • Vite for lightning-fast development and builds
  • React Query (@tanstack/react-query) for efficient state management
  • CSS with responsive design patterns

Backend

  • Node.js & Express.js with comprehensive RESTful API
  • MongoDB with Mongoose ODM for flexible schema design
  • Redis for high-performance caching and optimization
  • Socket.io for real-time WebSocket communication
  • JWT + bcrypt for secure authentication

Infrastructure & Services

  • Python ML Service for advanced incident analysis (port 8000)
  • Docker Compose for containerized development and deployment
  • Google Cloud Storage for file management
  • SendGrid for email notifications
  • Bull job queue for asynchronous task processing

Security & Reliability

  • Express Rate Limiting for API protection
  • Joi for comprehensive request validation
  • Circuit Breaker Patterns for fault tolerance
  • Extensive Error Handling & Monitoring

πŸš€ Getting Started

Prerequisites

  • Node.js (v18 or higher)
  • MongoDB (local or cloud instance)
  • Redis (local or cloud instance)
  • Python 3.8+ (for ML service)
  • Google Cloud Storage credentials
  • SendGrid API key

Installation

  1. Clone the repository

    git clone https://github.com/kasimlohar/AquaSafe.git
    cd AquaSafe
  2. Install dependencies

    # Install backend dependencies
    cd backend && npm install
    
    # Install frontend dependencies
    cd ../frontend && npm install
    cd ..
  3. Set up environment variables

    # Backend environment variables (.env)
    MONGODB_URI=your_mongodb_connection_string
    REDIS_URL=your_redis_connection_string
    JWT_SECRET=your_jwt_secret
    GOOGLE_CLOUD_STORAGE_CREDENTIALS=your_gcs_credentials
    SENDGRID_API_KEY=your_sendgrid_key
    SESSION_SECRET=your_session_secret
  4. Start services

    # MongoDB and Redis should be running
    # You can use Docker Compose or run them separately
  5. Seed database

    npm run seed

Running the Application

Development Mode:

# Run all services concurrently
npm run dev

Individual Services:

# Backend (http://localhost:3001)
cd backend && npm start

# Frontend (http://localhost:3000)
cd frontend && npm run dev

# ML Service (http://localhost:8000)
cd ml-service && python app.py

Visit http://localhost:3000 to access the application.


πŸ“ Project Structure

AquaSafe/
β”œβ”€β”€ frontend/                 # React + Vite application
β”‚   └── src/
β”‚       β”œβ”€β”€ components/       # Reusable React components
β”‚       └── main.jsx         # Application entry point
β”œβ”€β”€ backend/                  # Node.js + Express API
β”‚   └── src/
β”‚       β”œβ”€β”€ models/          # MongoDB schemas
β”‚       β”œβ”€β”€ routes/          # API endpoints
β”‚       β”œβ”€β”€ middleware/      # Validation & authentication
β”‚       └── server.js        # Server entry point
β”œβ”€β”€ ml-service/              # Python ML service
β”œβ”€β”€ docs/                    # Comprehensive documentation
β”‚   β”œβ”€β”€ API.md              # API design & endpoints
β”‚   β”œβ”€β”€ DATABASE.md         # Database schema
β”‚   └── DEPLOYMENT.md       # Deployment guides
└── scripts/                 # Setup & utility scripts

πŸ“š API Documentation

The backend provides a comprehensive RESTful API with the following main endpoints:

  • Beach Data - Retrieve real-time beach conditions and metrics
  • Incident Management - Create, read, update incident reports
  • User Management - User registration, authentication, profiles
  • Real-Time Alerts - WebSocket-based safety notifications
  • Risk Assessment - AI-powered risk analysis and recommendations

For detailed API documentation, visit /docs/API.md in the repository.


πŸ§ͺ Testing

Access the test page at /test to view and interact with UI components during development.


πŸ“– Key Architectural Decisions

Why MongoDB? Flexible schema design accommodates varied incident reports, geospatial data, and dynamic beach monitoring information without rigid table structures.

Why Redis Caching? Dramatically improves performance for frequently accessed beach data and reduces database load during peak usage.

Why WebSockets? Real-time incident alerts and safety updates require instant communication without polling overhead.

Why Microservices? Separation of ML analysis into a dedicated Python service enables independent scaling and easier maintenance.

Production-Ready Features:

  • Comprehensive validation on all inputs
  • Circuit breaker patterns for external service resilience
  • Error handling and structured logging
  • Extensive test coverage

πŸŽ“ What I Learned

This project deepened my expertise in several critical areas:

  • Full-Stack Architecture - Building scalable, production-ready systems with proper separation of concerns
  • Real-Time Systems - Implementing WebSocket communication and handling concurrent connections efficiently
  • Performance Optimization - Strategic caching with Redis and query optimization techniques
  • Comprehensive Validation - Multi-layer validation for data integrity and security
  • ML Integration - Connecting machine learning services with production applications
  • DevOps Practices - Docker containerization and deployment strategies

Key Takeaways

Proper caching strategies can reduce database load by 80%+. Comprehensive error handling transforms user experience. Modular architecture enables fearless scaling. Real-time systems require careful state management.


πŸ”„ Development Status

Current Progress:

  • βœ… Core API and database schema complete
  • βœ… Frontend component library built
  • βœ… WebSocket real-time features operational
  • βœ… Redis caching implemented
  • πŸ”„ ML service integration in progress
  • πŸ”„ Deployment pipeline being finalized

Planned Features:

  • Complete ML model training and integration
  • Native mobile application (React Native)
  • Advanced analytics and insights dashboard
  • Prediction models for peak safety hours
  • Integration with official weather APIs

Known Limitations:

  • ML service integration currently in development
  • Live deployment to production pending
  • Mobile app development to begin Q4

πŸ“¦ Deployment

Comprehensive deployment guides are available in /docs/DEPLOYMENT.md, including:

  • Docker containerization and orchestration
  • Environment configuration for production
  • Database migration strategies
  • CI/CD pipeline setup

🀝 Contributing

AquaSafe welcomes contributions! The codebase features:

  • Well-documented API with clear endpoint specifications
  • Comprehensive validation middleware
  • Extensive test coverage for reliability
  • Modular architecture for easy feature additions

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ‘€ Author

Kasim Lohar


πŸ™ Acknowledgments

Built as a comprehensive demonstration of full-stack development, real-time systems, and AI integration. Special focus on production-ready code quality, security, and performance optimization.


Made with ❀️ for safer beaches

⬆ Back to Top

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors