The world is currently experiencing a serious issue of water quality due to urbanization, industrialization, and agricultural activities, necessitating urgent solutions to safeguard public health and ecosystems. This study introduces a versatile IoT framework for real-time Water Quality Index (WQI) prediction and classification, leveraging ensemble machine learning for global applicability. The system integrates an ESP32 microcontroller with six sensors (pH, Total Dissolved Solids, temperature, turbidity, dissolved oxygen, and electrical conductivity), transmitting data to a Web Dashboard and Firebase Realtime Database for cloud storage and synchronization. The framework demonstrates the excellent performance of advanced ensemble algorithms including LightGBM, CatBoost, Random Forest, and XGBoost, that have an R2 of 0.9966 and 99.49% accuracy in classification, respectively, and confirmed with 17,367 records that have a timestamp of water bodies of diverse environments. The strength of this dataset is that it has been able to analyze temporal and seasonal patterns more than the conventional laboratory practices. The proposed framework's operations are cost and scalable, and they fill significant gaps in the real-time monitoring of water-quality, and they help in sustainable environmental management in resource-limited areas in the world.